Skip to content

Commit c24ab5d

Browse files
committed
add allow input
Signed-off-by: CrazyMax <[email protected]>
1 parent 64673bc commit c24ab5d

File tree

6 files changed

+56
-1
lines changed

6 files changed

+56
-1
lines changed

.github/workflows/ci.yml

+22
Original file line numberDiff line numberDiff line change
@@ -691,3 +691,25 @@ jobs:
691691
./lint.hcl
692692
env:
693693
DOCKER_BUILD_CHECKS_ANNOTATIONS: false
694+
695+
allow:
696+
runs-on: ubuntu-latest
697+
steps:
698+
-
699+
name: Checkout
700+
uses: actions/checkout@v4
701+
-
702+
name: Set up Docker Buildx
703+
uses: docker/setup-buildx-action@v3
704+
with:
705+
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
706+
driver-opts: |
707+
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
708+
-
709+
name: Build
710+
uses: ./
711+
with:
712+
files: |
713+
./test/config.hcl
714+
allow: network.host
715+
targets: app-entitlements

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ The following inputs can be used as `step.with` keys
184184
|----------------|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
185185
| `builder` | String | Builder instance (see [setup-buildx](https://github.com/docker/setup-buildx-action) action) |
186186
| `source` | String | Context to build from. Can be either local (`.`) or a [remote bake definition](https://docs.docker.com/build/customize/bake/file-definition/#remote-definition) |
187+
| `allow` | List/CSV | Allow build to access specified resources (e.g., `network.host`) |
187188
| `files` | List/CSV | List of [bake definition files](https://docs.docker.com/build/customize/bake/file-definition/) |
188189
| `workdir` | String | Working directory of execution |
189190
| `targets` | List/CSV | List of bake targets (`default` target used if empty) |
@@ -193,7 +194,7 @@ The following inputs can be used as `step.with` keys
193194
| `provenance` | Bool/String | [Provenance](https://docs.docker.com/build/attestations/slsa-provenance/) is a shorthand for `--set=*.attest=type=provenance` |
194195
| `push` | Bool | Push is a shorthand for `--set=*.output=type=registry` (default `false`) |
195196
| `sbom` | Bool/String | [SBOM](https://docs.docker.com/build/attestations/sbom/) is a shorthand for `--set=*.attest=type=sbom` |
196-
| `set` | List | List of [targets values to override](https://docs.docker.com/engine/reference/commandline/buildx_bake/#set) (eg: `targetpattern.key=value`) |
197+
| `set` | List | List of [targets values to override](https://docs.docker.com/engine/reference/commandline/buildx_bake/#set) (e.g., `targetpattern.key=value`) |
197198
| `github-token` | String | API token used to authenticate to a Git repository for [remote definitions](https://docs.docker.com/build/bake/remote-definition/) (default `${{ github.token }}`) |
198199

199200
### outputs

__tests__/context.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,23 @@ describe('getArgs', () => {
330330
'--provenance', `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
331331
]
332332
],
333+
[
334+
12,
335+
'0.17.0',
336+
new Map<string, string>([
337+
['allow', 'network.host'],
338+
['load', 'false'],
339+
['no-cache', 'false'],
340+
['push', 'false'],
341+
['pull', 'false'],
342+
]),
343+
[
344+
'bake',
345+
'--allow', 'network.host',
346+
'--metadata-file', metadataJson,
347+
"--provenance", `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`
348+
]
349+
],
333350
])(
334351
'[%d] given %p with %p as inputs, returns %p',
335352
async (num: number, buildxVersion: string, inputs: Map<string, string>, expected: Array<string>) => {

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ inputs:
1313
source:
1414
description: "Context to build from. Can be either local or a remote bake definition"
1515
required: false
16+
allow:
17+
description: "Allow build to access specified resources (e.g., network.host)"
18+
required: false
1619
files:
1720
description: "List of bake definition files"
1821
required: false

src/context.ts

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {Util} from '@docker/actions-toolkit/lib/util';
1111
import {BakeDefinition} from '@docker/actions-toolkit/lib/types/buildx/bake';
1212

1313
export interface Inputs {
14+
allow: string[];
1415
builder: string;
1516
files: string[];
1617
workdir: string;
@@ -28,6 +29,7 @@ export interface Inputs {
2829

2930
export async function getInputs(): Promise<Inputs> {
3031
return {
32+
allow: Util.getInputList('allow'),
3133
builder: core.getInput('builder'),
3234
files: Util.getInputList('files'),
3335
workdir: core.getInput('workdir') || '.',
@@ -80,6 +82,11 @@ async function getBakeArgs(inputs: Inputs, definition: BakeDefinition, toolkit:
8082
if (inputs.source) {
8183
args.push(inputs.source);
8284
}
85+
if (await toolkit.buildx.versionSatisfies('>=0.17.0')) {
86+
if (inputs.allow.length > 0) {
87+
args.push('--allow', inputs.allow.join(','));
88+
}
89+
}
8390
await Util.asyncForEach(inputs.files, async file => {
8491
args.push('--file', file);
8592
});

test/config.hcl

+5
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,8 @@ target "app-proxy" {
4242
inherits = ["app"]
4343
dockerfile = "proxy.Dockerfile"
4444
}
45+
46+
target "app-entitlements" {
47+
inherits = ["app"]
48+
entitlements = ["network.host"]
49+
}

0 commit comments

Comments
 (0)