1

When publishing a package to the Github Package Registry with docker push, it appears that the package is linked to the most recent commit on the master branch. However, I am currently building my packages on a different branch or off of a specific tag. Is there a way to tie the published image to a specific git commit, so that the source code assets linked to the image are correct?

Sebastian Mendez
  • 2,859
  • 14
  • 25

2 Answers2

1

The help page "Configuring Docker for use with GitHub Package Registry" mentions:

Push the image to GitHub Package Registry:

$ docker push docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME:VERSION

So as long as you have already build and tagged your image from any Git commit you want, the docker push step is independent of said Git commit: it relied solely on what you have built.

You could add variables to your docker build to include Git information.
See "How to Tag Docker Images with Git Commit Information" from Scott Lowe

docker build -t flask-local-build --build-arg GIT_COMMIT=$(git log -1 --format=%h) .
docker inspect flask-local-build | jq '.[].ContainerConfig.Labels'
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The image is built and tagged properly. The problem lies in the fact that the `docker push` step is independent of the said git commit. This means that the commit referenced in the release as well as the assets linked to the release as seen here https://github.com/octokit/webhooks.js/releases/tag/v6.2.2 will not match the actual assets and commit of the image unless you build and publish that image while that commit is the HEAD of master. This means publishing images from older commits/tags or branches off master will not have a properly linked commit. – Sebastian Mendez Aug 21 '19 at 04:46
  • @Sebastian A release is not linked to master HEAD, and is not mentioned in your question (which is about Github Package Registry, not about GitHub repository releases). Still, you can make a release for a specific tag, which in turn would reference the correct Git commit. – VonC Aug 21 '19 at 04:50
  • My problem is that whenever a release is created for a tag that doesn't exist, it defaults to creating a new tag which points to the HEAD of master. For docker images it's commonplace to tag the latest image `latest`, which appears to just not work with Github's package registry. – Sebastian Mendez Aug 21 '19 at 05:19
  • @Sebastian I agree. In your script building and publishing a Docker image, you need to create a tag first and a release. – VonC Aug 21 '19 at 05:56
0

Whenever you are creating image with docker build command, it will take all changes at directory. If you point master then it will build it from master.

To solve this, you may have separate directory for build alone or you write small script which will do the same. E.g you can write a shell script which will clone your repository at temp folder and pull the latest changes from specific branch and create and push the build to registry.

Sivakumar
  • 1,089
  • 1
  • 13
  • 24