1ffe3c632Sopenharmony_ci#!/bin/bash 2ffe3c632Sopenharmony_ci 3ffe3c632Sopenharmony_ciset -ex 4ffe3c632Sopenharmony_ci 5ffe3c632Sopenharmony_cicd $(dirname $0)/../../.. 6ffe3c632Sopenharmony_cigit_root=$(pwd) 7ffe3c632Sopenharmony_cicd kokoro/linux/dockerfile 8ffe3c632Sopenharmony_ci 9ffe3c632Sopenharmony_ciDOCKERHUB_ORGANIZATION=protobuftesting 10ffe3c632Sopenharmony_ci 11ffe3c632Sopenharmony_cifor DOCKERFILE_DIR in test/* 12ffe3c632Sopenharmony_cido 13ffe3c632Sopenharmony_ci # Generate image name based on Dockerfile checksum. That works well as long 14ffe3c632Sopenharmony_ci # as can count on dockerfiles being written in a way that changing the logical 15ffe3c632Sopenharmony_ci # contents of the docker image always changes the SHA (e.g. using "ADD file" 16ffe3c632Sopenharmony_ci # cmd in the dockerfile in not ok as contents of the added file will not be 17ffe3c632Sopenharmony_ci # reflected in the SHA). 18ffe3c632Sopenharmony_ci DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR)_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ ) 19ffe3c632Sopenharmony_ci 20ffe3c632Sopenharmony_ci echo $DOCKER_IMAGE_NAME 21ffe3c632Sopenharmony_ci # skip the image if it already exists in the repo 22ffe3c632Sopenharmony_ci curl --silent -f -lSL https://registry.hub.docker.com/v2/repositories/${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}/tags/latest > /dev/null \ 23ffe3c632Sopenharmony_ci && continue 24ffe3c632Sopenharmony_ci 25ffe3c632Sopenharmony_ci docker build -t ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME} ${DOCKERFILE_DIR} 26ffe3c632Sopenharmony_ci 27ffe3c632Sopenharmony_ci # "docker login" needs to be run in advance 28ffe3c632Sopenharmony_ci docker push ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME} 29ffe3c632Sopenharmony_cidone 30