| 1 |
#!/bin/bash |
| 2 |
# Copyright 2016 gRPC authors. |
| 3 |
# |
| 4 |
# 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 |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# 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. |
| 15 |
# |
| 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 |
|
| 24 |
set -ex |
| 25 |
|
| 26 |
cd $(dirname $0)/../.. |
| 27 |
git_root=$(pwd) |
| 28 |
cd - |
| 29 |
|
| 30 |
# Check that docker is installed and sudoless docker works. |
| 31 |
docker run -it debian:11 bash -c 'echo "sudoless docker run works!"' || \ |
| 32 |
(echo "Error: docker not installed or sudoless docker doesn't work?" && exit 1) |
| 33 |
|
| 34 |
# Some of the images we build are for arm64 architecture and the easiest |
| 35 |
# way of allowing them to build locally on x64 machine is to use |
| 36 |
# qemu binfmt-misc hook that automatically runs arm64 binaries under |
| 37 |
# an emulator. |
| 38 |
# Perform a check that "qemu-user-static" with binfmt-misc hook |
| 39 |
# is installed, to give an early warning (otherwise building arm64 images won't work) |
| 40 |
docker run -it arm64v8/debian:11 bash -c 'echo "able to run arm64 docker images with an emulator!"' || \ |
| 41 |
(echo "Error: can't run arm64 images under an emulator. Have you run 'sudo apt-get install qemu-user-static'?" && exit 1) |
| 42 |
|
| 43 |
DOCKERHUB_ORGANIZATION=grpctesting |
| 44 |
|
| 45 |
for DOCKERFILE_DIR in tools/dockerfile/test/* tools/dockerfile/grpc_artifact_* tools/dockerfile/interoptest/* tools/dockerfile/distribtest/* third_party/rake-compiler-dock/*/ |
| 46 |
do |
| 47 |
# Generate image name based on Dockerfile checksum. That works well as long |
| 48 |
# as can count on dockerfiles being written in a way that changing the logical |
| 49 |
# contents of the docker image always changes the SHA (e.g. using "ADD file" |
| 50 |
# cmd in the dockerfile in not ok as contents of the added file will not be |
| 51 |
# reflected in the SHA). |
| 52 |
DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR) |
| 53 |
|
| 54 |
if [ ! -e "$DOCKERFILE_DIR/Dockerfile" ]; then |
| 55 |
continue |
| 56 |
else |
| 57 |
DOCKER_IMAGE_TAG=$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ ) |
| 58 |
fi |
| 59 |
|
| 60 |
# skip the image if it already exists in the repo |
| 61 |
curl --silent -f -lSL https://registry.hub.docker.com/v2/repositories/${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}/tags/${DOCKER_IMAGE_TAG} > /dev/null \ |
| 62 |
&& continue |
| 63 |
|
| 64 |
docker build -t ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${DOCKERFILE_DIR} |
| 65 |
|
| 66 |
# "docker login" needs to be run in advance |
| 67 |
docker push ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} |
| 68 |
done |