Skip to content

Instantly share code, notes, and snippets.

@mpdude
Last active January 15, 2020 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpdude/2e37eca2a9d9b97d6f8038bd48cf1849 to your computer and use it in GitHub Desktop.
Save mpdude/2e37eca2a9d9b97d6f8038bd48cf1849 to your computer and use it in GitHub Desktop.
Build Docker image and push it to GPR
on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: machine-learning-apps/gpr-docker-publish@5b71bce8513330a62b8b61ba846d37caaf2a85ba
with:
image_name: 'my-image-name'
dockerfile_path: 'Dockerfile'
build_context: '.'
cache: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@mpdude
Copy link
Author

mpdude commented Jan 15, 2020

This is the most concise way to do...

  • docker login docker.pkg.github.com ... with your GITHUB_TOKEN
  • docker build ... from the dockerfile_path file with the build_context directory as context
  • Create an image named according to image_name
  • docker push to GPR

This will push into GPR within the repo that the action runs for.

So, for example, if this workflow lives in github.com/myorg/myrepo, the image will show up in github.com/myorg/myrepo/packages, and can be pulled with docker pull docker.pkg.github.com/myorg/myrepo/my-image-name.

Also, the image will be tagged with the SHA1 of the git commit that the action was run for.

cache pulls the latest version of the package and uses it as a build cache.

Note: In order to use the image from an other action, even if the repository hosting the image is public, you will need to docker login.

docker login docker.pkg.github.com --username username-ignored --password-stdin <<< '${{ secrets.GITHUB_TOKEN }}' should be sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment