Skip to content

Commit

Permalink
add-host input
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Jan 30, 2022
1 parent d8b0ca6 commit eebf87a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 2 additions & 0 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ ccc`],
new Map<string, string>([
['context', '.'],
['file', './test/Dockerfile'],
['add-host', 'docker:10.180.0.1'],
['cgroup-parent', 'foo'],
['shm-size', '2g'],
['ulimit', `nofile=1024:1024
Expand All @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as handlebars from 'handlebars';
let _defaultContext, _tmpDir: string;

export interface Inputs {
addHost: string[];
allow: string[];
buildArgs: string[];
builder: string;
Expand Down Expand Up @@ -67,6 +68,7 @@ export function tmpNameSync(options?: tmp.TmpNameOptions): string {

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

async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersion: string): Promise<Array<string>> {
let args: Array<string> = ['build'];
if (inputs.addHost.length > 0) {
args.push('--add-host', inputs.addHost.join(','));
}
if (inputs.allow.length > 0) {
args.push('--allow', inputs.allow.join(','));
}
Expand Down
2 changes: 2 additions & 0 deletions test/addhost.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM busybox
RUN cat /etc/hosts

0 comments on commit eebf87a

Please sign in to comment.