Skip to content

Commit f6efb5f

Browse files
committed
platforms input
Signed-off-by: CrazyMax <[email protected]>
1 parent 2dfca37 commit f6efb5f

File tree

5 files changed

+64
-20
lines changed

5 files changed

+64
-20
lines changed

.github/workflows/ci.yml

+15
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,18 @@ jobs:
449449
-
450450
name: List builder platforms
451451
run: echo ${{ steps.buildx.outputs.platforms }}
452+
453+
platforms:
454+
runs-on: ubuntu-latest
455+
steps:
456+
-
457+
name: Checkout
458+
uses: actions/checkout@v3
459+
-
460+
name: Set up QEMU
461+
uses: docker/setup-qemu-action@v2
462+
-
463+
name: Set up Docker Buildx
464+
uses: ./
465+
with:
466+
platforms: linux/amd64

README.md

+23-20
Original file line numberDiff line numberDiff line change
@@ -71,33 +71,36 @@ jobs:
7171
7272
### inputs
7373
74-
Following inputs can be used as `step.with` keys
75-
76-
| Name | Type | Description |
77-
|-------------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
78-
| `version` | String | [Buildx](https://github.com/docker/buildx) version. (eg. `v0.3.0`, `latest`, `https://github.com/docker/buildx.git#master`) |
79-
| `driver` | String | Sets the [builder driver](https://docs.docker.com/engine/reference/commandline/buildx_create/#driver) to be used (default `docker-container`) |
80-
| `driver-opts` | CSV | List of additional [driver-specific options](https://docs.docker.com/engine/reference/commandline/buildx_create/#driver-opt) (eg. `image=moby/buildkit:master`) |
81-
| `buildkitd-flags` | String | [Flags for buildkitd](https://docs.docker.com/engine/reference/commandline/buildx_create/#buildkitd-flags) daemon (since [buildx v0.3.0](https://github.com/docker/buildx/releases/tag/v0.3.0)) |
82-
| `install` | Bool | Sets up `docker build` command as an alias to `docker buildx` (default `false`) |
83-
| `use` | Bool | Switch to this builder instance (default `true`) |
84-
| `endpoint` | String | [Optional address for docker socket](https://docs.docker.com/engine/reference/commandline/buildx_create/#description) or context from `docker context ls` |
85-
| `config`¹ | String | [BuildKit config file](https://docs.docker.com/engine/reference/commandline/buildx_create/#config) |
86-
| `config-inline`¹ | String | Same as `config` but inline |
87-
| `append` | YAML | [Append additional nodes](docs/advanced/append-nodes.md) to the builder |
74+
Following inputs can be used as `step.with` keys:
8875

89-
> * ¹ `config` and `config-inline` are mutually exclusive
90-
91-
> `CSV` type must be a newline-delimited string
92-
> ```yaml
93-
> driver-opts: image=moby/buildkit:master
94-
> ```
76+
> `List` type is a newline-delimited string
9577
> ```yaml
9678
> driver-opts: |
9779
> image=moby/buildkit:master
9880
> network=host
9981
> ```
10082

83+
> `CSV` type must be a newline-delimited string
84+
> ```yaml
85+
> platforms: linux/amd64,linux/arm64
86+
> ```
87+
88+
| Name | Type | Description |
89+
|-------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
90+
| `version` | String | [Buildx](https://github.com/docker/buildx) version. (eg. `v0.3.0`, `latest`, `https://github.com/docker/buildx.git#master`) |
91+
| `driver` | String | Sets the [builder driver](https://docs.docker.com/engine/reference/commandline/buildx_create/#driver) to be used (default `docker-container`) |
92+
| `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`) |
93+
| `buildkitd-flags` | String | [Flags for buildkitd](https://docs.docker.com/engine/reference/commandline/buildx_create/#buildkitd-flags) daemon (since [buildx v0.3.0](https://github.com/docker/buildx/releases/tag/v0.3.0)) |
94+
| `install` | Bool | Sets up `docker build` command as an alias to `docker buildx` (default `false`) |
95+
| `use` | Bool | Switch to this builder instance (default `true`) |
96+
| `endpoint` | String | [Optional address for docker socket](https://docs.docker.com/engine/reference/commandline/buildx_create/#description) or context from `docker context ls` |
97+
| `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. |
98+
| `config`¹ | String | [BuildKit config file](https://docs.docker.com/engine/reference/commandline/buildx_create/#config) |
99+
| `config-inline`¹ | String | Same as `config` but inline |
100+
| `append` | YAML | [Append additional nodes](docs/advanced/append-nodes.md) to the builder |
101+
102+
> * ¹ `config` and `config-inline` are mutually exclusive
103+
101104
### outputs
102105

103106
Following outputs are available

__tests__/context.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ describe('getCreateArgs', () => {
9191
'tls://foo:1234'
9292
]
9393
],
94+
[
95+
4,
96+
new Map<string, string>([
97+
['driver', 'remote'],
98+
['platforms', 'linux/arm64,linux/arm/v7'],
99+
['endpoint', 'tls://foo:1234'],
100+
['install', 'false'],
101+
['use', 'true'],
102+
]),
103+
[
104+
'create',
105+
'--name', 'builder-9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d',
106+
'--driver', 'remote',
107+
'--platform', 'linux/arm64,linux/arm/v7',
108+
'--use',
109+
'tls://foo:1234'
110+
]
111+
],
94112
])(
95113
'[%d] given %p as inputs, returns %p',
96114
async (num: number, inputs: Map<string, string>, expected: Array<string>) => {

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ inputs:
3232
endpoint:
3333
description: 'Optional address for docker socket or context from `docker context ls`'
3434
required: false
35+
platforms:
36+
description: 'Fixed platforms for current node. If not empty, values take priority over the detected ones'
37+
required: false
3538
config:
3639
description: 'BuildKit config file'
3740
required: false

src/context.ts

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface Inputs {
2929
driver: string;
3030
driverOpts: string[];
3131
buildkitdFlags: string;
32+
platforms: string[];
3233
install: boolean;
3334
use: boolean;
3435
endpoint: string;
@@ -44,6 +45,7 @@ export async function getInputs(): Promise<Inputs> {
4445
driver: core.getInput('driver') || 'docker-container',
4546
driverOpts: await getInputList('driver-opts', true),
4647
buildkitdFlags: core.getInput('buildkitd-flags') || '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
48+
platforms: await getInputList('platforms'),
4749
install: core.getBooleanInput('install'),
4850
use: core.getBooleanInput('use'),
4951
endpoint: core.getInput('endpoint'),
@@ -67,6 +69,9 @@ export async function getCreateArgs(inputs: Inputs, buildxVersion: string): Prom
6769
args.push('--buildkitd-flags', inputs.buildkitdFlags);
6870
}
6971
}
72+
if (inputs.platforms.length > 0) {
73+
args.push('--platform', inputs.platforms.join(','));
74+
}
7075
if (inputs.use) {
7176
args.push('--use');
7277
}

0 commit comments

Comments
 (0)