Skip to content

Commit

Permalink
rename and align config inputs
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Mar 1, 2024
1 parent b7cf918 commit f876da6
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -275,7 +275,7 @@ jobs:
uses: ./
with:
buildkitd-flags: --debug
config-inline: |
buildkitd-config-inline: |
debug = true
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
Expand Down Expand Up @@ -564,7 +564,7 @@ jobs:
with:
context: .

cacheBinary:
cache-binary:
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
55 changes: 55 additions & 0 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -171,6 +190,42 @@ describe('getCreateArgs', () => {
'--name', 'builder-9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d',
'--driver', 'unknown',
]
],
[
8,
'v0.10.3',
new Map<string, string>([
['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<string, string>([
['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',
Expand Down
1 change: 1 addition & 0 deletions __tests__/fixtures/buildkitd.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debug = true
23 changes: 16 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,8 +35,8 @@ export async function getInputs(): Promise<Inputs> {
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')
Expand Down Expand Up @@ -64,10 +64,10 @@ export async function getCreateArgs(inputs: Inputs, toolkit: Toolkit): Promise<A
args.push('--use');
}
if (driverSupportsFlags(inputs.driver)) {
if (inputs.config) {
args.push('--config', toolkit.buildkit.config.resolveFromFile(inputs.config));
} else if (inputs.configInline) {
args.push('--config', toolkit.buildkit.config.resolveFromString(inputs.configInline));
if (inputs.buildkitdConfig) {
args.push('--config', toolkit.buildkit.config.resolveFromFile(inputs.buildkitdConfig));
} else if (inputs.buildkitdConfigInline) {
args.push('--config', toolkit.buildkit.config.resolveFromString(inputs.buildkitdConfigInline));
}
}
if (inputs.endpoint) {
Expand Down

0 comments on commit f876da6

Please sign in to comment.