Skip to content

Build Pipeline

Build Pipeline #716

Workflow file for this run

name: Build Pipeline
on:
workflow_dispatch:
inputs:
service_folder:
description: 'Folder prefix for the service'
required: true
type: choice
options:
- core-services
default: core-services
service:
description: 'Name of the service to build and deploy'
required: true
type: choice
options:
- "mdms-v2"
- "audit-service"
- "boundary-service"
- "build"
- "chatbot"
- "docs"
- "egov-accesscontrol"
- "egov-common-masters"
- "egov-data-uploader"
- "egov-document-uploader"
- "egov-enc-service"
- "egov-filestore"
- "egov-idgen"
- "egov-indexer"
- "egov-localization"
- "egov-location"
- "egov-malware-detection"
- "egov-mdms-service"
- "egov-notification-mail"
- "egov-notification-sms"
- "egov-otp"
- "egov-persister"
- "egov-pg-service"
- "egov-searcher"
- "egov-telemetry"
- "egov-url-shortening"
- "egov-user-event"
- "egov-user"
- "egov-workflow-v2"
- "gateway"
- "internal-gateway-scg"
- "internal-gateway"
- "libraries"
- "national-dashboard-ingest"
- "national-dashboard-kafka-pipeline"
- "nlp-engine"
- "pdf-service"
- "report"
- "service-request"
- "tenant"
- "user-otp"
- "xstate-chatbot"
- "zuul"
default: "audit-service"
permissions:
contents: read
jobs:
resolve-config:
runs-on: ubuntu-latest
outputs:
dockerfile_path: ${{ steps.pick_dockerfile.outputs.dockerfile_path }}
tag: ${{ steps.tag.outputs.tag }}
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Install yq
run: |
VERSION="4.30.8"
URL="https://github.com/mikefarah/yq/releases/download/v${VERSION}/yq_linux_amd64"
sudo curl -sSL "$URL" -o /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
- name: Determine Dockerfile path from build-config.yml
id: pick_dockerfile
env:
SERVICE: ${{ github.event.inputs.service }}
run: |
DEFAULT_DOCKERFILE="build/maven/Dockerfile"
echo "Looking for service '$SERVICE' in build-config.yml..."
DF=$(yq eval ".config[].build[] | select(.\"image-name\" == \"${SERVICE}\") | .dockerfile // \"\"" build/build-config.yml)
if [ -z "$DF" ] || [ "$DF" = "null" ]; then
echo "No entry found; defaulting to $DEFAULT_DOCKERFILE"
DF="$DEFAULT_DOCKERFILE"
else
echo "Found dockerfile: $DF"
fi
echo "dockerfile_path=$DF" >> "$GITHUB_OUTPUT"
echo "DOCKERFILE_PATH=$DF" >> "$GITHUB_ENV"
- name: Generate the Next Tag
id: tag
run: |
set -euxo pipefail
BRANCH="${GITHUB_REF##*/}"
HASH=$(git rev-parse --short HEAD)
TAG="${BRANCH}-${HASH}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "NEXT_TAG=$TAG" >> "$GITHUB_ENV"
build-matrix:
needs: resolve-config
# expose whether a DB folder was present
outputs:
db_folder_exists: ${{ steps.check-db-folder.outputs.folder_exists }}
strategy:
matrix:
include:
- arch: amd64
platform: linux/amd64
runner: ubuntu-latest
- arch: arm64
platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Check for DB folder
id: check-db-folder
env:
SERVICE: ${{ github.event.inputs.service }}
SERVICE_FOLDER: ${{ github.event.inputs.service_folder }}
run: |
BASE_PATH="${SERVICE_FOLDER}/${SERVICE}"
if [ -d "$BASE_PATH/src/main/resources/db" ]; then
echo "folder_exists=true" >> "$GITHUB_OUTPUT"
echo "db_path=$BASE_PATH/src/main/resources/db" >> "$GITHUB_OUTPUT"
elif [ -d "$BASE_PATH/migration" ]; then
echo "folder_exists=true" >> "$GITHUB_OUTPUT"
echo "db_path=$BASE_PATH/migration" >> "$GITHUB_OUTPUT"
else
echo "folder_exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- name: Build & push ${{ matrix.arch }} image
id: build_push_app
uses: docker/build-push-action@v5
with:
context: .
file: ${{ needs.resolve-config.outputs.dockerfile_path }}
platforms: ${{ matrix.platform }}
push: true
tags: egovio/${{ github.event.inputs.service }}:${{ needs.resolve-config.outputs.tag }}-${{ matrix.arch }}
build-args: |
WORK_DIR=${{ github.event.inputs.service_folder }}/${{ github.event.inputs.service }}
- name: Build and Push Database Docker Image
if: ${{ steps.check-db-folder.outputs.folder_exists == 'true' }}
id: build_push_db
uses: docker/build-push-action@v5
with:
context: ${{ steps.check-db-folder.outputs.db_path }}
file: ${{ steps.check-db-folder.outputs.db_path }}/Dockerfile
platforms: ${{ matrix.platform }}
push: true
tags: egovio/${{ github.event.inputs.service }}-db:${{ needs.resolve-config.outputs.tag }}-${{ matrix.arch }}
create-manifest:
needs: [build-matrix, resolve-config]
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- name: Create & push multi-arch manifest (application)
env:
SERVICE: ${{ github.event.inputs.service }}
TAG: ${{ needs.resolve-config.outputs.tag }}
run: |
docker buildx imagetools create \
--tag "egovio/${SERVICE}:${TAG}" \
"egovio/${SERVICE}:${TAG}-amd64" \
"egovio/${SERVICE}:${TAG}-arm64"
- name: Create & push multi-arch manifest (database)
if: ${{ needs.build-matrix.outputs.db_folder_exists == 'true' }}
env:
SERVICE: ${{ github.event.inputs.service }}
TAG: ${{ needs.resolve-config.outputs.tag }}
run: |
docker buildx imagetools create \
--tag "egovio/${SERVICE}-db:${TAG}" \
"egovio/${SERVICE}-db:${TAG}-amd64" \
"egovio/${SERVICE}-db:${TAG}-arm64"
- name: Add all image tags to GitHub summary
env:
DB_EXISTS: ${{ needs.build-matrix.outputs.db_folder_exists }}
SERVICE: ${{ github.event.inputs.service }}
TAG: ${{ needs.resolve-config.outputs.tag }}
run: |
echo "## App Docker images" >> $GITHUB_STEP_SUMMARY
echo "- \`egovio/${SERVICE}:${TAG}-amd64\`" >> $GITHUB_STEP_SUMMARY
echo "- \`egovio/${SERVICE}:${TAG}-arm64\`" >> $GITHUB_STEP_SUMMARY
echo "- **multi‑arch** \`egovio/${SERVICE}:${TAG}\`" >> $GITHUB_STEP_SUMMARY
if [ "$DB_EXISTS" = "true" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "## DB Docker images" >> $GITHUB_STEP_SUMMARY
echo "- \`egovio/${SERVICE}-db:${TAG}-amd64\`" >> $GITHUB_STEP_SUMMARY
echo "- \`egovio/${SERVICE}-db:${TAG}-arm64\`" >> $GITHUB_STEP_SUMMARY
echo "- **multi‑arch** \`egovio/${SERVICE}-db:${TAG}\`" >> $GITHUB_STEP_SUMMARY
fi