Skip to content

Commit f8f648e

Browse files
authored
ci: improve define-docker-variables.sh (#3240)
Use a fuller version that (like we do in other repositories) defines the Docker image for the ci/kokoro/{readme,install,docker} builds. Use the new variables in the CI scripts.
1 parent 58e5786 commit f8f648e

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

ci/kokoro/define-docker-variables.sh

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,40 @@ fi
2929
if [[ -n "${IMAGE+x}" ]]; then
3030
echo "IMAGE is already defined."
3131
else
32-
if [[ -n "${DISTRO_VERSION+x}" ]]; then
33-
readonly IMAGE_BASENAME="gcpp-ci-${DISTRO}-${DISTRO_VERSION}"
34-
if [[ -n "${PROJECT_ID:-}" ]]; then
35-
IMAGE="gcr.io/${PROJECT_ID}/google-cloud-cpp/${IMAGE_BASENAME}"
36-
else
37-
IMAGE="${IMAGE_BASENAME}"
38-
fi
39-
readonly IMAGE
40-
readonly BUILD_OUTPUT="cmake-out/${IMAGE_BASENAME}-${BUILD_NAME}"
41-
readonly BUILD_HOME="cmake-out/home/${IMAGE_BASENAME}-${BUILD_NAME}"
32+
DOCKER_IMAGE_BASENAME="ci-${DISTRO}"
33+
DOCKER_README_IMAGE_BASENAME="ci-readme-${DISTRO}"
34+
DOCKER_INSTALL_IMAGE_BASENAME="ci-install-${DISTRO}"
35+
if [[ -n "${DISTRO_VERSION:-}" ]]; then
36+
DOCKER_IMAGE_BASENAME="${DOCKER_IMAGE_BASENAME}-${DISTRO_VERSION}"
37+
DOCKER_README_IMAGE_BASENAME="${DOCKER_README_IMAGE_BASENAME}-${DISTRO_VERSION}"
38+
DOCKER_INSTALL_IMAGE_BASENAME="${DOCKER_INSTALL_IMAGE_BASENAME}-${DISTRO_VERSION}"
4239
fi
40+
readonly DOCKER_README_IMAGE_BASENAME
41+
readonly DOCKER_INSTALL_IMAGE_BASENAME
42+
readonly DOCKER_IMAGE_BASENAME
43+
44+
if [[ -n "${PROJECT_ID:-}" ]]; then
45+
DOCKER_IMAGE_PREFIX="gcr.io/${PROJECT_ID}/google-cloud-cpp"
46+
else
47+
# We want a prefix that works when running interactively, so it must be a
48+
# (syntactically) valid project id, this works.
49+
DOCKER_IMAGE_PREFIX="gcr.io/cloud-cpp-reserved/google-cloud-cpp"
50+
fi
51+
readonly DOCKER_IMAGE_PREFIX
52+
53+
IMAGE="${DOCKER_IMAGE_PREFIX}/${DOCKER_IMAGE_BASENAME}"
54+
README_IMAGE="${DOCKER_IMAGE_PREFIX}/${DOCKER_README_IMAGE_BASENAME}"
55+
INSTALL_IMAGE="${DOCKER_IMAGE_PREFIX}/${DOCKER_INSTALL_IMAGE_BASENAME}"
56+
readonly IMAGE
57+
readonly README_IMAGE
58+
readonly README_INSTALL_IMAGE
59+
60+
BUILD_OUTPUT="cmake-out/${DOCKER_IMAGE_BASENAME}"
61+
BUILD_HOME="cmake-out/home/${DOCKER_IMAGE_BASENAME}"
62+
if [[ -n "${BUILD_NAME:-}" ]]; then
63+
BUILD_OUTPUT="${BUILD_OUTPUT}-${BUILD_NAME}"
64+
BUILD_HOME="${BUILD_HOME}-${BUILD_NAME}"
65+
fi
66+
readonly BUILD_OUTPUT
67+
readonly BUILD_NAME
4368
fi

ci/kokoro/install/build.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ if [[ -f "${KOKORO_GFILE_DIR:-}/gcr-service-account.json" ]]; then
7171
fi
7272
gcloud auth configure-docker
7373

74-
readonly DEV_IMAGE="gcr.io/${PROJECT_ID}/google-cloud-cpp/test-install-${DISTRO}"
7574
echo "================================================================"
7675
echo "Download existing image (if available) for ${DISTRO} $(date)."
7776
has_cache="false"
78-
if docker pull "${DEV_IMAGE}:latest"; then
77+
if docker pull "${INSTALL_IMAGE}:latest"; then
7978
echo "Existing image successfully downloaded."
8079
has_cache="true"
8180
fi
@@ -90,13 +89,13 @@ devtools_flags=(
9089
"--target" "devtools"
9190
# Create the image with the same tag as the cache we are using, so we can
9291
# upload it.
93-
"-t" "${DEV_IMAGE}:latest"
92+
"-t" "${INSTALL_IMAGE}:latest"
9493
"--build-arg" "NCPU=${NCPU}"
9594
"-f" "ci/kokoro/install/Dockerfile.${DISTRO}"
9695
)
9796

9897
if "${has_cache}"; then
99-
devtools_flags+=("--cache-from=${DEV_IMAGE}:latest")
98+
devtools_flags+=("--cache-from=${INSTALL_IMAGE}:latest")
10099
fi
101100

102101
if [[ "${RUNNING_CI:-}" == "yes" ]] && \
@@ -113,13 +112,13 @@ if "${update_cache}" && [[ -z "${KOKORO_GITHUB_PULL_REQUEST_NUMBER:-}" ]]; then
113112
echo "================================================================"
114113
echo "Uploading updated base image for ${DISTRO} $(date)."
115114
# Do not stop the build on a failure to update the cache.
116-
docker push "${DEV_IMAGE}:latest" || true
115+
docker push "${INSTALL_IMAGE}:latest" || true
117116
fi
118117

119118
echo "================================================================"
120119
echo "Run validation script for INSTALL instructions on ${DISTRO}."
121120
docker build \
122-
"--cache-from=${DEV_IMAGE}:latest" \
121+
"--cache-from=${INSTALL_IMAGE}:latest" \
123122
"--target=install" \
124123
"--build-arg" "NCPU=${NCPU}" \
125124
-f "ci/kokoro/install/Dockerfile.${DISTRO}" .

ci/kokoro/readme/build.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ if [[ -f "${KOKORO_GFILE_DIR:-}/gcr-service-account.json" ]]; then
7171
fi
7272
gcloud auth configure-docker
7373

74-
readonly DEV_IMAGE="gcr.io/${PROJECT_ID:-__invalid-project-id__}/google-cloud-cpp/test-readme-${DISTRO}"
7574
echo "================================================================"
7675
echo "Download existing image (if available) for ${DISTRO} $(date)."
7776
has_cache="false"
78-
if docker pull "${DEV_IMAGE}:latest"; then
77+
if docker pull "${README_IMAGE}:latest"; then
7978
echo "Existing image successfully downloaded."
8079
has_cache="true"
8180
fi
@@ -90,7 +89,7 @@ devtools_flags=(
9089
"--target" "devtools"
9190
# Create the image with the same tag as the cache we are using, so we can
9291
# upload it.
93-
"-t" "${DEV_IMAGE}:latest"
92+
"-t" "${README_IMAGE}:latest"
9493
"--build-arg" "NCPU=${NCPU}"
9594
"-f" "ci/kokoro/readme/Dockerfile.${DISTRO}"
9695
)
@@ -113,13 +112,13 @@ if "${update_cache}" && [[ -z "${KOKORO_GITHUB_PULL_REQUEST_NUMBER:-}" ]]; then
113112
echo "================================================================"
114113
echo "Uploading updated base image for ${DISTRO} $(date)."
115114
# Do not stop the build on a failure to update the cache.
116-
docker push "${DEV_IMAGE}:latest" || true
115+
docker push "${README_IMAGE}:latest" || true
117116
fi
118117

119118
echo "================================================================"
120119
echo "Run validation script for README instructions on ${DISTRO}."
121120
docker build \
122-
"--cache-from=${DEV_IMAGE}:latest" \
121+
"--cache-from=${README_IMAGE}:latest" \
123122
"--target=readme" \
124123
"--build-arg" "NCPU=${NCPU}" \
125124
-f "ci/kokoro/readme/Dockerfile.${DISTRO}" .

0 commit comments

Comments
 (0)