This Github action builds a Docker image based on a given Git tag reference. The Git tag must start with a "v" prefix, for example "v1.23.4+5"
It's also possible to provide a script which can dynamically set environment variables which are then used as build arguments. That way you can retrieve a version number of a specific dependency via a web service or URL and pass the information to your Dockerfile.
name: Build and release Docker images
on:
push:
branches-ignore:
- '**'
tags:
- 'v*.*.*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Build Docker image
uses: flownative/action-docker-build@v1
with:
tag_ref: ${{ github.ref }}
image_name: flownative/docker-base/base
registry_password: ${{ secrets.GITHUB_TOKEN }}
The following inputs are used by this action:
tag_ref
: The full Git tag reference. This must be a semver tag ref of an existing tagged image. For example,refs/tags/v1.2.5+12
git_sha
: The SHA hash of the Git commit being used for the build. If set, this value is used as a label for the resulting Docker imagegit_repository_url
: The URL leading to the Git repository. If set, this value is used as a label for the resulting Docker imageimage_name
: The image name to build, without tag. For example,flownative/docker-magic-image/magic-image
image_tag
: The image tag to build. If empty, the tag is derived fromtag_ref
: e.g.v1.2.5
registry_password
: Password / token for the Github Docker image registry
After a successful run, the action provides your workflow with the following outputs:
image_name
: The name of the Docker image, which was built and pushedimage_tag
: The tag of the Docker image, which was built and pushedgit_tag
: The tag of the Git commit, which was discovered during the process
This action automatically sets a couple of labels in the built Docker image. This metadata may help you and others identifying the state of source code used at build time.
The following labels are set:
org.label-schema.version
: set to the image tagorg.label-schema.build-date
: set to the current date and time during the buildorg.label-schema.vcs-url
: set to to the Git repository URLorg.label-schema.vcs-ref
: set to the SHA of the current Git commit
Hint: You can review the image labels by running docker inspect
.
If the following file is present as .github/workflows/build-env.sh
,
its exported environment environment variables (you can provide multiple
ones) will be parsed ...
BUILD_ARG_MICRO_VERSION=$(wget -qO- https://versions.flownative.io/projects/base/channels/stable/versions/micro.txt)
export BUILD_ARG_MICRO_VERSION
... and can be used in a Dockerfile as build arguments as such:
…
ARG MICRO_VERSION
ENV MICRO_VERSION=${MICRO_VERSION}
RUN wget --no-hsts https://github.com/zyedidia/micro/releases/download/v${MICRO_VERSION}/micro-${MICRO_VERSION}-linux64.tar.gz; \
tar xfz micro-${MICRO_VERSION}-linux64.tar.gz; \
mv micro-${MICRO_VERSION}/micro /usr/local/bin; \
chmod 755 /usr/local/bin/micro; \
rm -rf micro-${MICRO_VERSION}* /var/log/* /var/lib/dpkg/status-old
…
The repository of this action does not contain the actual implementation
code. Instead, it's referring to a pre-built image in its Dockerfile
in order to save resources and speed up workflow runs.
The code of this action can be found here.