惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Troy Hunt's Blog
Last Week in AI
Last Week in AI
D
DataBreaches.Net
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cyberwarzone
Cyberwarzone
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
Cisco Talos Blog
Cisco Talos Blog
Latest news
Latest news
月光博客
月光博客
博客园 - 司徒正美
C
CERT Recently Published Vulnerability Notes
L
LangChain Blog
Simon Willison's Weblog
Simon Willison's Weblog
The Register - Security
The Register - Security
T
The Blog of Author Tim Ferriss
V
V2EX
F
Fortinet All Blogs
AWS News Blog
AWS News Blog
T
Tor Project blog
V
Vulnerabilities – Threatpost
C
CXSECURITY Database RSS Feed - CXSecurity.com
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
小众软件
小众软件
L
Lohrmann on Cybersecurity
量子位
F
Full Disclosure
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
Intezer
NISL@THU
NISL@THU
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园 - 三生石上(FineUI控件)
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园_首页
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
J
Java Code Geeks
S
Schneier on Security

Martin Heinz's Blog

A Guide to Python's Weak References Using weakref Module Recent Docker BuildKit Features You're Missing Out On Modern Git Commands and Features You Should Be Using Everything You Can Do with Python's textwrap Module Monitoring Indoor Air Quality with Prometheus, Grafana and a CO2 Sensor Everything You Can Do with Python's bisect Module You Don't Need a Dedicated Cache Service - PostgreSQL as a Cache A Collection of Docker Images To Solve All Your Debugging Needs Weird Python "Features" That Might Catch You By Surprise Lessons Learned From Writing 100 Articles Debugging Crashes and Deadlocks in Python using PyStack Goodbye etcd, Hello PostgreSQL: Running Kubernetes with an SQL Database Remote Interactive Debugging of Python Applications Running in Kubernetes The Right Way to Run Shell Commands From Python Real Multithreading is Coming to Python - Learn How You Can Use It Now Python's Missing Batteries: Essential Libraries You're Missing Out On Kubernetes-Native Synthetic Monitoring with Kuberhealthy Make Your CLI Demos a Breeze with Zero Stress and Zero Mistakes Reduce - The Power of a Single Python Function Why I Will Never Use Alpine Linux Ever Again Cgroups - Deep Dive into Resource Management in Kubernetes Dictionary Dispatch Pattern in Python Boost Your Python Application Performance using Continuous Profiling Lazy Evaluation Using Recursive Python Generators Python Magic Methods You Haven't Heard About Getting Started with Mastodon API in Python Backup-and-Restore of Containers with Kubernetes Checkpointing API Getting Started with Google APIs in Python Python CLI Tricks That Don't Require Any Code Whatsoever All The Ways To Introspect Python Objects at Runtime What is Python's "self" Argument, Anyway? Python List Comprehensions Are More Powerful Than You Might Think You Should Be Using Python's Walrus Operator - Here's Why Recipes and Tricks for Effective Structural Pattern Matching in Python It's Time to Say Goodbye to These Obsolete Python Libraries Advanced Features of Kubernetes' Horizontal Pod Autoscaler Data and System Visualization Tools That Will Boost Your Productivity Stop Messing with Kubernetes Finalizers Automate All the Boring Kubernetes Operations with Python End-to-End Monitoring with Grafana Cloud with Minimal Effort Bitly | bit.ly/3JLmSgA Bitly | bit.ly/3uETfbi Bitly | bit.ly/3MI4Iz0 Bitly | bit.ly/3M30D82 Bitly | bit.ly/3oMJ6qR Bitly | bit.ly/3IRD7IK Bitly | bit.ly/3A3B69t Bitly | bit.ly/31lKCYA Bitly | bit.ly/30uviIM Bitly | bit.ly/3E1X2mw Bitly | bit.ly/3Dv7JxP Bitly | bit.ly/3GG1BEz Bitly | bit.ly/3lLavs4 Bitly | bit.ly/39TqP3m Bitly | bit.ly/3A5Mpx8 Bitly | bit.ly/3kGwPl4 Bitly | bit.ly/3iHtulU Bitly | bit.ly/3xGjtKS Bitly | bit.ly/3h8DZg0 Bitly | bit.ly/2RQn1dG Bitly | bit.ly/3p2B5wW The Easiest Way to Debug Kubernetes Workloads Bitly | bit.ly/2PHVudx Cloud Native CI/CD with Tekton - Building Custom Tasks Bitly | bit.ly/3dg3QR9 Bitly | bit.ly/3qHtSkZ Deep Dive into Docker Internals - Union Filesystem Bitly | bit.ly/3qlRAUN Bitly | bit.ly/3pCUJ26 Bitly | bit.ly/3ifZxYr Bitly | bit.ly/34ZhIMt Bitly | bit.ly/3qSO7h0 Bitly | bit.ly/3muGLOk Bitly | bit.ly/35xN79v Bitly | bit.ly/3mLGshK Bitly | bit.ly/2IvkGQl Bitly | bit.ly/2Sk1KFK Bitly | bit.ly/3iCNIL6 Bitly | bit.ly/3beQPpy Saving Your Linux Machine from Certain Death New Features in Python 3.9 You Should Know About Deploy Any Python Project to Kubernetes Analyzing Docker Image Security Recursive SQL Queries with PostgreSQL Automating Every Aspect of Your Python Project Tour of Python Itertools Implementing 2D Physics in Javascript Ultimate Setup for Your Next Python Project Making Python Programs Blazingly Fast Security and Cryptography Mistakes You Are Probably Doing All The Time Going Serverless with OpenFaaS and Golang - Building Optimized Templates Going Serverless with OpenFaaS and Golang - The Ultimate Setup and Workflow Setting Up Swagger Docs for Golang API Building RESTful APIs in Golang Pytest Features, That You Need in Your (Testing) Life Ultimate Setup for Your Next Golang Project Python Tips and Trick, You Haven't Already Seen, Part 2. Tricks for Postgres and Docker that will make your life easier Getting The Most Out of Reading Books - Reading The "Professional Way" Python Tips and Trick, You Haven't Already Seen
Setting up GitHub Package Registry with Docker and Golang
Martin · 2019-10-05 · via Martin Heinz's Blog

