Skip to content

Commit 7c41daf

Browse files
committed
build-contexts input
Signed-off-by: CrazyMax <[email protected]>
1 parent e115266 commit 7c41daf

File tree

6 files changed

+50
-19
lines changed

6 files changed

+50
-19
lines changed

.github/workflows/ci.yml

+21
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,27 @@ jobs:
388388
docker:10.180.0.1
389389
foo:10.0.0.1
390390
391+
build-contexts:
392+
runs-on: ubuntu-latest
393+
steps:
394+
-
395+
name: Checkout
396+
uses: actions/checkout@v2
397+
-
398+
name: Set up Docker Buildx
399+
uses: docker/setup-buildx-action@v1
400+
with:
401+
version: v0.8.0
402+
-
403+
name: Build
404+
uses: ./
405+
with:
406+
context: ./test
407+
file: ./test/buildcontext.Dockerfile
408+
build-contexts: |
409+
alpine=docker-image://debian:stable-slim
410+
tags: name/app:latest
411+
391412
multi:
392413
runs-on: ubuntu-latest
393414
strategy:

README.md

+9-18
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,11 @@ Following inputs can be used as `step.with` keys
202202
| `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) |
205-
| `build-args` | List | List of build-time variables |
205+
| `build-args` | List | List of [build-time variables](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#build-arg) |
206+
| `build-contexts` | List | List of additional [build contexts](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#build-context) (e.g., `name=path`) |
206207
| `cache-from` | List | List of [external cache sources](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#cache-from) (e.g., `type=local,src=path/to/dir`) |
207208
| `cache-to` | List | List of [cache export destinations](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#cache-to) (e.g., `type=local,dest=path/to/dir`) |
208-
| `cgroup-parent`¹ | String | Optional [parent cgroup](https://docs.docker.com/engine/reference/commandline/build/#use-a-custom-parent-cgroup---cgroup-parent) for the container used in the build |
209+
| `cgroup-parent` | String | Optional [parent cgroup](https://docs.docker.com/engine/reference/commandline/build/#use-a-custom-parent-cgroup---cgroup-parent) for the container used in the build |
209210
| `context` | String | Build's context is the set of files located in the specified [`PATH` or `URL`](https://docs.docker.com/engine/reference/commandline/build/) (default [Git context](#git-context)) |
210211
| `file` | String | Path to the Dockerfile. (default `{context}/Dockerfile`) |
211212
| `labels` | List | List of metadata for an image |
@@ -214,27 +215,17 @@ Following inputs can be used as `step.with` keys
214215
| `no-cache` | Bool | Do not use cache when building the image (default `false`) |
215216
| `outputs` | List | List of [output destinations](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#output) (format: `type=local,dest=path`) |
216217
| `platforms` | List/CSV | List of [target platforms](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#platform) for build |
217-
| `pull` | Bool | Always attempt to pull a newer version of the image (default `false`) |
218+
| `pull` | Bool | Always attempt to pull all referenced images (default `false`) |
218219
| `push` | Bool | [Push](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#push) is a shorthand for `--output=type=registry` (default `false`) |
219-
| `secrets` | List | List of secrets to expose to the build (e.g., `key=string`, `GIT_AUTH_TOKEN=mytoken`) |
220-
| `secret-files` | List | List of secret files to expose to the build (e.g., `key=filename`, `MY_SECRET=./secret.txt`) |
221-
| `shm-size`¹ | String | Size of [`/dev/shm`](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#-size-of-devshm---shm-size) (e.g., `2g`) |
222-
| `ssh` | List | List of SSH agent socket or keys to expose to the build |
220+
| `secrets` | List | List of [secrets](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#secret) to expose to the build (e.g., `key=string`, `GIT_AUTH_TOKEN=mytoken`) |
221+
| `secret-files` | List | List of [secret files](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#secret) to expose to the build (e.g., `key=filename`, `MY_SECRET=./secret.txt`) |
222+
| `shm-size` | String | Size of [`/dev/shm`](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#-size-of-devshm---shm-size) (e.g., `2g`) |
223+
| `ssh` | List | List of [SSH agent socket or keys](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#ssh) to expose to the build |
223224
| `tags` | List/CSV | List of tags |
224225
| `target` | String | Sets the target stage to build |
225-
| `ulimit`¹ | List | [Ulimit](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#-set-ulimits---ulimit) options (e.g., `nofile=1024:1024`) |
226+
| `ulimit` | List | [Ulimit](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#-set-ulimits---ulimit) options (e.g., `nofile=1024:1024`) |
226227
| `github-token` | String | GitHub Token used to authenticate against a repository for [Git context](#git-context) (default `${{ github.token }}`) |
227228

228-
> ¹ `cgroup-parent`, `shm-size` and `ulimit` are only available using `moby/buildkit:master`
229-
> as builder image atm:
230-
> ```yaml
231-
> - name: Set up Docker Buildx
232-
> uses: docker/setup-buildx-action@v1
233-
> with:
234-
> driver-opts: |
235-
> image=moby/buildkit:master
236-
> ```
237-
238229
### outputs
239230

240231
Following outputs are available

action.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ inputs:
1616
build-args:
1717
description: "List of build-time variables"
1818
required: false
19+
build-contexts:
20+
description: "List of additional build contexts (e.g., name=path)"
21+
required: false
1922
builder:
2023
description: "Builder instance"
2124
required: false
@@ -55,7 +58,7 @@ inputs:
5558
description: "List of target platforms for build"
5659
required: false
5760
pull:
58-
description: "Always attempt to pull a newer version of the image"
61+
description: "Always attempt to pull all referenced images"
5962
required: false
6063
default: 'false'
6164
push:

dist/index.js

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

src/context.ts

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface Inputs {
1717
addHosts: string[];
1818
allow: string[];
1919
buildArgs: string[];
20+
buildContexts: string[];
2021
builder: string;
2122
cacheFrom: string[];
2223
cacheTo: string[];
@@ -71,6 +72,7 @@ export async function getInputs(defaultContext: string): Promise<Inputs> {
7172
addHosts: await getInputList('add-hosts'),
7273
allow: await getInputList('allow'),
7374
buildArgs: await getInputList('build-args', true),
75+
buildContexts: await getInputList('build-contexts', true),
7476
builder: core.getInput('builder'),
7577
cacheFrom: await getInputList('cache-from', true),
7678
cacheTo: await getInputList('cache-to', true),
@@ -115,6 +117,11 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio
115117
await asyncForEach(inputs.buildArgs, async buildArg => {
116118
args.push('--build-arg', buildArg);
117119
});
120+
if (buildx.satisfies(buildxVersion, '>=0.8.0')) {
121+
await asyncForEach(inputs.buildContexts, async buildContext => {
122+
args.push('--build-context', buildContext);
123+
});
124+
}
118125
await asyncForEach(inputs.cacheFrom, async cacheFrom => {
119126
args.push('--cache-from', cacheFrom);
120127
});

test/buildcontext.Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# syntax=docker/dockerfile-upstream:master
2+
FROM alpine
3+
RUN cat /etc/*release

0 commit comments

Comments
 (0)