Skip to content

Commit

Permalink
Add GitHub workflow to build Docker image from tags
Browse files Browse the repository at this point in the history
This workflow will be triggered when any tag, that match the semi-
regex (it is not normal regex, since "." is treated as a normal
period here), is pushed to the repository. The helper script will
then properly extract the version numbers we are interested in,
before the Docker image is built and tagged properly.

More info about this can be found in issue #28:
#28
  • Loading branch information
JonasAlfredsson committed Mar 31, 2021
1 parent e941b81 commit 06c1c67
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/version_extractor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This is a small helper script used to extract and verify the tag that is to
# be set on the Docker container. This file expects that the GitHub Action
# variable GITHUB_REF is passed in as the one and only argument.

if [ -z "${1}" ]; then
echo "Input argument was empty"
exit 1
fi

app_version=$(echo ${1} | sed -n -r -e 's&^refs/.+/v([1-9]\.[0-9]+\.[0-9]+).*$&\1&p')
nginx_version=$(echo ${1} | sed -n -r -e 's&^refs/.+/.*-nginx([1-9]\.[0-9]+\.[0-9]+)$&\1&p')

if [ -n "${app_version}" -a -n "${nginx_version}" ]; then
echo "::set-output name=APP_VERSION::${app_version}"
echo "::set-output name=NGINX_VERSION::${nginx_version}"
else
echo "Could not extract all expected values:"
echo "APP_VERSION=${app_version}"
echo "NGINX_VERSION=${nginx_version}"
exit 1
fi
48 changes: 48 additions & 0 deletions .github/workflows/build_tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: "build-tags"

on:
push:
branches-ignore:
- "**"
tags:
- "v[1-9].[0-9]+.[0-9]+-nginx[1-9].[0-9]+.[0-9]+"

jobs:
docker_buildx:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2

- name: Extract version numbers from GitHub reference
id: tagger
run: bash .github/version_extractor.sh ${GITHUB_REF}

- name: Set up QEMU environment
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push all images
uses: docker/build-push-action@v2
with:
context: ./src
platforms: |
linux/amd64
linux/386
linux/arm64
linux/arm/v7
pull: true
no-cache: true
push: true
build-args: BUILDX_QEMU_ENV=true
tags: |
jonasal/nginx-certbot:${{ steps.tagger.outputs.APP_VERSION }}
jonasal/nginx-certbot:${{ steps.tagger.outputs.APP_VERSION }}-nginx${{ steps.tagger.outputs.NGINX_VERSION }}

0 comments on commit 06c1c67

Please sign in to comment.