Skip to content

Commit 2ac1177

Browse files
committed
apply tags on each run
1 parent 8a570e7 commit 2ac1177

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ steps:
309309

310310
Specifying your own tags makes it easy to reuse the image later in the pipeline.
311311

312+
These tags are applied each time the plugin runs, whether the image is newly built or already exists and was pulled.
313+
312314
### AWS ECR specific configuration
313315

314316
#### Specifying an ECR repository name

hooks/pre-command

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,26 @@ if ! docker pull "${image}:${tag}"; then
7171
docker "${image_build_args[@]}" ${BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_ADDITIONAL_BUILD_ARGS:-} "${context}" ||
7272
log_fatal "^^^ +++" 1
7373

74-
echo "--- Pushing tags"
75-
echo " - ${tag}"
76-
docker push "${image}:${tag}"
74+
docker tag "${image}:${tag}" "${image}:latest"
7775

78-
results=()
79-
read_list_property 'TAGS'
80-
if [ "${#result[*]}" == "0" ]; then
81-
echo " - latest"
82-
docker tag "${image}:${tag}" "${image}:latest"
83-
docker push "${image}:latest"
84-
else
85-
for other_tag in ${result[@]+"${result[@]}"}; do
86-
echo " - ${other_tag}"
87-
docker tag "${image}:${tag}" "${image}:${other_tag}"
88-
docker push "${image}:${other_tag}"
89-
done
90-
fi
76+
echo "--- Pushing tag ${tag}"
77+
docker push "${image}:${tag}"
9178

79+
echo "--- Pushing tag latest"
80+
docker push "${image}:latest"
9281
fi || echo "Not found"
9382

83+
results=()
84+
read_list_property 'TAGS'
85+
if [ "${#result[*]}" != "0" ]; then
86+
for extra_tag in ${result[@]+"${result[@]}"}; do
87+
echo "--- Pushing extra tags"
88+
echo " - ${extra_tag}"
89+
docker tag "${image}:${tag}" "${image}:${extra_tag}"
90+
docker push "${image}:${extra_tag}"
91+
done
92+
fi
93+
9494
# Support using https://github.com/buildkite-plugins/docker-buildkite-plugin without an image by default
9595
export ${export_env_variable}="${image}:${tag}"
9696

0 commit comments

Comments
 (0)