odagrun DockerHub API



DockerHub

Purpose

Managing DockerHub Meta data and privacy settings from GitLab-CI, allows uniform and version controlled Meta Data without manual interactions. Besides Meta Data, the API can also delete Tags and docker Repository allowing cleanup intermediate Tags.

Common options for DockerHub API


  • --image=namespace/image need to be a valid docker image repo-name e.g.:
    • centos
    • library/centos
    • registry.hub.docker.com/library/centos
Note: the tag for --image is ignored.
e.g.: centos:latest is valid too.
  • --credentials=$DOCKER_CREDENTIALS

    • Create base64 string credentials with a docker given username and password:
      echo -e -n "myname:mypwd" | base64 -
      
    • verify this and it should return myname:mypwd with:
      echo -e -n "dXNlcm5hbWU6cGFzc3dvcmQ=" | base64 -D  -
      
    • Alternatively, on a linux computer, extract the DOCKER_CREDENTIALS from /root/.docker/config.json and take the auth value from index.docker.io after a succesfull sudo docker login <reponame>:
    {
      "auths": {
          "https://index.docker.io/v1/": {
              "auth": "ZGdxxxxxxxxxxxxxxxxxxUhdw=="
          },
          "quay.io": {
              "auth": "ZGdxxxxxxxxxxxxxxxxZGVsLg=="
          },
          ..........
      }
    }
    


  • optional [--allow-fail] will generate only a Warning in stead of failing the build.


Set OR Create Docker Hub META data


deploy:
  tag: odagrun
  script:
  - >
      DockerHub_set_description
      --image=${repo-name}
      [--credentials=$(base64(username:password))]
      [--set-private[=yes|no|auto|none]]
      [--full_description="my DockerHub long description"]
      [--description="my description"]
      [--allow-fail]

Defaults: with priority as listed

Option values
credentials DOCKER_CREDENTIALS
full_
description
ODAGRUN_IMAGE_DESCRIPTION
file:./description.md
file:./README.md
description ODAGRUN_IMAGE_TITLE
ODAGRUN_IMAGE_REFNAME
ODAGRUN_REVERSE_PROJECT_PATH
set-private auto

DockerHub_set_description also allows to set the repository private:

set-private  
auto set to private if GitLab Project Visibility is private or internal
set to public if GitLab Project Visibility is public
yes
or no options
the Docker repository is set to private.
Also --set-private without options
no the Docker repository is set public.
none the Docker repository private setting is not altered!
!yes
!no
!none
defaults to auto
Info! If the repository for the given image does not exists, it will be created, this allows to create a private repository before a registry_push, ensuring that a private image stays private!
Warning! The Project visibility of GitLab is only available since GitLab version `10.3` in CI, before `v10.3`, the `--set-private=auto` option will result in a public docker Repository.


Delete a Docker image Tag


clean:
  tag: odagrun
  script:
  - >
      DockerHub_delete_tag
      [--allow-fail]
      --image=${image}
      --reference=${tag}
      [--credentials=$DOCKER_CREDENTIALS]

Deletes a given tag for a given repository image.


Delete a Docker repository


clean:
  tag: odagrun
  script:
  - >
      DockerHub_delete_repository
      [--allow-fail]
      --image=${image}
      [--credentials=$(base64(username:password))]

Deletes a repository with given image name.

Danger! This deletes the repository with all tags and description!