GNS3 Docker Images
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hub_push 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. #
  3. # push repositories to DockerHub
  4. #
  5. # Requires curl and docker
  6. #
  7. set -e
  8. HUB_USER=$(docker info 2>/dev/null | sed -n 's/^Username:[[:space:]]*//p')
  9. if [ -z "$HUB_USER" ]; then
  10. echo 'Use "docker login" to login into DockerHub.' >&2
  11. exit 1
  12. fi
  13. hub_update() {
  14. local_repo=$1
  15. hub_repo=$HUB_USER/${local_repo##*/}
  16. # get local digest
  17. local_digest=$(docker inspect "$local_repo" --format '{{.Id}}' 2>/dev/null)
  18. [ -z "$local_digest" ] && return
  19. # get remote digest
  20. token=$(curl --silent "https://auth.docker.io/token?scope=repository:${hub_repo}:pull&service=registry.docker.io" | \
  21. tr '\r\n' ' ' | \
  22. sed -n 's/^.*"token": *"\([^"]*\)".*/\1/p')
  23. hub_digest=$(curl --silent \
  24. --header 'Accept: application/vnd.docker.distribution.manifest.v2+json' \
  25. --header "Authorization: Bearer $token" \
  26. "https://registry-1.docker.io/v2/${hub_repo}/manifests/latest" | \
  27. tr '\r\n' ' ' | \
  28. sed -n 's/^.*"config": *{[^}]*"digest": *"\([^"]*\)".*/\1/p')
  29. # push repository, if digest differs
  30. if [ "$local_digest" \!= "$hub_digest" ]; then
  31. echo
  32. echo "*** $hub_repo"
  33. echo
  34. [ "$local_repo" = "$hub_repo" ] || \
  35. docker tag "$local_repo" "$hub_repo"
  36. docker push "$hub_repo"
  37. [ "$local_repo" = "$hub_repo" ] || \
  38. docker rmi "$hub_repo" > /dev/null
  39. fi
  40. }
  41. if [ $# -gt 0 ]; then
  42. # push repos given on command line
  43. for repo in "$@"; do
  44. hub_update "$repo"
  45. done
  46. else
  47. # push (almost) all repos
  48. images=$(sed -e '/^[[:space:]]*$/d' -e '/^[[:space:]]*#/d' hub_images)
  49. for repo in $images; do
  50. hub_update "$repo"
  51. done
  52. fi