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.
 
 
 
 

59 lines
1.5 KiB

#!/bin/sh
#
# push repositories to DockerHub
#
# Requires curl and docker
#
set -e
HUB_USER=$(docker info 2>/dev/null | sed -n 's/^[[:space:]]*Username:[[:space:]]*//p')
if [ -z "$HUB_USER" ]; then
echo 'Use "docker login" to login into DockerHub.' >&2
exit 1
fi
hub_update() {
local_repo=$1
hub_repo=$HUB_USER/${local_repo##*/}
# get local digest
local_digest=$(docker inspect "$local_repo" --format '{{.Id}}' 2>/dev/null)
[ -z "$local_digest" ] && return
# get remote digest
token=$(curl --silent "https://auth.docker.io/token?scope=repository:${hub_repo}:pull&service=registry.docker.io" | \
tr '\r\n' ' ' | \
sed -n 's/^.*"token": *"\([^"]*\)".*/\1/p')
hub_digest=$(curl --silent \
--header 'Accept: application/vnd.docker.distribution.manifest.v2+json' \
--header "Authorization: Bearer $token" \
"https://registry-1.docker.io/v2/${hub_repo}/manifests/latest" | \
tr '\r\n' ' ' | \
sed -n 's/^.*"config": *{[^}]*"digest": *"\([^"]*\)".*/\1/p')
# push repository, if digest differs
if [ "$local_digest" \!= "$hub_digest" ]; then
echo
echo "*** $hub_repo"
echo
[ "$local_repo" = "$hub_repo" ] || \
docker tag "$local_repo" "$hub_repo"
docker push "$hub_repo"
[ "$local_repo" = "$hub_repo" ] || \
docker rmi "$hub_repo" > /dev/null
fi
}
if [ $# -gt 0 ]; then
# push repos given on command line
for repo in "$@"; do
hub_update "$repo"
done
else
# push (almost) all repos
images=$(sed -e '/^[[:space:]]*$/d' -e '/^[[:space:]]*#/d' hub_images)
for repo in $images; do
hub_update "$repo"
done
fi