This action will build and publish your container images using Docker in a reliable and efficient way. Unlike the official build-and-push-docker-images action, this action uses a separate image repository for caching single- or multi-layer builds, greatly speeding up your builds and saving precious CI resources.
Currently this action contains two stages. The build phase builds your image using cached layers on a registry, whereas the publish phase pushes the built image with all desired tags to the registry.
For the build phase, you will only need to specify your desired image repository names along with registry credentials. Container Builder will automatically detect all stages in your builds and cache them appropriately by pushing them to another image repository.
For the publish phase, you will need to either specify tags
,
tag_with_ref
or tag_with_sha
as otherwise no image (except from the
previously built cache layers) are being pushed to your registry.
The following snippet is an example GitHub workflow (e.g.
.github/workflows/main.yml
) which automatically builds a Dockerfile
in the repository root, caching all stages on GitHub Package Registry
while having the final images on the official Docker Registry:
name: Container Builder
on:
- push
- pull_request
jobs:
container-builder:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Build container image
uses: snapserv/action-container-builder@master
with:
target_repository: my-user/my-image
target_registry_username: {{ secrets.DOCKER_REGISTRY_USERNAME }}
target_registry_password: {{ secrets.DOCKER_REGISTRY_PASSWORD }}
cache_repository: docker.pkg.github.com/${{ github.repository }}/my-image
cache_registry_username: ${{ github.repository_owner }}
cache_registry_password: ${{ secrets.GITHUB_TOKEN }}
Please make sure to use actions/checkout
before this action, as
otherwise Container Builder will be unable to build your image.
-
build
: Boolean, can be set totrue
orfalse
, defaults totrue
. Specifies if the build phase should be executed or skipped. -
target_repository
: Specifies the desired repository name for the container image which is being built by this action, e.g.my-user/my-image
ormy.docker.registry/my-user/my-image
. While you must specify a fully-qualified image repository including the server and namespace, you shall not specify a tag. -
target_registry_username
: Specifies the username for authenticating against the registry used bytarget_repository
. Consult the documentation of your favorite registry to know what you need to specify, however this is equivalent to usingdocker login
. -
target_registry_password
: Specifies the password for authenticating against the registry used bytarget_repository
. Same remarks as fortarget_registry_username
apply. -
cache_repository
: Overrides the default repository name for the cached container build stages. By default, this will be set totarget_repository
suffixed with-cache
. -
cache_registry_username
: Specifies the username for authenticating against the registry used bycache_repository
. If not specified, this defaults to using the same value astarget_registry_username
. -
cache_registry_password
: Specifies the password for authenticating against the registry used bycache_repository
. If not specified, this defaults to using the same value astarget_registry_password
. -
build_context
: Specifies the path to the Docker build context, relative to the repository. This defaults to.
, which would include everything inside your repository. The usage of.dockerignore
applies as usual. -
build_dockerfile
: Specifies a custom path to the Dockerfile which should be built. This defaults toDockerfile
and is relative to thebuild_context
.
-
publish
: Boolean, can be set totrue
orfalse
, defaults totrue
. Specifies if the publish phase should be executed or skipped. -
tags
: Comma-separated list of tags which should always be added when publishing the image to your target registry. -
tag_with_ref
: Boolean, can be set totrue
orfalse
, defaults tofalse
. Automatically tags your image based on the current Git reference. All branch pushes and Git tags are being taken as-is when tagging the image with the exception of a branch calledmaster
, which gets automatically translated tolatest
. Pull requests are being tagged aspr-{number}
. -
tag_with_sha
: Boolean, can be set totrue
orfalse
, defaults tofalse
. Automatically tags your image based on the short Git commit SHA, prefixed withsha-
.
This action produces these outputs which can be used for further processing in a different GitHub action:
build_output
contains the name of the image which was created by the build phase. If the build did not succeed or was skipped, this output will be empty. If you want to test the final image before triggering the publish phase, you can use this image name for running your tests.