From ecea880832e1fe4b34ddc461945ec75932c71e2b Mon Sep 17 00:00:00 2001 From: sandhya1874 Date: Tue, 8 Oct 2024 22:03:06 +0100 Subject: [PATCH] . --- .../build_docker/action..yml | 159 +++++++++--------- .../build_multiplatform_docker/action.yml | 1 + .../workflows/build_multiplatform_docker.yml | 38 ++++- 3 files changed, 114 insertions(+), 84 deletions(-) diff --git a/.github/actions/build-test-and-deploy/build_docker/action..yml b/.github/actions/build-test-and-deploy/build_docker/action..yml index c9b97fe..d9501f8 100644 --- a/.github/actions/build-test-and-deploy/build_docker/action..yml +++ b/.github/actions/build-test-and-deploy/build_docker/action..yml @@ -1,88 +1,81 @@ name: Build docker image & push to registry. -on: - workflow_call: - inputs: - repository_name: - description: Repository name - required: true - type: string - docker_registry: - description: Docker registry - required: true - type: string - registry_org: - description: Docker registry organisation - required: true - type: string - additional_docker_tag: - description: Additional docker tag that can be used to specify stable tags - required: false - type: string - push: - description: Push docker image to registry flag - required: true - type: boolean - app_version: - description: App version - required: true - type: string - docker_registry_username: - description: Docker registry username - required: true - type: string - docker_registry_token: - description: Docker registry username - required: true - type: string - git_head_ref: - description: git head ref - required: true - type: string - git_ref_name: - description: git branch name - required: true - type: string +inputs: + repository_name: + description: Repository name + required: true + type: string + docker_registry: + description: Docker registry + required: true + type: string + registry_org: + description: Docker registry organisation + required: true + type: string + additional_docker_tag: + description: Additional docker tag that can be used to specify stable tags + required: false + type: string + push: + description: Push docker image to registry flag + required: true + type: boolean + app_version: + description: App version + required: true + type: string + HMPPS_QUAYIO_USER: + description: Docker registry username + required: false + type: string + HMPPS_QUAYIO_TOKEN: + description: Docker registry token + required: false + type: string + git_head_ref: + description: Github source branch ref + required: false + type: string + git_branch_ref: + description: Github source branch name + required: false + type: string -permissions: - contents: read - packages: write - -jobs: - docker_build: - name: Build docker image - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: docker/setup-qemu-action@v2 - - uses: docker/setup-buildx-action@v2 - - name: Docker login if Docker registry is quay.io - uses: docker/login-action@v2 - with: - registry: ${{ inputs.docker_registry }} - username: ${{ inputs.docker_registry_username }} - password: ${{ inputs.docker_registry_token }} +runs: + using: "composite" + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v2 + - uses: docker/setup-buildx-action@v2 + - name: Docker login if Docker registry is quay.io + if: ${{ inputs.docker_registry == 'quay.io' }} + uses: docker/login-action@v2 + with: + registry: ${{ inputs.docker_registry }} + username: ${{ inputs.HMPPS_QUAYIO_USER }} + password: ${{ inputs.HMPPS_QUAYIO_TOKEN }} - - name: Docker login if Docker registry is ghcr.io - if: ${{ inputs.docker_registry == 'ghcr.io' }} - uses: docker/login-action@v2 - with: - registry: ${{ inputs.docker_registry }} - username: ${{ input.docker_registry_username }} - password: ${{ input.input.docker_registry_token }} + - name: Docker login if Docker registry is ghcr.io + if: ${{ inputs.docker_registry == 'ghcr.io' }} + uses: docker/login-action@v2 + with: + registry: ${{ inputs.docker_registry }} + username: ${{ github.actor }} + password: ${{ github.token }} - - name: Build Docker images - uses: docker/build-push-action@v4 - with: - cache-from: type=gha - cache-to: type=gha,mode=max - context: . - push: ${{ inputs.push }} - provenance: false - build-args: | - "BUILD_NUMBER=${{ inputs.app_version }}" - "GIT_REF=$${{ inputs.git_head_ref }}" - "GIT_BRANCH=$${{ inputs.git_ref_name }}" - tags: | - ${{ inputs.docker_registry}}/${{ inputs.registry_org }}/${{ inputs.repository_name }}:latest - ${{ inputs.docker_registry}}/${{ inputs.registry_org }}/${{ inputs.repository_name }}:${{ inputs.app_version }} + - name: Build Docker images + uses: docker/build-push-action@v4 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + push: ${{ inputs.push }} + provenance: false + build-args: | + "BUILD_NUMBER=${{ inputs.app_version }}" + "GIT_REF=$${{ inputs.git_head_ref }}" + "GIT_BRANCH=${{ inputs.git_branch_ref }}" + tags: | + ${{ inputs.docker_registry}}/${{ inputs.registry_org }}/${{ github.event.repository.name }}:latest + ${{ inputs.docker_registry}}/${{ inputs.registry_org }}/${{ github.event.repository.name }}:${{ inputs.app_version }} diff --git a/.github/actions/build-test-and-deploy/build_multiplatform_docker/action.yml b/.github/actions/build-test-and-deploy/build_multiplatform_docker/action.yml index 2f08a97..02f8719 100644 --- a/.github/actions/build-test-and-deploy/build_multiplatform_docker/action.yml +++ b/.github/actions/build-test-and-deploy/build_multiplatform_docker/action.yml @@ -73,6 +73,7 @@ runs: uses: docker/build-push-action@v4 with: cache-from: type=gha + platform: linux/amd64,linux/arm64 cache-to: type=gha,mode=max context: . push: ${{ inputs.push }} diff --git a/.github/workflows/build_multiplatform_docker.yml b/.github/workflows/build_multiplatform_docker.yml index 276f104..13fde17 100644 --- a/.github/workflows/build_multiplatform_docker.yml +++ b/.github/workflows/build_multiplatform_docker.yml @@ -19,6 +19,11 @@ on: description: Push docker image to registry flag required: true type: boolean + docker_multiplatform: + description: Docker image build multiplatform or not + required: true + type: boolean + default: true secrets: HMPPS_QUAYIO_USER: @@ -42,8 +47,39 @@ jobs: version=$(date '+%Y-%m-%d').${{ github.run_number }}.$(echo ${{ github.sha }} | cut -c1-7) echo "version=$version" | tee -a "$GITHUB_OUTPUT" - multiplatform_docker_build: + docker_build: name: Build docker image + if: ${{ docker_multiplatform == false }} + needs: [ create_app_version ] + runs-on: ubuntu-latest + steps: + - uses: ministryofjustice/hmpps-github-actions/.github/actions/build-test-and-deploy/build_docker@feat/HEAT-344-share-app-version-across-jobs + if: ${{ inputs.docker_registry == 'ghcr.io' }} + with: + repository_name: ${{ github.event.repository.name }} + docker_registry: ${{ inputs.docker_registry }} + registry_org: ${{ inputs.registry_org }} + additional_docker_tag: ${{ inputs.additional_docker_tag }} + push: ${{ inputs.push }} + app_version: ${{ needs.create_app_version.outputs.version }} + + - uses: ministryofjustice/hmpps-github-actions/.github/actions/build-test-and-deploy/build_docker@feat/HEAT-344-share-app-version-across-jobs + if: ${{ inputs.docker_registry == 'quay.io' }} + with: + repository_name: ${{ github.event.repository.name }} + docker_registry: ${{ inputs.docker_registry }} + registry_org: ${{ inputs.registry_org }} + additional_docker_tag: ${{ inputs.additional_docker_tag }} + push: ${{ inputs.push }} + app_version: ${{ needs.create_app_version.outputs.version }} + HMPPS_QUAYIO_USER: ${{ secrets.HMPPS_QUAYIO_USER }} + HMPPS_QUAYIO_TOKEN: ${{ secrets.HMPPS_QUAYIO_TOKEN}} + git_head_ref: ${{ github.head_ref }} + git_branch_ref: ${{ github.ref_name }} + + multiplatform_docker_build: + name: Build multiplatform docker image + if: ${{ docker_multiplatform == true }} needs: [ create_app_version ] runs-on: ubuntu-latest steps: