How can I update full description on Docker Hub automatically?

﹥>﹥吖頭↗ 提交于 2019-12-03 17:26:14

问题


I'm using Travis CI for building docker images from Dockerfiles and then pushing them to the Docker Hub on success.

I've created an MD file describing the image and how to use it. I want to have the same description on the Docker Hub in the full description section.

As I may update the description in the future, I want to have Travis CI automatically update the description based on the MD file in the repository with the new image.

Anyone knows how to do this?


回答1:


Since the Docker Hub does not expose any API, the only way to send stuff to the Docker Hub remotely is with the docker push command, and this limits use to sending images.

On the other hand, if you let the Docker Hub service build your image for you from a Github or Bitbucket repository, then Docker Hub will update the long description by taking the content of the README.md file found on that repository. See the Understand the build process section from the Docker Hub's Automated Build documentation.

This implies that you host your Dockerfile and README.md files on Github or Bitbucket.


If you really need to first build your image on TravisCI (maybe because you also run automated tests on the built image), then you can have TravisCI trigger a webhook on Docker Hub to tell Docker Hub to build the image once TravisCI determined it was passing the tests.

To do so, in Docker Hub, configure your image as you would for automated build (hence associate a Github or Bitbucket project), but deactivate the automated feature:

Then scroll down on the Build settings page to the Build Trigger section and copy the trigger URL:

Now edit your .travis.yml file and add the following block (mind the <your account> and <your image> placeholders):

after_success:
# notify Docker Hub to make a new build
- >
  [ "$TRAVIS_BRANCH" == "master" ]
  && curl -X POST -H "Content-Type: application/json"
  --data '{"docker_tag_name": "latest"}'
  https://registry.hub.docker.com/u/<your account>/<your image>/trigger/$DOCKER_HUB_TOKEN/

Then go to your project page on the Travis CI website, and open the project settings:

And add the DOCKER_HUB_TOKEN environment variable to your Travis CI project with the trigger token value found on the Docker Hub Build Settings page:

You will still need a Github or Bitbucket repository associated to your Docker Hub project, but Travis CI will be the one to instruct Docker Hub when to build your image.




回答2:


Actually, you can update it using API

local code=$(jq -n --arg msg "$(<README.md)" \
    '{"registry":"registry-1.docker.io","full_description": $msg }' | \
        curl -s -o /dev/null  -L -w "%{http_code}" \
           https://cloud.docker.com/v2/repositories/"${image}"/ \
           -d @- -X PATCH \
           -H "Content-Type: application/json" \
           -H "Authorization: JWT ${token}")

See details here




回答3:


I have a GitHub Action to do this. https://github.com/peter-evans/dockerhub-description

    - name: Docker Hub Description
      uses: peter-evans/dockerhub-description@v2.1.0
      env:
        DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
        DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
        DOCKERHUB_REPOSITORY: peterevans/dockerhub-description

You can also use it independently of GitHub Actions in other CI tools.

    docker run -v $PWD:/workspace \
      -e DOCKERHUB_USERNAME='user1' \
      -e DOCKERHUB_PASSWORD='xxxxx' \
      -e DOCKERHUB_REPOSITORY='my-docker-image' \
      -e README_FILEPATH='/workspace/README.md' \
      peterevans/dockerhub-description:2.1.0



回答4:


you can use a docker container in your pipeline using this

https://hub.docker.com/r/sheogorath/readme-to-dockerhub

Project code

https://github.com/SISheogorath/readme-to-dockerhub

Gitlab CI Pipeline config looks like this

update-readme:
  stage: docs
  image:
    name: docker:stable
  services:
    - docker:dind
  script:
    - docker run --rm -v $(pwd)/README.md:/data/README.md -e DOCKERHUB_USERNAME=$CI_REGISTRY_USER -e DOCKERHUB_PASSWORD=$CI_REGISTRY_PASSWORD -e DOCKERHUB_REPO_PREFIX=$CI_REGISTRY_IMAGE -e DOCKERHUB_REPO_NAME=$CONTAINER_NAME sheogorath/readme-to-dockerhub

Also I've got got a smaller command you can use as well, if you run this in the docker repo it will read README.md by default

  docker run --rm -v $(pwd):/data/ aemdesign/dockerhub-description "$DOCKER_USERNAME" "$DOCKER_PASSWORD" aemdesign/dispatcher

If you want to specify manually run

  docker run --rm -v $(pwd):/data/ aemdesign/dockerhub-description "$DOCKER_USERNAME" "$DOCKER_PASSWORD" aemdesign/dispatcher ./README.md

code: https://github.com/aem-design/docker-dockerhub-description



来源:https://stackoverflow.com/questions/34710513/how-can-i-update-full-description-on-docker-hub-automatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!