diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29d8e5ca..60a7a457 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -251,7 +251,7 @@ jobs: uses: ./ with: buildkitd-flags: --debug - config: /tmp/buildkitd.toml + buildkitd-config: /tmp/buildkitd.toml - name: Build uses: docker/build-push-action@v5 @@ -275,7 +275,7 @@ jobs: uses: ./ with: buildkitd-flags: --debug - config-inline: | + buildkitd-config-inline: | debug = true [registry."docker.io"] mirrors = ["mirror.gcr.io"] @@ -564,7 +564,7 @@ jobs: with: context: . - cacheBinary: + cache-binary: runs-on: ubuntu-latest strategy: fail-fast: false diff --git a/README.md b/README.md index 88ba43f0..672fc779 100644 --- a/README.md +++ b/README.md @@ -85,23 +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 | | [Flags for buildkitd](https://docs.docker.com/engine/reference/commandline/buildx_create/#buildkitd-flags) daemon | -| `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. | -| `config`¹ | String | | [BuildKit config file](https://docs.docker.com/engine/reference/commandline/buildx_create/#config) | -| `config-inline`¹ | String | | Same as `config` but inline | -| `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 | - -> * ¹ `config` and `config-inline` are mutually exclusive +| 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 | + +_\* `buildkitd-config` and `buildkitd-config-inline` are mutually exclusive_ ### outputs diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 1342fd2b..7149b278 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -1,12 +1,31 @@ import {beforeEach, describe, expect, jest, test} from '@jest/globals'; +import * as fs from 'fs'; +import * as path from 'path'; import * as uuid from 'uuid'; import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx'; +import {Context} from '@docker/actions-toolkit/lib/context'; import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; import {Toolkit} from '@docker/actions-toolkit/lib/toolkit'; import {Node} from '@docker/actions-toolkit/lib/types/builder'; import * as context from '../src/context'; +const fixturesDir = path.join(__dirname, 'fixtures'); +// prettier-ignore +const tmpDir = path.join(process.env.TEMP || '/tmp', 'setup-buildx-jest'); +const tmpName = path.join(tmpDir, '.tmpname-jest'); + +jest.spyOn(Context, 'tmpDir').mockImplementation((): string => { + if (!fs.existsSync(tmpDir)) { + fs.mkdirSync(tmpDir, {recursive: true}); + } + return tmpDir; +}); + +jest.spyOn(Context, 'tmpName').mockImplementation((): string => { + return tmpName; +}); + jest.mock('uuid'); jest.spyOn(uuid, 'v4').mockReturnValue('9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'); @@ -171,6 +190,42 @@ describe('getCreateArgs', () => { '--name', 'builder-9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d', '--driver', 'unknown', ] + ], + [ + 8, + 'v0.10.3', + new Map([ + ['install', 'false'], + ['use', 'false'], + ['buildkitd-config', path.join(fixturesDir, 'buildkitd.toml')], + ['cache-binary', 'true'], + ['cleanup', 'true'], + ]), + [ + 'create', + '--name', 'builder-9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d', + '--driver', 'docker-container', + '--buildkitd-flags', '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host', + '--config', tmpName, + ] + ], + [ + 9, + 'v0.10.3', + new Map([ + ['install', 'false'], + ['use', 'false'], + ['buildkitd-config-inline', 'debug = true'], + ['cache-binary', 'true'], + ['cleanup', 'true'], + ]), + [ + 'create', + '--name', 'builder-9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d', + '--driver', 'docker-container', + '--buildkitd-flags', '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host', + '--config', tmpName, + ] ] ])( '[%d] given buildx %s and %p as inputs, returns %p', diff --git a/__tests__/fixtures/buildkitd.toml b/__tests__/fixtures/buildkitd.toml new file mode 100644 index 00000000..6f4faa62 --- /dev/null +++ b/__tests__/fixtures/buildkitd.toml @@ -0,0 +1 @@ +debug = true diff --git a/action.yml b/action.yml index bf6cec94..de618014 100644 --- a/action.yml +++ b/action.yml @@ -18,9 +18,15 @@ inputs: description: 'List of additional driver-specific options. (eg. image=moby/buildkit:master)' required: false buildkitd-flags: - description: 'Flags for buildkitd daemon' + description: 'BuildKit daemon flags' default: '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host' required: false + buildkitd-config: + description: 'BuildKit daemon config file' + required: false + buildkitd-config-inline: + description: 'Inline BuildKit daemon config' + required: false install: description: 'Sets up docker build command as an alias to docker buildx build' default: 'false' @@ -35,12 +41,6 @@ inputs: platforms: description: 'Fixed platforms for current node. If not empty, values take priority over the detected ones' required: false - config: - description: 'BuildKit config file' - required: false - config-inline: - description: 'Inline BuildKit config' - required: false append: description: 'Append additional nodes to the builder' required: false @@ -52,6 +52,15 @@ inputs: description: 'Cleanup temp files and remove builder at the end of a job' default: 'true' required: false + # deprecated inputs + config: + description: 'BuildKit daemon config file' + deprecationMessage: 'Use buildkitd-config instead' + required: false + config-inline: + description: 'Inline BuildKit daemon config' + deprecationMessage: 'Use buildkitd-config-inline instead' + required: false outputs: name: diff --git a/src/context.ts b/src/context.ts index 38dbe3a4..cdaa4c38 100644 --- a/src/context.ts +++ b/src/context.ts @@ -13,12 +13,12 @@ export interface Inputs { driver: string; driverOpts: string[]; buildkitdFlags: string; + buildkitdConfig: string; + buildkitdConfigInline: string; platforms: string[]; install: boolean; use: boolean; endpoint: string; - config: string; - configInline: string; append: string; cacheBinary: boolean; cleanup: boolean; @@ -35,8 +35,8 @@ export async function getInputs(): Promise { install: core.getBooleanInput('install'), use: core.getBooleanInput('use'), endpoint: core.getInput('endpoint'), - config: core.getInput('config'), - configInline: core.getInput('config-inline'), + buildkitdConfig: core.getInput('buildkitd-config') || core.getInput('config'), + buildkitdConfigInline: core.getInput('buildkitd-config-inline') || core.getInput('config-inline'), append: core.getInput('append'), cacheBinary: core.getBooleanInput('cache-binary'), cleanup: core.getBooleanInput('cleanup') @@ -64,10 +64,10 @@ export async function getCreateArgs(inputs: Inputs, toolkit: Toolkit): Promise