-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract
build-quesma-docker-image
to a reusable GitHub Actions work…
…flow (#862) While working on an upcoming PR, I noticed that `build-quesma-docker-image` step in GitHub Actions workflow was duplicated in 3 places... and my PR would add a 4th copy! Therefore extract the `build-quesma-docker-image` step into a "reusable workflow" (`workflow_call` trigger) which can be called from other workflows, avoiding duplication. All the behaviors of this step stay the same - for now the "build+push" step and "build+export" step are separate to make sure the behavior stays the same. Additionally `docker-image-latest.yml` is renamed to `nightly-docker-build-and-push.yml` in order to avoid confusion with the new `build-quesma-docker-image.yml` file. --------- Signed-off-by: Piotr Grabowski <[email protected]>
- Loading branch information
1 parent
69258d8
commit 0c220f9
Showing
6 changed files
with
121 additions
and
135 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Reusable workflow that builds Quesma Docker image and either: | ||
# - pushes it to Docker Hub | ||
# - or exports it to .tar artifact | ||
|
||
name: Docker image build | ||
on: | ||
workflow_call: # Can be reused from another workflow | ||
inputs: | ||
VERSION: | ||
description: 'Version number to tag the image with (optional)' | ||
default: nightly | ||
required: false | ||
type: string | ||
PUSH: | ||
description: 'Whether to push the image to the registry (optional)' # if not, we will export it to .tar artifact | ||
default: false | ||
required: false | ||
type: boolean | ||
|
||
jobs: | ||
build-quesma-docker-image: | ||
strategy: | ||
matrix: | ||
module: [ "quesma" ] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
cache-dependency-path: ${{ matrix.module }}/go.sum | ||
go-version: '1.22' | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v3 | ||
if: ${{ inputs.PUSH }} | ||
with: | ||
username: ${{ secrets.DOCKER_USER }} | ||
password: ${{ secrets.DOCKER_PAT }} | ||
|
||
- name: Set the build date | ||
run: echo QUESMA_BUILD_DATE=$(git --no-pager log -1 --date=format:'%Y-%m-%d' --format="%ad") >> $GITHUB_ENV | ||
|
||
# If we don't push the image, we build it only for the host architecture and export it to .tar file | ||
# This step is similar to "Build and push", but avoids building arm64 image, which takes | ||
# a lot of time on GitHub Actions. | ||
- name: Build and export | ||
uses: docker/build-push-action@v6 | ||
if: ${{ !inputs.PUSH }} | ||
with: | ||
context: ${{ matrix.module }}/. | ||
tags: | | ||
quesma/quesma:${{ inputs.VERSION }} | ||
quesma/quesma:nightly | ||
push: false | ||
outputs: type=docker,dest=/tmp/image.tar | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
env: | ||
DOCKER_BUILD_SUMMARY: false | ||
|
||
# If we push the image, we build it for both amd64 and arm64 and don't export it | ||
- name: Build and push | ||
uses: docker/build-push-action@v6 | ||
if: ${{ inputs.PUSH }} | ||
with: | ||
context: ${{ matrix.module }}/. | ||
tags: | | ||
quesma/quesma:${{ inputs.VERSION }} | ||
quesma/quesma:nightly | ||
push: true | ||
build-args: | | ||
QUESMA_BUILD_SHA=${{ github.sha }} | ||
QUESMA_VERSION=${{ inputs.VERSION }} | ||
QUESMA_BUILD_DATE=${{ env.QUESMA_BUILD_DATE }} | ||
platforms: linux/amd64,linux/arm64 | ||
env: | ||
DOCKER_BUILD_SUMMARY: false | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-artifact@v4 | ||
if: ${{ !inputs.PUSH }} | ||
with: | ||
name: ${{ matrix.module }} | ||
path: /tmp/image.tar | ||
retention-days: 1 |
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Docker image build (nightly) | ||
# Pipeline which builds `nightly` Docker images for Quesma | ||
# pushes them to Docker Hub as `quesma/quesma:nightly` (and `quesma/quesma:<VERSION>`, if VERSION is specified explicitly) | ||
# | ||
# This workflow is triggered by a push/merge to the `main` branch | ||
# quesma/quesma:nightly image is a pointer to latest released version. | ||
# | ||
# This workflow is not reusable, use build-quesma-docker-image.yml as a reusable workflow. | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
workflow_dispatch: # Handy for testing | ||
inputs: | ||
VERSION: | ||
description: 'Version number to tag the image with (optional)' | ||
default: nightly | ||
required: true | ||
PUSH: | ||
description: 'Whether to push the image to the registry' | ||
default: false | ||
required: true | ||
jobs: | ||
build-quesma-docker-image: | ||
uses: ./.github/workflows/build-quesma-docker-image.yml | ||
with: | ||
VERSION: ${{ inputs.VERSION || 'nightly' }} # when called from the main branch, `github.event.inputs.VERSION` doesn't use default value and is just empty | ||
# Pushes to DockerHub only for `main` branch builds, unless set explicitly in the job input | ||
PUSH: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || inputs.PUSH }} |
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
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