Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build docker image & push to registry. | ||
on: | ||
workflow_call: | ||
inputs: | ||
docker_registry: | ||
description: Docker registry | ||
required: false | ||
default: 'ghcr.io' | ||
type: string | ||
registry_org: | ||
description: Docker registry organisation | ||
required: false | ||
default: 'ministryofjustice' | ||
type: string | ||
additional_docker_tag: | ||
description: Additional docker tag that can be used to specify stable tags | ||
required: false | ||
default: '' | ||
type: string | ||
push: | ||
description: Push docker image to registry flag | ||
required: true | ||
default: true | ||
type: boolean | ||
permissions: | ||
contents: read | ||
packages: write | ||
jobs: | ||
docker_build: | ||
name: Build docker image | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set version | ||
id: version | ||
run: | | ||
version=$(date '+%Y-%m-%d').${{ github.run_number }}.$(echo ${{ github.sha }} | cut -c1-7) | ||
echo "version=$version" | tee -a "$GITHUB_OUTPUT" | ||
- 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: ${{ secrets.HMPPS_QUAYIO_USER }} | ||
password: ${{ secrets.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: ${{ 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 | ||
tags: | | ||
${{ inputs.docker_registry}}/${{ inputs.registry_org }}/${{ github.event.repository.name }}:latest | ||
${{ inputs.docker_registry}}/${{ inputs.registry_org }}/${{ github.event.repository.name }}:${{ steps.version.outputs.version }} |