Skip to content

Commit 862bde3

Browse files
committedFeb 25, 2024
add run option
Signed-off-by: Jared Quick <jared.quick@salesforce.com>
1 parent 086b0df commit 862bde3

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed
 

‎README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ Important: this only works when building a single service, an error will be gene
6464

6565
A list of KEY=VALUE that are passed through as build arguments when image is being built.
6666

67-
#### `labels` (build only, string or array)
67+
#### `labels` (build and run only, string or array)
6868

69-
A list of KEY=VALUE that are passed through as service labels when image is being built. These will be merged with any service labels defined in the compose file.
69+
A list of KEY=VALUE that are passed through as service labels when image is being built or ran. These will be merged with any service labels defined in the compose file.
7070

7171
#### `env` or `environment` (run only, string or array)
7272

‎commands/run.sh

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ if [[ "$(plugin_read_config RUN_LABELS "true")" =~ ^(true|on|1)$ ]]; then
9292
)
9393
fi
9494

95+
while read -r label ; do
96+
[[ -n "${label:-}" ]] && run_params+=("--label" "${label}")
97+
done <<< "$(plugin_read_list LABELS)"
98+
9599
# append env vars provided in ENV or ENVIRONMENT, these are newline delimited
96100
while IFS=$'\n' read -r env ; do
97101
[[ -n "${env:-}" ]] && run_params+=("-e" "${env}")

‎plugin.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ configuration:
153153
environment: [ run ]
154154
expand-volume-vars: [ volumes ]
155155
graceful-shutdown: [ run ]
156-
labels: [ build ]
156+
labels: [ build, run ]
157157
leave-volumes: [ run ]
158158
mount-buildkite-agent: [ run ]
159159
mount-checkout: [ run ]

‎tests/run.bats

+25
Original file line numberDiff line numberDiff line change
@@ -1280,3 +1280,28 @@ cmd3"
12801280
assert_output --partial "env-propagation-list desired, but LIST_OF_VARS is not defined!"
12811281
unstub buildkite-agent
12821282
}
1283+
1284+
@test "Run with a list of propagated labels" {
1285+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_LABELS_0="com.buildkite.test=test"
1286+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_LABELS_1="com.buildkite.test2=test2"
1287+
export BUILDKITE_COMMAND="echo hello world"
1288+
1289+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
1290+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false
1291+
1292+
stub docker \
1293+
"compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \
1294+
"compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 --label com.buildkite.test=test --label com.buildkite.test2=test2 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice"
1295+
1296+
stub buildkite-agent \
1297+
"meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1"
1298+
1299+
run "$PWD"/hooks/command
1300+
1301+
assert_success
1302+
refute_output --partial "Pulling"
1303+
assert_output --partial "ran myservice"
1304+
1305+
unstub docker
1306+
unstub buildkite-agent
1307+
}

0 commit comments

Comments
 (0)