Github Packages
Publishing images to GitHub Packages
Each time you create a new release on GitHub, you can trigger a workflow to publish your image. The workflow in the example below runs when the release event triggers with the created activity type. For more information on the release event, see “Events that trigger workflows.
In the example workflow below, we use the Docker build-push-action action to build the Docker image, and if the build succeeds, push the built image to GitHub Packages.
The build-push-action options required for GitHub Packages are:
username: You can use the$context to automatically use the username of the user that triggered the workflow run. For more information, see “Context and expression syntax for GitHub Actions.”password: You can use the automatically-generatedGITHUB_TOKENsecret for the password. For more information, see “Authenticating with the GITHUB_TOKEN.”registry: Must be set todocker.pkg.github.com.repository: Must be set in the formatOWNER/REPOSITORY/IMAGE_NAME. For example, for an image namedocto-imagestored on GitHub athttp://github.com/octo-org/octo-repo, therepositoryoption should be set toocto-org/octo-repo/octo-image.
YAML
name: Publish Docker image
on:
release:
types: [published]
jobs:
push_to_registry:
name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Push to GitHub Packages
uses: docker/build-push-action@v1
with:
username: $
password: $
registry: docker.pkg.github.com
repository: my-org/my-repo/my-image
tag_with_ref: true
The above workflow checks out the GitHub repository, and uses the build-push-action action to build and push the Docker image. It sets the build-push-action option tag_with_ref to automatically tag the built Docker image with the Git reference of the workflow event. This workflow is triggered on publishing a GitHub release, so the reference will be the Git tag for the release.