Skip to content

Experimenting GitHub Container Registry

https://www.linkedin.com/in/rvr88/

Recently GitHub announced public beta availability of their Container Registry and I thought I will give it a try. So in this article I will take you through the basic setup for pushing docker images to GitHub Container Registry and do a simple CI.

GitHub Container Registry is free for public images (Public repos) and for private repos, its free during the beta phase. Please keep that in mind, once the beta goes to GA charges are applicable.

The Setup
1. First we need to generate PAT token from the User Settings -> Developer Settings. The PAT token will help you to authenticate with GitHub.

2. Assign the corrections permissions to the Token. You need below permission to push the image to the registry
read:packages
write:packages 
delete:packages 

3. Save your PAT and it is recommended to store it in your environment variables in the machine
$ export CR_PAT=YOUR_TOKEN

First push to GitHub Container Registry
4. Login into GitHub Container Registry using below command in the machine
$ echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin
5. Build the docker image and tag with following name convention
# docker build -t ghcr.io/OWNER/IMAGE_NAME:VERSION .
docker build -t ghcr.io/mysticrenji/react-netcore:1.0 .

6. Push the image to the registry
docker push ghcr.io/mysticrenji/react-netcore:1.0
7. Once you pushed the image, it will available in the packages section in GitHub Home Page

By default the images pushed to GitHub Container Registry will be in private mode by default. You may have to change it, if required.

Putting everything together into CI Process
GibHub Actions yml

name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Docker Push
run: |
echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
docker build . --tag ghcr.io/mysticrenji/react-netcore:$GITHUB_SHA
docker push ghcr.io/mysticrenji/react-netcore:$GITHUB_SHA

That’s all folks. Please try it and let me know your thoughts on this.
Github Repo

This article has been originally taken from my blog

Disclaimer:

The views expressed and the content shared in all published articles on this website are solely those of the respective authors, and they do not necessarily reflect the views of the author’s employer or the techbeatly platform. We strive to ensure the accuracy and validity of the content published on our website. However, we cannot guarantee the absolute correctness or completeness of the information provided. It is the responsibility of the readers and users of this website to verify the accuracy and appropriateness of any information or opinions expressed within the articles. If you come across any content that you believe to be incorrect or invalid, please contact us immediately so that we can address the issue promptly.


https://www.linkedin.com/in/rvr88/
A DevOps engineer by profession, dad, traveler and more interestingly to tweak around stuff inside memory constrained devices during spare time.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.