https://github.com/flownative/action-docker-build
A Github action which builds a Docker image with support for dynamic build args
https://github.com/flownative/action-docker-build
actions docker github-actions release-automation
Last synced: 8 months ago
JSON representation
A Github action which builds a Docker image with support for dynamic build args
- Host: GitHub
- URL: https://github.com/flownative/action-docker-build
- Owner: flownative
- License: mit
- Created: 2020-01-06T08:58:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-23T06:52:50.000Z (over 6 years ago)
- Last Synced: 2025-03-21T06:02:21.427Z (over 1 year ago)
- Topics: actions, docker, github-actions, release-automation
- Language: Dockerfile
- Homepage:
- Size: 31.3 KB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](http://opensource.org/licenses/MIT)
[](https://www.flownative.com/en/products/open-source.html)
# Docker Image Build Github Action
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.
## Example workflow
````yaml
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 }}
````
## Inputs
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 image
- `git_repository_url`: The URL leading to the Git repository. If set,
this value is used as a label for the resulting Docker image
- `image_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 from
`tag_ref`: e.g. `v1.2.5`
- `registry_password`: Password / token for the Github Docker image
registry
## Outputs
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 pushed
- `image_tag`: The tag of the Docker image, which was built and pushed
- `git_tag`: The tag of the Git commit, which was discovered during the
process
## Docker image labels
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 tag
- `org.label-schema.build-date`: set to the current date and time during
the build
- `org.label-schema.vcs-url`: set to to the Git repository URL
- `org.label-schema.vcs-ref`: set to the SHA of the current Git commit
Hint: You can review the image labels by running `docker inspect`.
## Dynamic build arguments
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 ...
````bash
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:
```Dockerfile
…
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
…
```
## Implementation Note
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](https://github.com/flownative/docker-action-docker-build).