Skip to content

Commit 5bac683

Browse files
Export BUILDKITE_PLUGIN_DOCKER_IMAGE even when skipping pull (#50)
1 parent 7d0833d commit 5bac683

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

hooks/pre-command

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,53 +38,52 @@ read_secrets
3838

3939
if [ "${BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_SKIP_PULL_FROM_CACHE:-}" == "true" ] && image_exists "$tag"; then
4040
echo "Image exists, skipping pull"
41-
exit 0;
42-
fi
43-
44-
echo "--- Pulling image"
41+
else
42+
echo "--- Pulling image"
4543

46-
if ! docker pull "${image}:${tag}"; then
47-
echo '--- Building image'
48-
image_build_args=(
49-
"build"
50-
"--file=${docker_file}"
51-
"--tag=${image}:${tag}"
52-
)
53-
if [[ -n "${target:-}" ]]; then
54-
image_build_args+=(
55-
"--target=${target}"
44+
if ! docker pull "${image}:${tag}"; then
45+
echo '--- Building image'
46+
image_build_args=(
47+
"build"
48+
"--file=${docker_file}"
49+
"--tag=${image}:${tag}"
5650
)
57-
fi
58-
if [[ "${#build_args[@]}" -gt 0 ]]; then
59-
for ba in "${build_args[@]}"; do
51+
if [[ -n "${target:-}" ]]; then
6052
image_build_args+=(
61-
"${ba}"
53+
"--target=${target}"
6254
)
63-
done
64-
fi
65-
if [[ "${#secrets_args[@]}" -gt 0 ]]; then
66-
export DOCKER_BUILDKIT=1
67-
for sa in "${secrets_args[@]}"; do
68-
image_build_args+=(
69-
"${sa}"
70-
)
71-
done
72-
fi
55+
fi
56+
if [[ "${#build_args[@]}" -gt 0 ]]; then
57+
for ba in "${build_args[@]}"; do
58+
image_build_args+=(
59+
"${ba}"
60+
)
61+
done
62+
fi
63+
if [[ "${#secrets_args[@]}" -gt 0 ]]; then
64+
export DOCKER_BUILDKIT=1
65+
for sa in "${secrets_args[@]}"; do
66+
image_build_args+=(
67+
"${sa}"
68+
)
69+
done
70+
fi
7371

74-
echo "Inside $(pwd), running \`docker ${image_build_args[*]} ${context}\`"
75-
# We can't quote BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_ADDITIONAL_BUILD_ARGS, because it's passed here as a string instead of a bash array.
76-
# shellcheck disable=SC2086
77-
docker "${image_build_args[@]}" ${BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_ADDITIONAL_BUILD_ARGS:-} "${context}" ||
78-
log_fatal "^^^ +++" 1
72+
echo "Inside $(pwd), running \`docker ${image_build_args[*]} ${context}\`"
73+
# We can't quote BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_ADDITIONAL_BUILD_ARGS, because it's passed here as a string instead of a bash array.
74+
# shellcheck disable=SC2086
75+
docker "${image_build_args[@]}" ${BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_ADDITIONAL_BUILD_ARGS:-} "${context}" ||
76+
log_fatal "^^^ +++" 1
7977

80-
docker tag "${image}:${tag}" "${image}:latest"
78+
docker tag "${image}:${tag}" "${image}:latest"
8179

82-
echo "--- Pushing tag ${tag}"
83-
docker push "${image}:${tag}"
80+
echo "--- Pushing tag ${tag}"
81+
docker push "${image}:${tag}"
8482

85-
echo "--- Pushing tag latest"
86-
docker push "${image}:latest"
87-
fi || echo "Not found"
83+
echo "--- Pushing tag latest"
84+
docker push "${image}:latest"
85+
fi || echo "Not found"
86+
fi
8887

8988
# Support using https://github.com/buildkite-plugins/docker-buildkite-plugin without an image by default
9089
export ${export_env_variable}="${image}:${tag}"

0 commit comments

Comments
 (0)