This Action for Docker uses the Git branch as the Docker tag for building and pushing the container. Hereby the master-branch is published as the latest-tag.
name: Publish Docker
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Publish to Registry
uses: TakeoffTech/Publish-Docker-Github-Action@master
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
name
is the name of the image you would like to push
username
the login username for the registry
password
the login password for the registry
If you would like to publish the image to other registries, these actions might be helpful
Registry | Action |
---|---|
Amazon Webservices Elastic Container Registry (ECR) | https://github.com/elgohr/ecr-login-action |
Google Cloud Container Registry | https://github.com/elgohr/gcloud-login-action |
tag
is the tag, which was pushed
snapshot-tag
is the tag that is generated by the snapshot-option and pushed
flux-tag
is the tag that is generated by the addfluxtag-option and pushed
digest
is the digest of the image, which was pushed
Use registry
for pushing to a custom registry.
NOTE: GitHub's Docker registry uses a different path format to Docker Hub, as shown below. See Configuring Docker for use with GitHub Package Registry for more information. If you're using GitHub Packages, you might also want to use
${{ github.actor }}
as theusername
.
with:
name: owner/repository/image
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: gcr.io
Publishing to github packages
with:
name: owner/repository/containername
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: docker.pkg.github.com
With this the image url will be docker.pkg.github.com/someorg/somerepo/container:latest
Use tagging
to push an additional image, which is tagged with GITHUB_TAG.
When you would like to think about versioning images, this might be useful.
if: contains(github.ref, 'refs/tags/v')
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tagging: true
Use snapshot
to push an additional image, which is tagged with
{YEAR}{MONTH}{DAY}{HOUR}{MINUTE}{SECOND}{first 6 digits of the git sha}
.
The date was inserted to prevent new builds with external dependencies override older builds with the same sha.
When you would like to think about versioning images, this might be useful.
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
snapshot: true
Use addfluxtag
to push an additional image, which is tagged with
{branch name}-{first 7 digits of the git sha}
.
This should make a uniqe container tag to use for the FluxCD automation documented here:
[https://docs.fluxcd.io/en/latest/references/automated-image-update.html]
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
addfluxtag: true
Use dockerfile
when you would like to explicitly build a Dockerfile.
This might be useful when you have multiple DockerImages.
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
dockerfile: MyDockerFileName
Use workdir
when you would like to change the directory for building.
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
workdir: mySubDirectory
Use context
when you would like to change the Docker build context.
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
context: myContextDirectory
Use buildargs
when you want to pass a list of environment variables as build-args. Identifiers are separated by comma.
All buildargs
will be masked, so that they don't appear in the logs.
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
env:
MY_FIRST: variableContent
MY_SECOND: variableContent
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
buildargs: MY_FIRST,MY_SECOND
Use buildoptions
when you want to configure options for building.
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
buildoptions: "--compress --force-rm"
Use tags
when you want to bring your own tags (separated by comma).
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tags: "latest,another"
Use cache
when you have big images, that you would only like to build partially (changed layers).
CAUTION: Docker builds will cache non-repoducable commands, such as installing packages. If you use this option, your packages will never update. To avoid this, run this action on a schedule with caching disabled to rebuild the cache periodically.
name: Publish to Registry
on:
push:
branches:
- master
schedule:
- cron: '0 2 * * 0' # Weekly on Sundays at 02:00
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
cache: ${{ github.event_name != 'schedule' }}
DEPRECATED: Please use tags instead. This option will be removed in a future release.
Use tag_names
when you want to push tags/release by their git name (e.g. refs/tags/MY_TAG_NAME
).
CAUTION: Images produced by this feature can be override by branches with the same name - without a way to restore.
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tag_names: true