Generally, for any programming language, to run your application you need to create some kind of package (npm for JavaScript, NuGet for C#, ...) and then store it somewhere. In case of Docker, people usually just throw their images into Docker Hub, but we now have new alternative here...

The alternative is GitHub Package Registry - it has been in beta for a while now and it seems that more and more people are getting access to it, so it feels like the time has come to explore its features, here specifically for Docker and Go projects.

This post is part of the series "All You Need For Your Next Golang Project", if that sound interesting, go ahead and checkout previous part here.

Note: This article is applicable to any project using docker images, not just Golang.

Why Use GitHub Registry

First of all, why should you even consider switching from, let's say, Docker Hub or any other registry, to GitHub Package Registry:

  • If you are already using GitHub as your SCM, then it makes sense to use GitHub Package Registry, as it allows you to keep everything in one place instead of pushing your packages elsewhere.
  • There is another shiny new (beta) feature of GitHub - Actions, which you can leverage in conjunction with GitHub Package Registry (more on this in another post...).
  • Even though I consider Docker images superior to e.g. npm packages, you can also push those to the GitHub Package Registry, if you prefer non-Docker artifacts.

Let's Do It!

So, now, let's see how to use it. Let's start with building and tagging your image:

Note: If you are working with Go, then you might want to checkout my repository here, where all the GitHub Package Registry fun is already tied into Makefile targets.


docker build -t  docker.pkg.github.com/<gh-username>/<gh-repo-name>/<image-name>:<version> .

# For Example
docker build -t  docker.pkg.github.com/martinheinz/go-project-blueprint/blueprint:latest .

To be able to push images to GitHub Package Registry, you need to name it using format shown above - which really is just URL of registry with your GitHub username and repository name.

Next, how do we access it?

First, to be able to authenticate ourselves with GitHub Package Registry, we need to create personal access token. This access token must have read:packages and write:packages scope and additionally in case you have a private repository, you will have to include repo scope as well.

There is already very nice guide on GitHub help website on how to create personal token, so I'm not gonna copy and paste the steps here. You can read about it here.

Now, that we have personal token let's login:


docker login docker.pkg.github.com -u <USERNAME> -p <GITHUB_TOKEN>

# For Example:
docker login docker.pkg.github.com -u MartinHeinz -p dgni723a3k67fsdj65e # Not an actual token, so don't even try

Finally, time to push our image:


docker push docker.pkg.github.com/<gh-username>/<gh-repo-name>/<image-name>:<version>

# For Example:
docker push docker.pkg.github.com/martinheinz/go-project-blueprint/blueprint:latest

And obviously you can also pull the image:


docker pull docker.pkg.github.com/<gh-username>/<gh-repo-name>/<image-name>:<version>

# For Example:
docker pull docker.pkg.github.com/martinheinz/go-project-blueprint/blueprint:latest

Use It in Your CI/CD Pipeline

Last thing we might want to to do with GitHub Package Registry is to integrate it with CI/CD tools. Let's look at how it can be done with Travis (Full .travis.yml can be found in my repository here):


# ...
- language: go  # Push if on master
      services:
        - docker
      if: branch = master
      script:
        - export GO111MODULE=on
        - go mod vendor  # Download dependencies
        # Important stuff start here 👇
        - echo "$DOCKER_PASSWORD" | docker login docker.pkg.github.com -u "$DOCKER_USERNAME" --password-stdin
        - docker build -t  docker.pkg.github.com/martinheinz/go-project-blueprint/blueprint:latest .
        - docker push docker.pkg.github.com/martinheinz/go-project-blueprint/blueprint:latest
# ...

As you can see above, you can run build and push the same way as on your machine, the only difference is the docker login. Here, we use environment variables specified in Travis UI. Username gets passed to the login command through -u parameter and password using echo into stdin, this is needed, so that we don't end-up with our personal GitHub token being printed in Travis logs.

So, how do we set those environment variables? These are the steps:

  • Navigate to your Travis job settings for your repository e.g. https://travis-ci.com/MartinHeinz/go-project-blueprint/settings
  • Scroll down to Environment Variables section
  • Set variable name to DOCKER_USERNAME and DOCKER_PASSWORD respectively. In case of password (GitHub token) make sure, that Display value in build log is set to false.
  • Click Add and trigger the build

If you are not using Travis and want to use GitHub Webhook to trigger build, then you can use RegistryPackageEvent. This could be useful if you are using for example Jenkins, OpenShift or Kubernetes and want to trigger deployment every time your package is published or updated in GitHub Package Registry.

Words of Caution

One thing you should keep in mind when using GitHub Package Registry is that you can't delete packages that you push to registry. This is so that you don't break projects that depend on your package. You can request package deletion from GitHub Support, but you should not count on them actually deleting anything.

Conclusion

I hope after reading this, you will give the GitHub Package Registry a shot. If you don't have beta access yet, you can sign up here. In case you have any questions, don't hesitate to reach out to me or you can also have a look at my repository, where you can find examples of GitHub Package Registry usage.

Resources