Skip to content

Commit eebf87a

Browse files
committed
add-host input
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
1 parent d8b0ca6 commit eebf87a

File tree

7 files changed

+41
-0
lines changed

7 files changed

+41
-0
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,30 @@ jobs:
416416
if: always()
417417
uses: crazy-max/ghaction-dump-context@v1
418418

419+
addhost:
420+
runs-on: ubuntu-latest
421+
steps:
422+
-
423+
name: Checkout
424+
uses: actions/checkout@v2
425+
-
426+
name: Set up Docker Buildx
427+
uses: docker/setup-buildx-action@v1
428+
-
429+
name: Build
430+
uses: ./
431+
with:
432+
context: ./test
433+
file: ./test/addhost.Dockerfile
434+
tags: name/app:latest
435+
add-host: |
436+
docker:10.180.0.1
437+
foo:10.0.0.1
438+
-
439+
name: Dump context
440+
if: always()
441+
uses: crazy-max/ghaction-dump-context@v1
442+
419443
multi:
420444
runs-on: ubuntu-latest
421445
strategy:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +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`) |
202203
| `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`) |
203204
| `builder` | String | Builder instance (see [setup-buildx](https://github.com/docker/setup-buildx-action) action) |
204205
| `build-args` | List | List of build-time variables |

__tests__/context.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ ccc`],
469469
new Map<string, string>([
470470
['context', '.'],
471471
['file', './test/Dockerfile'],
472+
['add-host', 'docker:10.180.0.1'],
472473
['cgroup-parent', 'foo'],
473474
['shm-size', '2g'],
474475
['ulimit', `nofile=1024:1024
@@ -481,6 +482,7 @@ nproc=3`],
481482
[
482483
'buildx',
483484
'build',
485+
'--add-host', 'docker:10.180.0.1',
484486
'--cgroup-parent', 'foo',
485487
'--file', './test/Dockerfile',
486488
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ 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)"
12+
required: false
1013
allow:
1114
description: "List of extra privileged entitlement (e.g., network.host,security.insecure)"
1215
required: false

dist/index.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as handlebars from 'handlebars';
1414
let _defaultContext, _tmpDir: string;
1515

1616
export interface Inputs {
17+
addHost: string[];
1718
allow: string[];
1819
buildArgs: string[];
1920
builder: string;
@@ -67,6 +68,7 @@ export function tmpNameSync(options?: tmp.TmpNameOptions): string {
6768

6869
export async function getInputs(defaultContext: string): Promise<Inputs> {
6970
return {
71+
addHost: await getInputList('add-host'),
7072
allow: await getInputList('allow'),
7173
buildArgs: await getInputList('build-args', true),
7274
builder: core.getInput('builder'),
@@ -104,6 +106,9 @@ export async function getArgs(inputs: Inputs, defaultContext: string, buildxVers
104106

105107
async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersion: string): Promise<Array<string>> {
106108
let args: Array<string> = ['build'];
109+
if (inputs.addHost.length > 0) {
110+
args.push('--add-host', inputs.addHost.join(','));
111+
}
107112
if (inputs.allow.length > 0) {
108113
args.push('--allow', inputs.allow.join(','));
109114
}

test/addhost.Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM busybox
2+
RUN cat /etc/hosts

0 commit comments

Comments
 (0)