Manually publish images to GitHub Container Registry (GHCR)

This is just a short little post on how to manually publish images to GitHub Container Registry (GHCR). Looking at the documentation, the usual way to go seems to be to use GitHub Actions and automatically build and publish images onto the registry. However, I do have one use case where images aren’t built via GitHub Actions but offline on a machine of mine, yet I still want to make the images available via ghcr.io. It took me longer than it should have to figure out how to manually authenticate to ghcr.io, so here are the steps.

Generate Personal Access Token

At first, you might think that you can authenticate with GHCR just by simply using your GitHub username and password. That is not the case. To authenticate you will need a token, a so-called personal access token (PAT). Head over to GitHub and click on the drop-down of your user on the top right. From there, head into Settings. Then click on Developer settings at the bottom of the left side. Now click on Personal access token and from there Generate new token:

Next, give your token a meaningful name, choose an expiration of your liking and check the write:packages scope, then hit Generate token at the bottom of the page:

Make sure you copy your token, you will not be able to see it again!

Login to ghcr.io

The next step is rather straightforward. Head into the command line (or whatever tool you are using) and authenticate with ghcr.io via the usual docker login ghcr.io or similar methods. Your username is your GitHub username or the organization that you want to publish the image to and your password is the personal access token. On successful login, you should see something like this:

$ podman login ghcr.io
Username: <your GitHub username/organization>
Password: <your personal access token>
Login Succeeded!

Publish images to GHCR

Once logged in, you are ready to publish your images to ghcr.io/<your GitHub username/organization>/<your package name>, for example:

$ podman push localhost/gvenzl/oracle-xe:latest ghcr.io/gvenzl/oracle-xe:latest

How to download the latest GitHub repo release via command line

I just fiddled around a bit to find out how to download the latest GitHub release via the command line. Turns out that GitHub doesn’t provide a universal download URL to release binaries like it does for the release browser page itself. The latest release page can always be reached via https://github.com/ORGANIZATION/REPO/releases/latest, e.g. https://github.com/gvenzl/csv2db/releases/latest. Unfortunately that is not true for the binaries, which are available under https://github.com/ORGANIZATION/REPO/archive/RELEASE_TAG.zip and https://github.com/ORGANIZATION/REPO/archive/RELEASE_TAG.tar.gz but not under something generic like https://github.com/ORGANIZATION/REPO/archive/latest.zip and https://github.com/ORGANIZATION/REPO/archive/latest.tar.gz

Continue reading “How to download the latest GitHub repo release via command line”