Skip to content

Commit 8a570e7

Browse files
committed
add parameter to specify docker tags
1 parent cf7058a commit 8a570e7

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,24 @@ steps:
291291
- my-custom-plugin#v1.0.0:
292292
```
293293

294+
### Specifying tags to apply to the pushed Docker image
295+
296+
By default, the image is tagged with the `latest` tag in addition to the cache key.
297+
298+
By specifying the `tags` parameter you can specify your own set of tags to apply to the image:
299+
300+
```yaml
301+
steps:
302+
- command: echo wow
303+
plugins:
304+
- seek-oss/docker-ecr-cache#v2.0.0:
305+
tags:
306+
- latest
307+
- build-${BUILDKITE_BUILD_NUMBER}
308+
```
309+
310+
Specifying your own tags makes it easy to reuse the image later in the pipeline.
311+
294312
### AWS ECR specific configuration
295313

296314
#### Specifying an ECR repository name

hooks/pre-command

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,24 @@ 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-
docker tag "${image}:${tag}" "${image}:latest"
75-
76-
echo "--- Pushing tag ${tag}"
74+
echo "--- Pushing tags"
75+
echo " - ${tag}"
7776
docker push "${image}:${tag}"
7877

79-
echo "--- Pushing tag latest"
80-
docker push "${image}:latest"
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
91+
8192
fi || echo "Not found"
8293

8394
# Support using https://github.com/buildkite-plugins/docker-buildkite-plugin without an image by default

plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ configuration:
3333
type: string
3434
region:
3535
type: string
36+
tags:
37+
type: [array, string]
3638
required: []

0 commit comments

Comments
 (0)