Automatically upload docker image to GitHub docker registry

Time:2021-7-25

Original text transferred from:Upload docker image to GitHub docker registry automatically with drone

Automatically upload docker image to GitHub docker registry

I’m glad to receive itGitHubGet started with your beta invitationGitHub Package RegistryRelated functions. You can know from the description file that registry currently supports several packages, such asnpm, gem, docker, mvnandnuget, this article mainly introduces how to use drone to quickly connect the “automatically upload docker image to GitHub Registry” of CI / CD process. At the end, let’s see how to use the docker registry provided by GitHub.

Teaching film

https://www.youtube.com/watch?v=2MgV6NKeeJ…

For more practical videos, please refer to my udemy teaching series

GitHub certification

$ docker login docker.pkg.github.com \
  -u USERNAME \
  -p PASSWORD/TOKEN

The quickest way to log in to GitHub’s docker registry is to log in directly with your personal account and password, and the registry setting isdocker.pkg.github.comHere, please note that although the official has written that you can log in with your personal password, if you log in with OTP, this method is not applicable and safe. Personally, I strongly recommend that you establish an exclusive token in the background.

Automatically upload docker image to GitHub docker registry

amongread:packages and write:packagesPlease check the two scopes. If it is a private repo, thenrepoCheck the option, so you can get a token as a password. You candocker loginLet’s log in and try

Tandem drone CI / CD

From commit to automatic uploading of docker image can be quickly completed through drone. Let’s create it firstDockerfile

FROM plugins/base:multiarch

LABEL maintainer="Bo-Yi Wu <[email protected]>" \
  org.label-schema.name="Drone Workshop" \
  org.label-schema.vendor="Bo-Yi Wu" \
  org.label-schema.schema-version="1.0"

ADD release/linux/amd64/helloworld /bin/

HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "/bin/helloworld", "-ping" ]

ENTRYPOINT ["/bin/helloworld"]

Then through the official dronedockerSuite to complete automated upload

kind: pipeline
name: default

steps:
- name: build
  image: golang:1.13
  commands:
  - make build_linux_amd64

- name: docker
  image: plugins/docker
  settings:
    registry: docker.pkg.github.com
    repo: docker.pkg.github.com/appleboy/test/demo
    auto_tag: true
    auto_tag_suffix: linux-amd64
    username: appleboy
    password:
      from_secret: docker_password

The difference between GitHub and dockerhub is that the format of GitHub isOWNER/REPOSITORY/IMAGE_NAME, notice there’s one more in the middleREPOSITORYDockerhub isOWNER/IMAGE_NAME。 Then go backstage anddocker_passwordAfter setting, you can deploy correctly.

This work adoptsCC agreement, reprint must indicate the author and the link to this article