Skip to content

Commit

Permalink
Introducing release jobs (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
mieciu authored Jul 19, 2024
1 parent f091838 commit ccc751e
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 20 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/docker-image-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Docker image build (latest)
# Pipeline which builds latest / nightly Docker images for Quesma
# pushes them to Docker Hub and GCR with `latest` tag,
# triggered by a push/merge to the `main` branch

on:
push:
branches: [ "main" ]
workflow_dispatch: # Handy for testing
inputs:
VERSION:
description: 'Version number to tag the image with (optional)'
default: latest
required: true
PUSH:
description: 'Whether to push the image to the registry'
default: false
required: true

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: Login to GCR (only for build running on `main` branch)
uses: docker/login-action@v3
with:
registry: europe-docker.pkg.dev
username: _json_key
password: ${{ secrets.GCR_SERVICE_ACCOUNT_PRIVATE_KEY }}

- name: Log in to Docker Hub
uses: docker/login-action@v3
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

- name: Build and export
uses: docker/build-push-action@v6
with:
context: ${{ matrix.module }}/.
# when called from the main branch, `github.event.inputs.VERSION` doesn't use default value and is just empty
tags: |
europe-docker.pkg.dev/metal-figure-407109/quesma-nightly/quesma:${{ github.sha }}
europe-docker.pkg.dev/metal-figure-407109/quesma-nightly/quesma:${{ github.event.inputs.VERSION || 'latest' }}
quesma/quesma:${{ github.event.inputs.VERSION || 'latest' }}
quesma/quesma:latest
# Pushes to GCR only for `main` branch builds, unless set explicitly in the job input
push: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event.inputs.PUSH }}
build-args: |
QUESMA_BUILD_SHA=${{ github.sha }}
QUESMA_VERSION=${{ github.event.inputs.VERSION }}
QUESMA_BUILD_DATE=${{ env.QUESMA_BUILD_DATE }}
platforms: linux/amd64,linux/arm64
env:
DOCKER_BUILD_SUMMARY: false
54 changes: 34 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
name: Docker image build
# At this moment we push to image to our 'nightly' GCR repository
name: Release Quesma
# Builds Quesma Docker image using specific git tag
# and creates a GitHub release draft

on:
push:
branches: [ "main" ]
workflow_dispatch: # Handy for testing
workflow_dispatch:
inputs:
VERSION:
description: 'Version number to tag the image with'
default: latest
required: true
PUSH:
description: 'Whether to push the image to the registry'
default: false
description: 'Version number - needs to be a valid semver, relevant tag should be present in the repository'
required: true

jobs:
Expand All @@ -22,7 +16,19 @@ jobs:
module: [ "quesma" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate input - needs to match semver
run: |
echo "Validating input: ${{ github.event.inputs.VERSION }}"
if ! echo "${{ github.event.inputs.VERSION }}" | grep -qE '^([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$'; then
echo "ERROR: VERSION does not conform to SemVer (Semantic Versioning)"
exit 1
fi
shell: bash

- name: Checkout the correct revision
uses: actions/checkout@v
with:
ref: ${{ github.event.inputs.VERSION }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down Expand Up @@ -53,18 +59,26 @@ jobs:
uses: docker/build-push-action@v6
with:
context: ${{ matrix.module }}/.
# when called from the main branch, `github.event.inputs.VERSION` doesn't use default value and is just empty
tags: |
europe-docker.pkg.dev/metal-figure-407109/quesma-nightly/quesma:${{ github.sha }}
europe-docker.pkg.dev/metal-figure-407109/quesma-nightly/quesma:${{ github.event.inputs.VERSION || 'latest' }}
quesma/quesma:${{ github.event.inputs.VERSION || 'latest' }}
quesma/quesma:latest
# Pushes to GCR only for `main` branch builds, unless set explicitly in the job input
push: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event.inputs.PUSH }}
tags: |
europe-docker.pkg.dev/metal-figure-407109/quesma-nightly/quesma:${{ github.event.inputs.VERSION }}
quesma/quesma:${{ github.event.inputs.VERSION }}
push: true
build-args: |
QUESMA_BUILD_SHA=${{ github.sha }}
QUESMA_VERSION=${{ github.event.inputs.VERSION }}
QUESMA_BUILD_DATE=${{ env.QUESMA_BUILD_DATE }}
platforms: linux/amd64,linux/arm64
env:
DOCKER_BUILD_SUMMARY: false

- name: Create GitHub release (draft)
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Provided by GitHub Actions, doesn't exist in repo secrets
with:
tag_name: ${{ github.event.inputs.VERSION }}
release_name: ${{ github.event.inputs.VERSION }}
body: |
### Quesma ${{ github.event.inputs.VERSION }}
draft: true
prerelease: false

0 comments on commit ccc751e

Please sign in to comment.