push_testing_images.sh 1.03 KB
Newer Older
1 2 3 4 5 6
#!/bin/bash

set -ex

cd $(dirname $0)/../../..
git_root=$(pwd)
7
cd kokoro/linux/dockerfile
8

9
DOCKERHUB_ORGANIZATION=protobuftesting
10

11
for DOCKERFILE_DIR in test/* release/*
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
do
  # Generate image name based on Dockerfile checksum. That works well as long
  # as can count on dockerfiles being written in a way that changing the logical
  # contents of the docker image always changes the SHA (e.g. using "ADD file"
  # cmd in the dockerfile in not ok as contents of the added file will not be
  # reflected in the SHA).
  DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR)_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ )

  echo $DOCKER_IMAGE_NAME
  # skip the image if it already exists in the repo
  curl --silent -f -lSL https://registry.hub.docker.com/v2/repositories/${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}/tags/latest > /dev/null \
      && continue

  docker build -t ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME} ${DOCKERFILE_DIR}

  # "docker login" needs to be run in advance
  docker push ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}
done