blob: e9151303f752229450554bb98a133ea63e228eb5 [file] [log] [blame]
Jan Tattermusch45970612016-11-30 11:23:45 +01001#!/bin/bash
Jan Tattermusch7897ae92017-06-07 22:57:36 +02002# Copyright 2016 gRPC authors.
Jan Tattermusch45970612016-11-30 11:23:45 +01003#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02004# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
Jan Tattermusch45970612016-11-30 11:23:45 +01007#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02008# http://www.apache.org/licenses/LICENSE-2.0
Jan Tattermusch45970612016-11-30 11:23:45 +01009#
Jan Tattermusch7897ae92017-06-07 22:57:36 +020010# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
Jan Tattermusch45970612016-11-30 11:23:45 +010015#
16# Builds selected testing docker images and pushes them to dockerhub.
17# Useful for testing environments where it's impractical (or impossible)
18# to rely on docker images being cached locally after they've been built
19# for the first time (which might be costly especially for some images).
20# NOTE: gRPC docker images intended to be used by end users are NOT
21# pushed using this script (they're built automatically by dockerhub).
22# This script is only for "internal" images we use when testing gRPC.
23
24set -ex
25
26cd $(dirname $0)/../..
27git_root=$(pwd)
28cd -
29
30DOCKERHUB_ORGANIZATION=grpctesting
31
Jan Tattermusch27af5b12017-08-31 16:45:33 +020032for DOCKERFILE_DIR in tools/dockerfile/test/* tools/dockerfile/grpc_artifact_* tools/dockerfile/interoptest/* third_party/rake-compiler-dock
Jan Tattermusch45970612016-11-30 11:23:45 +010033do
34 # Generate image name based on Dockerfile checksum. That works well as long
35 # as can count on dockerfiles being written in a way that changing the logical
36 # contents of the docker image always changes the SHA (e.g. using "ADD file"
37 # cmd in the dockerfile in not ok as contents of the added file will not be
38 # reflected in the SHA).
39 DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR)_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ )
40
41 # skip the image if it already exists in the repo
42 curl --silent -f -lSL https://registry.hub.docker.com/v2/repositories/${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}/tags/latest > /dev/null \
43 && continue
44
45 docker build -t ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME} ${DOCKERFILE_DIR}
46
47 # "docker login" needs to be run in advance
48 docker push ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}
49done