echothrust/howtos

A list of OpenBSD (mostly) material

View on GitHub

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:

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.