Skip to content

Commit 315b224

Browse files
authored
Merge pull request #478 from Gusto/add-builder-use-once-parameter
Change behavior of `builder.use` to only use builder once
2 parents 58ec2f9 + b5633d7 commit 315b224

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

commands/build.sh

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ if [[ ! "$(plugin_read_config SKIP_PULL "false")" == "true" ]] ; then
115115
build_params+=(--pull)
116116
fi
117117

118+
if [[ -n "$(plugin_read_config BUILDER_NAME "")" ]] && [[ "$(plugin_read_config BUILDER_USE "false")" == "true" ]]; then
119+
build_params+=("--builder" "$(plugin_read_config BUILDER_NAME "")")
120+
fi
121+
118122
if [[ "$(plugin_read_config NO_CACHE "false")" == "true" ]] ; then
119123
build_params+=(--no-cache)
120124
fi

hooks/pre-command

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ fi
7373
if [[ "${builder_use}" == "true" ]]; then
7474
if builder_instance_exists "${builder_name}"; then
7575
echo "~~~ :docker: Using Builder Instance '${builder_name}'"
76-
docker buildx use "${builder_name}"
7776
else
7877
echo "+++ 🚨 Builder Instance '${builder_name}' does not exist"
7978
exit 1

tests/build.bats

+16
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ setup_file() {
3131
unstub docker
3232
}
3333

34+
@test "Build with builder" {
35+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice
36+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILDER_NAME=mybuilder
37+
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILDER_USE=true
38+
39+
stub docker \
40+
"compose -f docker-compose.yml -p buildkite1111 build --pull --builder mybuilder myservice : echo built myservice"
41+
42+
run "$PWD"/hooks/command
43+
44+
assert_success
45+
assert_output --partial "built myservice"
46+
47+
unstub docker
48+
}
49+
3450
@test "Build with no-cache" {
3551
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice
3652
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_NO_CACHE=true

tests/builder-instances.bats

+3-4
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ load '../lib/shared'
105105
assert_success
106106
assert_output --partial "~~~ :docker: Creating Builder Instance 'builder-name' with Driver 'docker-container'"
107107
assert_output --partial "~~~ :warning: Builder Instance 'builder-name' created but will not be used as 'use: true' parameter not specified"
108-
108+
109109
assert_output --partial "~~~ :docker: Using Default Builder 'test' with Driver 'driver'"
110110

111111
unstub docker
@@ -131,8 +131,7 @@ load '../lib/shared'
131131
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILDER_NAME=builder-name
132132

133133
stub docker \
134-
"buildx inspect builder-name : exit 0" \
135-
"buildx use builder-name : exit 0"
134+
"buildx inspect builder-name : exit 0"
136135

137136
run "$PWD"/hooks/pre-command
138137

@@ -198,7 +197,7 @@ load '../lib/shared'
198197

199198
assert_success
200199
assert_output "~~~ :docker: Cleaning up Builder Instance 'builder-name'"
201-
200+
202201
unstub docker
203202
}
204203

0 commit comments

Comments
 (0)