Skip to content

Commit

Permalink
Merge pull request kubernetes#269 from ddysher/sync-image-caicloud
Browse files Browse the repository at this point in the history
Sync image to index.caicloud.io and caicloudgcr
  • Loading branch information
ddysher authored and liubog2008 committed Oct 13, 2016
2 parents 52e27cb + 14ec465 commit d59a094
Showing 1 changed file with 56 additions and 11 deletions.
67 changes: 56 additions & 11 deletions hack/caicloud/sync-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,62 @@
# limitations under the License.

# Kubernetes team hosts a lot of images on gcr.io, which is blocked by GFW.
# The script pulls such images from gcr.io, and push to docker hub under
# our dedicated account (caicloudgcr). Prerequisites for running the script:
# 1. The script must be ran on host outside of GFW, of course;
# 2. The host has logged into docker hub using caicloudgcr account.
# The script pulls such images from gcr.io, and push to caicloud private
# registry. The script must be ran on host outside of GFW

KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..


# Sync a single image. $1 will be pulled, then tagged and pushed as $2.
#
# Input:
# $1 The image to pull
# $2 The image to push
function sync_image {
docker pull "$1"
docker tag -f "$1" "$2"
docker push "$2"
}

echo "Login in to index.caicloud.io ..."
docker login index.caicloud.io

# Sync images in gcr.io/google_containers. E.g.
# gcr.io/google_containers/cloudsql-authenticator
# -> index.caicloud.io/google_containers_cloudsql-authenticator
grep -IhEro "gcr.io/google_containers/[^\", ]*" \
--include \*.go --include \*.json --include \*.yaml --include \*.yaml.in --include \*.yml --include Dockerfile --include \*.manifest \
--exclude-dir=${KUBE_ROOT}/examples/guestbook \
${KUBE_ROOT}/test ${KUBE_ROOT}/examples ${KUBE_ROOT}/cluster/addons ${KUBE_ROOT}/cluster/saltbase ${KUBE_ROOT}/contrib ${KUBE_ROOT}/docs | sort -u |
while read -r gcr_image ; do
image=${gcr_image#"gcr.io/google_containers/"}
caicloud_image="index.caicloud.io/google_containers_$image"
echo "++++++++++ Processing $gcr_image, image: $image"
sync_image "$gcr_image" "$caicloud_image"
done

# Sync images in gcr.io/google_samples.
grep -IhEro "gcr.io/google_samples/[^\", ]*" \
--include \*.go --include \*.json --include \*.yaml --include \*.yaml.in --include \*.yml --include Dockerfile --include \*.manifest \
${KUBE_ROOT}/examples/guestbook | sort -u |
while read -r gcr_image ; do
image=${gcr_image#"gcr.io/google_samples/"}
caicloud_image="index.caicloud.io/google_samples_$image"
echo "++++++++++ Processing $gcr_image, image: $image"
sync_image "$gcr_image" "$caicloud_image"
done

# Some other images we want to sync to index.caicloud.io
sync_image registry:2.2 index.caicloud.io/registry:2.2


# Before index.caicloud.io is performant enough, we also sync to caicloudgcr.
echo "Login in to docker hub account caicloudgcr ..."
docker login caicloudgcr

# Sync images in gcr.io/google_containers. E.g.
# gcr.io/google_containers/cloudsql-authenticator
# -> index.caicloud.io/google_containers_cloudsql-authenticator
grep -IhEro "gcr.io/google_containers/[^\", ]*" \
--include \*.go --include \*.json --include \*.yaml --include \*.yaml.in --include \*.yml --include Dockerfile --include \*.manifest \
--exclude-dir=${KUBE_ROOT}/examples/guestbook \
Expand All @@ -30,20 +79,16 @@ grep -IhEro "gcr.io/google_containers/[^\", ]*" \
image=${gcr_image#"gcr.io/google_containers/"}
caicloudgcr_image="caicloudgcr/google_containers_$image"
echo "++++++++++ Processing $gcr_image, image: $image"
docker pull "$gcr_image"
docker tag -f "$gcr_image" "$caicloudgcr_image"
docker push "$caicloudgcr_image"
sync_image "$gcr_image" "$caicloudgcr_image"
done

# Sync images in gcr.io/google_samples.
grep -IhEro "gcr.io/google_samples/[^\", ]*" \
--include \*.go --include \*.json --include \*.yaml --include \*.yaml.in --include \*.yml --include Dockerfile --include \*.manifest \
${KUBE_ROOT}/examples/guestbook | sort -u |
while read -r gcr_image ; do
image=${gcr_image#"gcr.io/google_samples/"}
caicloudgcr_image="caicloudgcr/google_samples_$image"
echo "++++++++++ Processing $gcr_image, image: $image"
docker pull "$gcr_image"
docker tag -f "$gcr_image" "$caicloudgcr_image"
docker push "$caicloudgcr_image"
count=$(($count+1))
sync_image "$gcr_image" "$caicloudgcr_image"
done

0 comments on commit d59a094

Please sign in to comment.