Skip to content

Commit

Permalink
Update Docker reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
admdly committed Dec 7, 2023
1 parent 0a5d7aa commit 9fc4883
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build and Push to Docker Hub
on:
workflow_call:
inputs:
download_artifact:
download-artifact:
description: >
'The name of a build artifact containing the files required to build the image(s).
The download should contain a single .tar archive named build.tar.'
Expand All @@ -15,26 +15,26 @@ on:
default: '["linux/amd64"]'
required: false
type: string
repository_name:
repository-name:
description: 'The repository to push images to (e.g. namespace/repo-name).'
default: ${{ github.repository }}
required: false
type: string
tag_latest:
tag-latest:
description: 'Whether to tag the builds with the latest tag or not.'
default: false
default: 'false'
required: false
type: boolean
tag_raw:
type: string
tag-raw:
description: 'The raw tag name to tag the builds with, if any.'
default: ''
required: false
type: string
secrets:
dockerhub_username:
dockerhub-username:
description: 'The username used to authenticate with Docker Hub.'
required: true
dockerhub_token:
dockerhub-token:
description: 'The personal access token used to authenticate with Docker Hub.'
required: true

Expand All @@ -51,11 +51,13 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.repository_name }}
images: ${{ inputs.repository-name }}
flavor: |
latest=false
tags: |
type=semver,pattern={{version}}
type=raw,value=latest,enable=${{ inputs.tag_latest }}
type=raw,value=${{ inputs.tag_raw }},enable=${{ inputs.tag_raw != '' }}
type=raw,value=latest,enable=${{ inputs.tag-latest == 'true' }}
type=raw,value=${{ inputs.tag-raw }},enable=${{ inputs.tag-raw != '' }}
- name: 'Set up QEMU'
uses: docker/setup-qemu-action@v3
Expand All @@ -66,30 +68,38 @@ jobs:
- name: 'Login to Docker Hub'
uses: docker/login-action@v3
with:
username: ${{ secrets.dockerhub_username }}
password: ${{ secrets.dockerhub_token }}
username: ${{ secrets.dockerhub-username }}
password: ${{ secrets.dockerhub-token }}

- name: 'Checkout Dockerfile'
uses: actions/checkout@v4
with:
sparse-checkout: |
Dockerfile
sparse-checkout-cone-mode: false

- name: 'Download Files Required for Build'
if: ${{ inputs.download_artifact != '' }}
if: ${{ inputs.download-artifact != '' }}
uses: actions/download-artifact@v3
with:
name: ${{ inputs.download_artifact }}
name: ${{ inputs.download-artifact }}
path: '/tmp/'

- name: 'Extract Files Required for Build'
if: ${{ inputs.download_artifact != '' }}
if: ${{ inputs.download-artifact != '' }}
run: |
mkdir /tmp/src
tar -xvf /tmp/build.tar -C /tmp/src
mkdir ./src
tar -xvf /tmp/build.tar -C ./src
- name: 'Build and Push by Digest'
id: build
uses: docker/build-push-action@v5
with:
cache-from: type=gha,scope=${{ github.ref_name }}-${{ matrix.platform }}
cache-to: type=gha,scope=${{ github.ref_name }}-${{ matrix.platform }}
context: .
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ inputs.repository_name }},push-by-digest=true,name-canonical=true,push=true
outputs: type=image,name=${{ inputs.repository-name }},push-by-digest=true,name-canonical=true,push=true
platforms: ${{ matrix.platform }}

- name: 'Export Digest'
Expand Down Expand Up @@ -124,24 +134,26 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.repository_name }}
images: ${{ inputs.repository-name }}
flavor: |
latest=false
tags: |
type=semver,pattern={{version}}
type=raw,value=latest,enable=${{ inputs.tag_latest }}
type=raw,value=${{ inputs.tag_raw }},enable=${{ inputs.tag_raw != '' }}
type=raw,value=latest,enable=${{ inputs.tag-latest == 'true' }}
type=raw,value=${{ inputs.tag-raw }},enable=${{ inputs.tag-raw != '' }}
- name: 'Login to Docker Hub'
uses: docker/login-action@v3
with:
username: ${{ secrets.dockerhub_username }}
password: ${{ secrets.dockerhub_token }}
username: ${{ secrets.dockerhub-username }}
password: ${{ secrets.dockerhub-token }}

- name: 'Create Manifest List and Push'
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ inputs.repository_name }}@sha256:%s ' *)
$(printf '${{ inputs.repository-name }}@sha256:%s ' *)
working-directory: /tmp/digests

- name: 'Inspect Image'
run: |
docker buildx imagetools inspect ${{ inputs.repository_name }}:${{ steps.meta.outputs.version }}
docker buildx imagetools inspect ${{ inputs.repository-name }}:${{ steps.meta.outputs.version }}

0 comments on commit 9fc4883

Please sign in to comment.