Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandhya1874 committed Oct 8, 2024
1 parent 0363ec3 commit ecea880
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 84 deletions.
159 changes: 76 additions & 83 deletions .github/actions/build-test-and-deploy/build_docker/action..yml
Original file line number Diff line number Diff line change
@@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
38 changes: 37 additions & 1 deletion .github/workflows/build_multiplatform_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit ecea880

Please sign in to comment.