Broadcast your project with Github Package Registry

Broadcast your project with Github Package Registry
Did you take a look at the new features of Github?

We will particularly remember the announcement of Github Actions, now in beta program, which has made quite some noise in the community with the possibility to integrate your CI/CD workflow right in your repository. A nice solution, reducing the quantity of tools to manage the development of your project, his packaging and his deployment.

Since I talk about packaging, maybe some of you have joined the Github Package Registry beta program, our topic of today! If you are interested in the feature (or Github Actions), you can register by now, Users and organisations are now automatically granted access.

According to the documentation, the Github Package Registry is defined as:

GitHub Package Registry is a software package hosting service, similar to npmjs.org, rubygems.org, or hub.docker.com, that allows you to host your packages and code in one place. You can host software packages privately or publicly and use them as dependencies in your projects.

The supported list of packages clients by the Github Package Registry will leave nobody jealous. In this list, we can quote NPM, Rubygem, Maven, Gradle, Docker, .NET, Nuget, Swift. What to be able to cover a large scope of projects.

What does it cost?

Update: The cost chart is now available. So it's totally free for open-source project and you can find the price for private project on the main description page of Github Package Registry.

For now, GitHub has announced that the Package Registry will be free for all repositories during the beta. Nothing has been announced about the price after, with the exception of public and open source repositories; they will stay for free.

How to use it?

The good news is, if you have already the habit to use and deploy on a particular package hosting platform, you will not be out of place. Most of the previously listed clients have their own system of login which will just make you need to change your host endpoint.

Since a good code value thousand commentary, let's practice how to use this new feature! And because I'm more an ops than a developer, I have experimented with a Docker case.

Before starting to type on the command line, don't forget to get a token with the right permission to connect to the package registry. You can find the form in your Github account on the path "Settings/Developer settings/Personal access tokens".

No big surprise here, we enable the permission related to package policies which will also turn on the repo access if we want to use the writing option.

Now we are ready to deploy our release as a package in the registry and to bring a bit more fun, I used Github Actions to :

  1. Login properly to the Github docker registry with the previous token and my Github username to identify myself.
  2. Build my Dockerfile with the correct tag including the Docker Registry URL.
  3. Push my new Docker image to the Github Docker Registry.

And with commands:

docker login docker.pkg.github.com -u USERNAME -p TOKEN 
docker build -t docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME:VERSION 
docker push docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME:VERSION

And that's right! It's all you gonna have to do to upload your package. An increment of the package is now visible in the repository.

You can see the description and pull instruction on the package page below:

If you want to see all that by yourself, you can find my sources for this lab in my trial repository deployed from a Github Action.

Nice, let's try our package!

For that we gonna need another read:package token (or the same if you don't care) which will give you the permission to log in to environment registry.
It's only log in to the Docker registry that we will be able to pull our new image.

echo TOKEN | docker login docker.pkg.github.com -u USERNAME --password-stdin 
docker run --rm docker.pkg.github.com/benguichard/hello-github/hello-github:latest 
> [...] 
> Status: Downloaded newer image for docker.pkg.github.com/benguichard/hello-github/hello-github:latest 
> hello world!

Except the fact that we are forced to authenticate and so losing the interest of the "public" registry, the usage stays easy and quick to pull.

Conclusion

After a quick usage of this feature, we can find a really useful case if you like to keep things together and focus on your productivity. I will certainly use it again to bind it with some Github Actions workflows.

By now, the service is still new and is not ready yet to replace some popular registry such as npmjs.org, rubygems.org, or hub.docker.com as the feature can make it imaginable.

However, the service is operational and the experience is good, no doubt that we will find his position easily in some popular workflows soon!

Show Comments