From eebf87aed1a1cf36c4e7e9db376c406424caf232 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 30 Jan 2022 18:33:31 +0100 Subject: [PATCH] `add-host` input Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 24 ++++++++++++++++++++++++ README.md | 1 + __tests__/context.test.ts | 2 ++ action.yml | 3 +++ dist/index.js | 4 ++++ src/context.ts | 5 +++++ test/addhost.Dockerfile | 2 ++ 7 files changed, 41 insertions(+) create mode 100644 test/addhost.Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b1e98430..e6b7f5435 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -416,6 +416,30 @@ jobs: if: always() uses: crazy-max/ghaction-dump-context@v1 + addhost: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Build + uses: ./ + with: + context: ./test + file: ./test/addhost.Dockerfile + tags: name/app:latest + add-host: | + docker:10.180.0.1 + foo:10.0.0.1 + - + name: Dump context + if: always() + uses: crazy-max/ghaction-dump-context@v1 + multi: runs-on: ubuntu-latest strategy: diff --git a/README.md b/README.md index dd3111c9c..10c214de9 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,7 @@ Following inputs can be used as `step.with` keys | Name | Type | Description | |---------------------|----------|------------------------------------| +| `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`) | | `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`) | | `builder` | String | Builder instance (see [setup-buildx](https://github.com/docker/setup-buildx-action) action) | | `build-args` | List | List of build-time variables | diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 532159fe1..1bd111f09 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -469,6 +469,7 @@ ccc`], new Map([ ['context', '.'], ['file', './test/Dockerfile'], + ['add-host', 'docker:10.180.0.1'], ['cgroup-parent', 'foo'], ['shm-size', '2g'], ['ulimit', `nofile=1024:1024 @@ -481,6 +482,7 @@ nproc=3`], [ 'buildx', 'build', + '--add-host', 'docker:10.180.0.1', '--cgroup-parent', 'foo', '--file', './test/Dockerfile', '--iidfile', '/tmp/.docker-build-push-jest/iidfile', diff --git a/action.yml b/action.yml index 9f94b261a..c24ed4536 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,9 @@ branding: color: 'blue' inputs: + add-host: + description: "Add a custom host-to-IP mapping (e.g., docker:10.180.0.1)" + required: false allow: description: "List of extra privileged entitlement (e.g., network.host,security.insecure)" required: false diff --git a/dist/index.js b/dist/index.js index c8468dfd1..1d2cc7515 100644 --- a/dist/index.js +++ b/dist/index.js @@ -270,6 +270,7 @@ exports.tmpNameSync = tmpNameSync; function getInputs(defaultContext) { return __awaiter(this, void 0, void 0, function* () { return { + addHost: yield getInputList('add-host'), allow: yield getInputList('allow'), buildArgs: yield getInputList('build-args', true), builder: core.getInput('builder'), @@ -311,6 +312,9 @@ exports.getArgs = getArgs; function getBuildArgs(inputs, defaultContext, buildxVersion) { return __awaiter(this, void 0, void 0, function* () { let args = ['build']; + if (inputs.addHost.length > 0) { + args.push('--add-host', inputs.addHost.join(',')); + } if (inputs.allow.length > 0) { args.push('--allow', inputs.allow.join(',')); } diff --git a/src/context.ts b/src/context.ts index b62112e68..087cca7af 100644 --- a/src/context.ts +++ b/src/context.ts @@ -14,6 +14,7 @@ import * as handlebars from 'handlebars'; let _defaultContext, _tmpDir: string; export interface Inputs { + addHost: string[]; allow: string[]; buildArgs: string[]; builder: string; @@ -67,6 +68,7 @@ export function tmpNameSync(options?: tmp.TmpNameOptions): string { export async function getInputs(defaultContext: string): Promise { return { + addHost: await getInputList('add-host'), allow: await getInputList('allow'), buildArgs: await getInputList('build-args', true), builder: core.getInput('builder'), @@ -104,6 +106,9 @@ export async function getArgs(inputs: Inputs, defaultContext: string, buildxVers async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersion: string): Promise> { let args: Array = ['build']; + if (inputs.addHost.length > 0) { + args.push('--add-host', inputs.addHost.join(',')); + } if (inputs.allow.length > 0) { args.push('--allow', inputs.allow.join(',')); } diff --git a/test/addhost.Dockerfile b/test/addhost.Dockerfile new file mode 100644 index 000000000..040f1cc84 --- /dev/null +++ b/test/addhost.Dockerfile @@ -0,0 +1,2 @@ +FROM busybox +RUN cat /etc/hosts