Skip to content

Commit d745845

Browse files
committed
Fix add-hosts context
Signed-off-by: CrazyMax <[email protected]>
1 parent 1ca185b commit d745845

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

Diff for: .github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ jobs:
416416
if: always()
417417
uses: crazy-max/ghaction-dump-context@v1
418418

419-
addhost:
419+
add-hosts:
420420
runs-on: ubuntu-latest
421421
steps:
422422
-
@@ -432,7 +432,7 @@ jobs:
432432
context: ./test
433433
file: ./test/addhost.Dockerfile
434434
tags: name/app:latest
435-
add-host: |
435+
add-hosts: |
436436
docker:10.180.0.1
437437
foo:10.0.0.1
438438
-

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Following inputs can be used as `step.with` keys
199199

200200
| Name | Type | Description |
201201
|---------------------|----------|------------------------------------|
202-
| `add-host` | List/CSV | Add a [custom host-to-IP mapping](https://docs.docker.com/engine/reference/commandline/build/#add-entries-to-container-hosts-file---add-host) (e.g., `docker:10.180.0.1`) |
202+
| `add-hosts` | List/CSV | List of [customs host-to-IP mapping](https://docs.docker.com/engine/reference/commandline/build/#add-entries-to-container-hosts-file---add-host) (e.g., `docker:10.180.0.1`) |
203203
| `allow` | List/CSV | List of [extra privileged entitlement](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#allow) (e.g., `network.host,security.insecure`) |
204204
| `builder` | String | Builder instance (see [setup-buildx](https://github.com/docker/setup-buildx-action) action) |
205205
| `build-args` | List | List of build-time variables |

Diff for: __tests__/context.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ ccc`],
446446
['context', '.'],
447447
['tag', 'localhost:5000/name/app:latest'],
448448
['file', './test/Dockerfile'],
449+
['add-hosts', 'docker:10.180.0.1,foo:10.0.0.1'],
449450
['network', 'host'],
450451
['load', 'false'],
451452
['no-cache', 'false'],
@@ -455,6 +456,8 @@ ccc`],
455456
[
456457
'buildx',
457458
'build',
459+
'--add-host', 'docker:10.180.0.1',
460+
'--add-host', 'foo:10.0.0.1',
458461
'--file', './test/Dockerfile',
459462
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
460463
'--metadata-file', '/tmp/.docker-build-push-jest/metadata-file',
@@ -469,7 +472,7 @@ ccc`],
469472
new Map<string, string>([
470473
['context', '.'],
471474
['file', './test/Dockerfile'],
472-
['add-host', 'docker:10.180.0.1'],
475+
['add-hosts', 'docker:10.180.0.1\nfoo:10.0.0.1'],
473476
['cgroup-parent', 'foo'],
474477
['shm-size', '2g'],
475478
['ulimit', `nofile=1024:1024
@@ -483,6 +486,7 @@ nproc=3`],
483486
'buildx',
484487
'build',
485488
'--add-host', 'docker:10.180.0.1',
489+
'--add-host', 'foo:10.0.0.1',
486490
'--cgroup-parent', 'foo',
487491
'--file', './test/Dockerfile',
488492
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',

Diff for: action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ branding:
77
color: 'blue'
88

99
inputs:
10-
add-host:
11-
description: "Add a custom host-to-IP mapping (e.g., docker:10.180.0.1)"
10+
add-hosts:
11+
description: "List of a customs host-to-IP mapping (e.g., docker:10.180.0.1)"
1212
required: false
1313
allow:
1414
description: "List of extra privileged entitlement (e.g., network.host,security.insecure)"

Diff for: dist/index.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/context.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as handlebars from 'handlebars';
1414
let _defaultContext, _tmpDir: string;
1515

1616
export interface Inputs {
17-
addHost: string[];
17+
addHosts: string[];
1818
allow: string[];
1919
buildArgs: string[];
2020
builder: string;
@@ -68,7 +68,7 @@ export function tmpNameSync(options?: tmp.TmpNameOptions): string {
6868

6969
export async function getInputs(defaultContext: string): Promise<Inputs> {
7070
return {
71-
addHost: await getInputList('add-host'),
71+
addHosts: await getInputList('add-hosts'),
7272
allow: await getInputList('allow'),
7373
buildArgs: await getInputList('build-args', true),
7474
builder: core.getInput('builder'),
@@ -106,9 +106,9 @@ export async function getArgs(inputs: Inputs, defaultContext: string, buildxVers
106106

107107
async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersion: string): Promise<Array<string>> {
108108
let args: Array<string> = ['build'];
109-
if (inputs.addHost.length > 0) {
110-
args.push('--add-host', inputs.addHost.join(','));
111-
}
109+
await asyncForEach(inputs.addHosts, async addHost => {
110+
args.push('--add-host', addHost);
111+
});
112112
if (inputs.allow.length > 0) {
113113
args.push('--allow', inputs.allow.join(','));
114114
}

0 commit comments

Comments
 (0)