Sebastian Mendez
Sebastian Mendez

Reputation: 2981

Tying Docker Image to correct Github commit in Github Package Registry

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?

Upvotes: 1

Views: 790

Answers (2)

Sivakumar
Sivakumar

Reputation: 1119

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.

Upvotes: 0

VonC
VonC

Reputation: 1326882

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'

Upvotes: 1

Related Questions