Skip to content

Commit b6c221f

Browse files
committed
feat: add parameter for keep-daemon and keep-state when removing Builder Instance
1 parent 35bb0ec commit b6c221f

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,18 @@ Commas separated, Key-Value pairs of driver-specific options to configure the Bu
386386

387387
Example: `memory=100m,cpuset-cpus=1`
388388

389+
##### `keep-daemon` (boolean)
390+
391+
If set to true, will keep the BuildKit daemon running after the buildx context (Builder) is removed. This is useful when you manage BuildKit daemons and buildx contexts independently. Only supported by the `docker-container` and `kubernetes` drivers. Optional when using `remove`.
392+
393+
The default is `false`.
394+
395+
##### `keep-state` (boolean)
396+
397+
If set to true, will keep BuildKit state so it can be reused by a new Builder with the same name, persisting the driver's cache. Currently, only supported by the `docker-container` driver. Optional when using `remove`.
398+
399+
The default is `false`.
400+
389401
##### `name`
390402

391403
Sets the name of the Builder instance to create or use. Required when using `create` or `use` builder paramaters.

hooks/pre-exit

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rm -f "docker-compose.buildkite-${BUILDKITE_BUILD_NUMBER}-override.yml"
1313

1414
# clean up resources after a run command. we do this here so that it will
1515
# run after a job is cancelled
16-
if [[ -n "$(plugin_read_list RUN)" ]] && [[ "$(plugin_read_config CLEANUP "true")" == "true" ]] ; then
16+
if [[ -n "$(plugin_read_list RUN)" ]] && [[ "$(plugin_read_config CLEANUP "true")" == "true" ]]; then
1717
# shellcheck source=lib/run.bash
1818
. "$DIR/../lib/run.bash"
1919

@@ -27,9 +27,20 @@ builder_remove="$(plugin_read_config BUILDER_REMOVE "false")"
2727

2828
if [[ "${builder_remove}" == true ]]; then
2929
if builder_instance_exists "${builder_name}"; then
30+
31+
builder_remove_args=()
32+
33+
if [[ "$(plugin_read_config BUILDER_KEEP_DAEMON "false")" == "true" ]]; then
34+
builder_remove_args+=("--keep-daemon")
35+
fi
36+
37+
if [[ "$(plugin_read_config BUILDER_KEEP_STATE "false")" == "true" ]]; then
38+
builder_remove_args+=("--keep-state")
39+
fi
40+
3041
echo "~~~ :docker: Cleaning up Builder Instance '${builder_name}"
3142
docker buildx stop "${builder_name}"
32-
docker buildx rm "${builder_name}"
43+
docker buildx rm "${builder_name}" ${builder_remove_args:+${builder_remove_args[@]}}
3344
else
3445
echo "~~~ :docker: Cannot remove Builder Instance '${builder_name}' as does not exist"
3546
fi

plugin.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ configuration:
3737
enum: [ "docker-container", "kubernetes", "remote" ]
3838
driver-opt:
3939
type: string
40+
keep-daemon:
41+
type: boolean
42+
keep-state:
43+
type: boolean
4044
name:
4145
type: string
4246
platform:

0 commit comments

Comments
 (0)