diff --git a/README.md b/README.md index 794ed88..b2f6a01 100644 --- a/README.md +++ b/README.md @@ -85,22 +85,23 @@ The following inputs can be used as `step.with` keys: > platforms: linux/amd64,linux/arm64 > ``` -| Name | Type | Default | Description | -|------------------------------|----------|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `version` | String | | [Buildx](https://github.com/docker/buildx) version. (eg. `v0.3.0`, `latest`, `https://github.com/docker/buildx.git#master`) | -| `driver` | String | `docker-container` | Sets the [builder driver](https://docs.docker.com/engine/reference/commandline/buildx_create/#driver) to be used | -| `driver-opts` | List | | List of additional [driver-specific options](https://docs.docker.com/engine/reference/commandline/buildx_create/#driver-opt) (eg. `image=moby/buildkit:master`) | -| `buildkitd-flags` | String | | [BuildKit daemon flags](https://docs.docker.com/engine/reference/commandline/buildx_create/#buildkitd-flags) | -| `buildkitd-config` \* | String | | [BuildKit daemon config file](https://docs.docker.com/engine/reference/commandline/buildx_create/#config) | -| `buildkitd-config-inline` \* | String | | Same as `buildkitd-config` but inline | -| `install` | Bool | `false` | Sets up `docker build` command as an alias to `docker buildx` | -| `use` | Bool | `true` | Switch to this builder instance | -| `endpoint` | String | | [Optional address for docker socket](https://docs.docker.com/engine/reference/commandline/buildx_create/#description) or context from `docker context ls` | -| `platforms` | List/CSV | | Fixed [platforms](https://docs.docker.com/engine/reference/commandline/buildx_create/#platform) for current node. If not empty, values take priority over the detected ones. | -| `append` | YAML | | [Append additional nodes](https://docs.docker.com/build/ci/github-actions/configure-builder/#append-additional-nodes-to-the-builder) to the builder | -| `cache-binary` | Bool | `true` | Cache buildx binary to GitHub Actions cache backend | -| `cleanup` | Bool | `true` | Cleanup temp files and remove builder at the end of a job | -| `name` | String | Default Docker Context | Name of the builder to create or use. If a builder with this name already exists, it will be used instead of creating a new one. | +| Name | Type | Default | Description | +|------------------------------|----------|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `version` | String | | [Buildx](https://github.com/docker/buildx) version. (eg. `v0.3.0`, `latest`, `https://github.com/docker/buildx.git#master`) | +| `name` | String | | Name of the builder. If not specified, one will be generated or if it already exists, it will be used instead of creating a new one | +| `driver` | String | `docker-container` | Sets the [builder driver](https://docs.docker.com/engine/reference/commandline/buildx_create/#driver) to be used | +| `driver-opts` | List | | List of additional [driver-specific options](https://docs.docker.com/engine/reference/commandline/buildx_create/#driver-opt) (eg. `image=moby/buildkit:master`) | +| `buildkitd-flags` | String | | [BuildKit daemon flags](https://docs.docker.com/engine/reference/commandline/buildx_create/#buildkitd-flags) | +| `buildkitd-config` \* | String | | [BuildKit daemon config file](https://docs.docker.com/engine/reference/commandline/buildx_create/#config) | +| `buildkitd-config-inline` \* | String | | Same as `buildkitd-config` but inline | +| `install` | Bool | `false` | Sets up `docker build` command as an alias to `docker buildx` | +| `use` | Bool | `true` | Switch to this builder instance | +| `endpoint` | String | | [Optional address for docker socket](https://docs.docker.com/engine/reference/commandline/buildx_create/#description) or context from `docker context ls` | +| `platforms` | List/CSV | | Fixed [platforms](https://docs.docker.com/engine/reference/commandline/buildx_create/#platform) for current node. If not empty, values take priority over the detected ones | +| `append` | YAML | | [Append additional nodes](https://docs.docker.com/build/ci/github-actions/configure-builder/#append-additional-nodes-to-the-builder) to the builder | +| `keep-state` | Bool | `false` | Keep BuildKit state on `cleanup`. This is only useful on persistent self-hosted runners | +| `cache-binary` | Bool | `true` | Cache buildx binary to GitHub Actions cache backend | +| `cleanup` | Bool | `true` | Cleanup temp files and remove builder at the end of a job | > [!IMPORTANT] > If you set the `buildkitd-flags` input, the default flags (`--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host`) diff --git a/action.yml b/action.yml index 4c1895d..9d99f95 100644 --- a/action.yml +++ b/action.yml @@ -34,6 +34,9 @@ inputs: description: 'Switch to this builder instance' default: 'true' required: false + name: + description: 'Name of the builder. If not specified, one will be generated or if it already exists, it will be used instead of creating a new one.' + required: false endpoint: description: 'Optional address for docker socket or context from `docker context ls`' required: false @@ -43,6 +46,10 @@ inputs: append: description: 'Append additional nodes to the builder' required: false + keep-state: + description: 'Keep BuildKit state on cleanup. This is only useful on persistent self-hosted runners.' + default: 'false' + required: false cache-binary: description: 'Cache buildx binary to GitHub Actions cache backend' default: 'true' @@ -50,12 +57,6 @@ inputs: cleanup: description: 'Cleanup temp files and remove builder at the end of a job' default: 'true' - keep-state: - description: 'Keep BuildKit state on cleanup. This is only useful on persistent self-hosted runners.' - default: 'false' - required: false - name: - description: 'Builder name set when creating the builder. If not specified, one will be generated.' required: false # TODO: remove deprecated config and config-inline inputs config: diff --git a/src/context.ts b/src/context.ts index bd6162d..5a318d8 100644 --- a/src/context.ts +++ b/src/context.ts @@ -42,17 +42,14 @@ export async function getInputs(): Promise { buildkitdConfig: core.getInput('buildkitd-config') || core.getInput('config'), buildkitdConfigInline: core.getInput('buildkitd-config-inline') || core.getInput('config-inline'), append: core.getInput('append'), + keepState: core.getBooleanInput('keep-state'), cacheBinary: core.getBooleanInput('cache-binary'), - cleanup: core.getBooleanInput('cleanup'), - keepState: core.getBooleanInput('keep-state') + cleanup: core.getBooleanInput('cleanup') }; } export async function getBuilderName(name: string, driver: string): Promise { - if (driver == 'docker') { - return await Docker.context(); - } - return name || `builder-${crypto.randomUUID()}`; + return driver == 'docker' ? await Docker.context() : name || `builder-${crypto.randomUUID()}`; } export async function getCreateArgs(inputs: Inputs, toolkit: Toolkit): Promise> { diff --git a/src/main.ts b/src/main.ts index 2203b3f..9f10f5a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -28,6 +28,12 @@ actionsToolkit.run( const standalone = await toolkit.buildx.isStandalone(); stateHelper.setStandalone(standalone); + if (inputs.keepState && inputs.driver !== 'docker-container') { + // https://docs.docker.com/reference/cli/docker/buildx/rm/#keep-state + throw new Error(`Cannot use keep-state with ${inputs.driver} driver`); + } + stateHelper.setKeepState(inputs.keepState); + await core.group(`Docker info`, async () => { try { await Docker.printVersion(); @@ -115,7 +121,6 @@ actionsToolkit.run( }); } } - stateHelper.setKeepState(inputs.keepState); if (inputs.driver !== 'docker') { await core.group(`Creating a new builder instance`, async () => {