Skip to content

Commit 99cca01

Browse files
committed
apply tags on each run
1 parent 8a570e7 commit 99cca01

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ steps:
293293

294294
### Specifying tags to apply to the pushed Docker image
295295

296-
By default, the image is tagged with the `latest` tag in addition to the cache key.
296+
The image is tagged with the cache key and`latest`.
297297

298298
By specifying the `tags` parameter you can specify your own set of tags to apply to the image:
299299

@@ -303,11 +303,10 @@ steps:
303303
plugins:
304304
- seek-oss/docker-ecr-cache#v2.0.0:
305305
tags:
306-
- latest
307306
- build-${BUILDKITE_BUILD_NUMBER}
308307
```
309308

310-
Specifying your own tags makes it easy to reuse the image later in the pipeline.
309+
These tags are applied *each time the plugin runs*, whether the image is newly built or already exists and was pulled.
311310

312311
### AWS ECR specific configuration
313312

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)