This Action for Docker uses the Git branch or tag as the Docker tag for building and pushing the container.
Forked from elgohr/Publish-Docker-Github-Action and edited to handle git branches and tags by default.
name: Publish Docker
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Publish to Registry
uses: minddocdev/mou-docker-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
sha-tag
is the git commit sha, which was pushed
ref-tag
is the detected sanitized git branch or tag, 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.
with:
name: owner/repository/image
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: docker.pkg.github.com
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: minddocdev/mou-docker-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 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: minddocdev/mou-docker-action@master
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
cache: ${{ github.event_name != 'schedule' }}
Use tags
when you want to pass a list of environment variables as docker tags,
that will also be push into the registry.
Identifiers are separated by comma.
- name: Publish to Registry
uses: minddocdev/mou-docker-action@master
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tags: firsttag,secondtag
Run the tests with
docker build .