GitHub Action to build and push Docker images with Buildx
Go to file
Nick Adcock b9dd5932a8 Add inputs and examples to readme
Signed-off-by: Nick Adcock <nick.adcock@docker.com>
2020-03-05 16:28:11 +00:00
.github/workflows Add basic CI workflow to test action works 2020-03-05 15:52:50 +00:00
action.yml Add inputs and examples to readme 2020-03-05 16:28:11 +00:00
Dockerfile Add basic CI workflow to test action works 2020-03-05 15:52:50 +00:00
LICENCE Add apache 2 licence file 2020-03-05 15:52:19 +00:00
README.md Add inputs and examples to readme 2020-03-05 16:28:11 +00:00

build-push-action

Builds and pushes docker images and will log in to a docker registry if required

Inputs

Example usage

Inputs

repository

Required Docker repository to tag the image with.

username

Username used to log in to a docker registry. If not set then no login will occur.

password

Password used to log in to a docker registry. If not set then no login will occur.

registry

Server address of docker registry. If not set then will default to Docker Hub.

tags

Comma-delimited list of tags. These will be added to the registry/repository to form the image's tags.

Example:

tags: tag1,tag2

tag_with_ref

Boolean value. Defaults to false.

Automatically tags the built image with the git reference. The format of the tag depends on the type of git reference with all forward slashes replaced with -.

For pushes to a branch the reference will be refs/heads/{branch-name} and the tag will be {branch-name}. If {branch-name} is master then the tag will be latest.

For pull requests the reference will be refs/pull/{pull-request} and the tag will be pr-{pull-request}.

For git tags the reference will be refs/tags/{git-tag} and the tag will be {git-tag}.

Examples:

Git Reference Image tag
refs/heads/master latest
refs/heads/my/branch my-branch
refs/pull/2/merge pr-2-merge
refs/tags/v1.0.0 v1.0.0

tag_with_sha

Boolean value. Defaults to false.

Automatically tags the built image with the git short sha prefixed with sha-.

Example:

Git sha Image tag
676cae2f85471aeff6776463c72881ebd902dcf9 sha-676cae2

path

Path to run the docker build from. Defaults to ..

dockerfile

Name of the Dockerfile (Default is 'path/Dockerfile'). Defaults to {path}/Dockerfile.

target

Sets the target build stage to build.

always_pull

Boolean value. Defaults to false.

Always attempt to pull a newer version of the image.

build_args

Comma-delmited list of build-time variables.

Example:

build_args: arg1=value1,arg2=value2

labels

Comma-delimited list of labels to add to the built image.

Example:

labels: label_name_1=label_value_1,label_name_2=label_value_2

add_git_labels

Boolean value. Defaults to false.

Adds labels with git repo info to the built image.

The labels are:

Label key Example value Description
com.docker.github-actions-actor my-username The actor that kicked off the workflow. For example this could be the username of the user that did the git push.
com.docker.github-actions-sha 676cae2f85471aeff6776463c72881ebd902dcf9 Full git sha of the current commit.

push

Boolean value. Defaults to true.

Whether to push the built image.

Example usage

The following will build the root Dockerfile, tag the image as myorg/myrepository:latest, logs in to docker hub using GitHub secrets, and pushes the image to the docker hub repository myorg/myrepository:

uses: docker/build-push-action@v1
with:
  username: ${{ secrets.DOCKER_USERNAME }}
  password: ${{ secrets.DOCKER_PASSWORD }}
  repository: myorg/myrepository
  tags: latest

The following will build the root Dockerfile, tag the image with the git reference and sha as described above, logs in to docker hub using GitHub secrets, and pushes the image to the docker hub repository myorg/myrepository:

uses: docker/build-push-action@v1
with:
  username: ${{ secrets.DOCKER_USERNAME }}
  password: ${{ secrets.DOCKER_PASSWORD }}
  repository: myorg/myrepository
  tag_with_ref: true
  tag_with_sha: true

The following will only push the image when the event that kicked off the workflow was a push of a git tag:

uses: docker/build-push-action@v1
with:
  username: ${{ secrets.DOCKER_USERNAME }}
  password: ${{ secrets.DOCKER_PASSWORD }}
  repository: myorg/myrepository
  tag_with_ref: true
  push: ${{ startsWith(github.ref, 'refs/tags/') }}

The following builds the mytarget stage and pushes that:

uses: docker/build-push-action@v1
with:
  username: ${{ secrets.DOCKER_USERNAME }}
  password: ${{ secrets.DOCKER_PASSWORD }}
  repository: myorg/myrepository
  tag_with_ref: true
  target: mytarget