mirror of
https://github.com/docker/bake-action.git
synced 2026-06-05 17:48:40 +02:00
Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a5dfed355 | |||
| e2b72bb7a3 | |||
| 27749bcdf3 | |||
| 5f156eafc0 | |||
| b116023d12 | |||
| 2fd7073488 | |||
| 73b0efa7a0 | |||
| 29394f21ba | |||
| 908c98f276 | |||
| b6cc37d5b9 | |||
| dc557970d4 | |||
| 75d6ba252c | |||
| 49c6172f1b | |||
| c2d911883d | |||
| 1a7ee794b9 | |||
| d905335142 | |||
| c8060c064e | |||
| c4a4a41172 | |||
| 8529ef025a | |||
| 9775caf8a9 | |||
| 11d4bbed70 | |||
| 33a1cc61da | |||
| f423d25e3d | |||
| 017aa056d6 | |||
| ac8675748b | |||
| efcacd553e | |||
| 7ea090ddec | |||
| 9c020d87bf | |||
| 2930c788f0 | |||
| 5adcaf655c | |||
| 27bea1331e | |||
| dd824dd722 | |||
| ccc779750c | |||
| 9ef2cc9961 | |||
| b5447a726f | |||
| cd4ed51f40 | |||
| a1e9d9056a | |||
| a36b3d6c7b | |||
| 8ee01addc6 | |||
| fe4533e90f | |||
| 52a1696536 | |||
| 31ed06a2f8 |
@@ -398,3 +398,127 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
./test/config.hcl
|
./test/config.hcl
|
||||||
|
|
||||||
|
git-context:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
|
||||||
|
driver-opts: |
|
||||||
|
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
|
||||||
|
-
|
||||||
|
name: Build
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
source: "{{defaultContext}}"
|
||||||
|
|
||||||
|
git-context-and-local:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
|
||||||
|
driver-opts: |
|
||||||
|
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
|
||||||
|
-
|
||||||
|
name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
-
|
||||||
|
name: Build
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
source: "{{defaultContext}}"
|
||||||
|
files: |
|
||||||
|
cwd://${{ steps.meta.outputs.bake-file }}
|
||||||
|
|
||||||
|
multi-output:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
services:
|
||||||
|
registry:
|
||||||
|
image: registry:2
|
||||||
|
ports:
|
||||||
|
- 5000:5000
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
|
||||||
|
driver-opts: |
|
||||||
|
network=host
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
workdir: ./test/go
|
||||||
|
set: |
|
||||||
|
*.output=type=image,name=localhost:5000/name/app:latest,push=true
|
||||||
|
*.output=type=docker,name=app:local
|
||||||
|
*.output=type=oci,dest=/tmp/oci.tar
|
||||||
|
-
|
||||||
|
name: Check registry
|
||||||
|
run: |
|
||||||
|
docker buildx imagetools inspect localhost:5000/name/app:latest --format '{{json .}}'
|
||||||
|
-
|
||||||
|
name: Check docker
|
||||||
|
run: |
|
||||||
|
docker image inspect app:local
|
||||||
|
-
|
||||||
|
name: Check oci
|
||||||
|
run: |
|
||||||
|
set -ex
|
||||||
|
mkdir -p /tmp/oci-out
|
||||||
|
tar xf /tmp/oci.tar -C /tmp/oci-out
|
||||||
|
tree -nh /tmp/oci-out
|
||||||
|
|
||||||
|
load-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
services:
|
||||||
|
registry:
|
||||||
|
image: registry:2
|
||||||
|
ports:
|
||||||
|
- 5000:5000
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
|
||||||
|
driver-opts: |
|
||||||
|
network=host
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
workdir: ./test/go
|
||||||
|
targets: image
|
||||||
|
load: true
|
||||||
|
push: true
|
||||||
|
set: |
|
||||||
|
*.tags=localhost:5000/name/app:latest
|
||||||
|
-
|
||||||
|
name: Check registry
|
||||||
|
run: |
|
||||||
|
docker buildx imagetools inspect localhost:5000/name/app:latest --format '{{json .}}'
|
||||||
|
-
|
||||||
|
name: Check docker
|
||||||
|
run: |
|
||||||
|
docker image inspect localhost:5000/name/app:latest
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ jobs:
|
|||||||
targets: test
|
targets: test
|
||||||
-
|
-
|
||||||
name: Upload coverage
|
name: Upload coverage
|
||||||
uses: codecov/codecov-action@v3
|
uses: codecov/codecov-action@v4
|
||||||
with:
|
with:
|
||||||
file: ./coverage/clover.xml
|
file: ./coverage/clover.xml
|
||||||
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
|||||||
@@ -14,15 +14,23 @@ as a high-level build command.
|
|||||||
___
|
___
|
||||||
|
|
||||||
* [Usage](#usage)
|
* [Usage](#usage)
|
||||||
* [Subactions](#subactions)
|
* [Path context](#path-context)
|
||||||
* [`list-targets`](#list-targets)
|
* [Git context](#git-context)
|
||||||
* [Customizing](#customizing)
|
* [Customizing](#customizing)
|
||||||
* [inputs](#inputs)
|
* [inputs](#inputs)
|
||||||
* [outputs](#outputs)
|
* [outputs](#outputs)
|
||||||
|
* [Subactions](#subactions)
|
||||||
|
* [`list-targets`](#list-targets)
|
||||||
* [Contributing](#contributing)
|
* [Contributing](#contributing)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
### Path context
|
||||||
|
|
||||||
|
By default, this action will use the local bake definition (`source: .`), so
|
||||||
|
you need to use the [`actions/checkout`](https://github.com/actions/checkout/)
|
||||||
|
action to check out the repository.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: ci
|
name: ci
|
||||||
|
|
||||||
@@ -54,6 +62,126 @@ jobs:
|
|||||||
push: true
|
push: true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Git context
|
||||||
|
|
||||||
|
Git context can be provided using the [`source` input](#inputs). This means
|
||||||
|
that you don't need to use the [`actions/checkout`](https://github.com/actions/checkout/)
|
||||||
|
action to check out the repository as [BuildKit](https://docs.docker.com/build/buildkit/)
|
||||||
|
will do this directly.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: ci
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
bake:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
-
|
||||||
|
name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
uses: docker/bake-action@v4
|
||||||
|
with:
|
||||||
|
source: "${{ github.server_url }}/${{ github.repository }}.git#${{ github.ref }}"
|
||||||
|
push: true
|
||||||
|
```
|
||||||
|
|
||||||
|
Be careful because **any file mutation in the steps that precede the build step
|
||||||
|
will be ignored, including processing of the `.dockerignore` file** since
|
||||||
|
the context is based on the Git reference. However, you can use the
|
||||||
|
[Path context](#path-context) alongside the [`actions/checkout`](https://github.com/actions/checkout/)
|
||||||
|
action to remove this restriction.
|
||||||
|
|
||||||
|
Default Git context can also be provided using the [Handlebars template](https://handlebarsjs.com/guide/)
|
||||||
|
expression `{{defaultContext}}`. Here we can use it to provide a subdirectory
|
||||||
|
to the default Git context:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
uses: docker/bake-action@v4
|
||||||
|
with:
|
||||||
|
source: "{{defaultContext}}:mysubdir"
|
||||||
|
push: true
|
||||||
|
```
|
||||||
|
|
||||||
|
Building from the current repository automatically uses the `GITHUB_TOKEN`
|
||||||
|
secret that GitHub [automatically creates for workflows](https://docs.github.com/en/actions/security-guides/automatic-token-authentication),
|
||||||
|
so you don't need to pass that manually. If you want to authenticate against
|
||||||
|
another private repository for remote definitions, you can set the
|
||||||
|
[`BUILDX_BAKE_GIT_AUTH_TOKEN` environment variable](https://docs.docker.com/build/building/variables/#buildx_bake_git_auth_token).
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> Supported since Buildx 0.14.0
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
uses: docker/bake-action@v4
|
||||||
|
with:
|
||||||
|
source: "${{ github.server_url }}/${{ github.repository }}.git#${{ github.ref }}"
|
||||||
|
push: true
|
||||||
|
env:
|
||||||
|
BUILDX_BAKE_GIT_AUTH_TOKEN: ${{ secrets.MYTOKEN }}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Customizing
|
||||||
|
|
||||||
|
### inputs
|
||||||
|
|
||||||
|
The following inputs can be used as `step.with` keys
|
||||||
|
|
||||||
|
> `List` type is a newline-delimited string
|
||||||
|
> ```yaml
|
||||||
|
> set: target.args.mybuildarg=value
|
||||||
|
> ```
|
||||||
|
> ```yaml
|
||||||
|
> set: |
|
||||||
|
> target.args.mybuildarg=value
|
||||||
|
> foo*.args.mybuildarg=value
|
||||||
|
> ```
|
||||||
|
|
||||||
|
> `CSV` type is a comma-delimited string
|
||||||
|
> ```yaml
|
||||||
|
> targets: default,release
|
||||||
|
> ```
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
|----------------|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `builder` | String | Builder instance (see [setup-buildx](https://github.com/docker/setup-buildx-action) action) |
|
||||||
|
| `source` | String | Context to build from. Can be either local (`.`) or a [remote bake definition](https://docs.docker.com/build/customize/bake/file-definition/#remote-definition) |
|
||||||
|
| `files` | List/CSV | List of [bake definition files](https://docs.docker.com/build/customize/bake/file-definition/) |
|
||||||
|
| `workdir` | String | Working directory of execution |
|
||||||
|
| `targets` | List/CSV | List of bake targets (`default` target used if empty) |
|
||||||
|
| `no-cache` | Bool | Do not use cache when building the image (default `false`) |
|
||||||
|
| `pull` | Bool | Always attempt to pull a newer version of the image (default `false`) |
|
||||||
|
| `load` | Bool | Load is a shorthand for `--set=*.output=type=docker` (default `false`) |
|
||||||
|
| `provenance` | Bool/String | [Provenance](https://docs.docker.com/build/attestations/slsa-provenance/) is a shorthand for `--set=*.attest=type=provenance` |
|
||||||
|
| `push` | Bool | Push is a shorthand for `--set=*.output=type=registry` (default `false`) |
|
||||||
|
| `sbom` | Bool/String | [SBOM](https://docs.docker.com/build/attestations/sbom/) is a shorthand for `--set=*.attest=type=sbom` |
|
||||||
|
| `set` | List | List of [targets values to override](https://docs.docker.com/engine/reference/commandline/buildx_bake/#set) (eg: `targetpattern.key=value`) |
|
||||||
|
| `github-token` | String | API token used to authenticate to a Git repository for [remote definitions](https://docs.docker.com/build/bake/remote-definition/) (default `${{ github.token }}`) |
|
||||||
|
|
||||||
|
### outputs
|
||||||
|
|
||||||
|
The following outputs are available
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
|------------|------|-----------------------|
|
||||||
|
| `metadata` | JSON | Build result metadata |
|
||||||
|
|
||||||
## Subactions
|
## Subactions
|
||||||
|
|
||||||
### `list-targets`
|
### `list-targets`
|
||||||
@@ -111,50 +239,21 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
targets: ${{ matrix.target }}
|
targets: ${{ matrix.target }}
|
||||||
```
|
```
|
||||||
|
#### inputs
|
||||||
## Customizing
|
|
||||||
|
|
||||||
### inputs
|
|
||||||
|
|
||||||
Following inputs can be used as `step.with` keys
|
|
||||||
|
|
||||||
> `List` type is a newline-delimited string
|
|
||||||
> ```yaml
|
|
||||||
> set: target.args.mybuildarg=value
|
|
||||||
> ```
|
|
||||||
> ```yaml
|
|
||||||
> set: |
|
|
||||||
> target.args.mybuildarg=value
|
|
||||||
> foo*.args.mybuildarg=value
|
|
||||||
> ```
|
|
||||||
|
|
||||||
> `CSV` type is a comma-delimited string
|
|
||||||
> ```yaml
|
|
||||||
> targets: default,release
|
|
||||||
> ```
|
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|--------------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------|
|
|--------------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `builder` | String | Builder instance (see [setup-buildx](https://github.com/docker/setup-buildx-action) action) |
|
| `workdir` | String | Working directory to use (defaults to `.`) |
|
||||||
| `files` | List/CSV | List of [bake definition files](https://docs.docker.com/build/customize/bake/file-definition/) |
|
| `files` | List/CSV | List of [bake definition files](https://docs.docker.com/build/customize/bake/file-definition/) |
|
||||||
| `workdir` | String | Working directory of execution |
|
| `target` | String | The target to use within the bake file |
|
||||||
| `targets` | List/CSV | List of bake targets (`default` target used if empty) |
|
|
||||||
| `no-cache` | Bool | Do not use cache when building the image (default `false`) |
|
|
||||||
| `pull` | Bool | Always attempt to pull a newer version of the image (default `false`) |
|
|
||||||
| `load` | Bool | Load is a shorthand for `--set=*.output=type=docker` (default `false`) |
|
|
||||||
| `provenance` | Bool/String | [Provenance](https://docs.docker.com/build/attestations/slsa-provenance/) is a shorthand for `--set=*.attest=type=provenance` |
|
|
||||||
| `push` | Bool | Push is a shorthand for `--set=*.output=type=registry` (default `false`) |
|
|
||||||
| `sbom` | Bool/String | [SBOM](https://docs.docker.com/build/attestations/sbom/) is a shorthand for `--set=*.attest=type=sbom` |
|
|
||||||
| `set` | List | List of [targets values to override](https://docs.docker.com/engine/reference/commandline/buildx_bake/#set) (eg: `targetpattern.key=value`) |
|
|
||||||
| `source` | String | [Remote bake definition](https://docs.docker.com/build/customize/bake/file-definition/#remote-definition) to build from |
|
|
||||||
|
|
||||||
### outputs
|
#### outputs
|
||||||
|
|
||||||
The following outputs are available
|
The following outputs are available
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|------------|------|-----------------------|
|
|------------|----------|----------------------------|
|
||||||
| `metadata` | JSON | Build result metadata |
|
| `targets` | List/CSV | List of extracted targest |
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {beforeEach, describe, expect, jest, test} from '@jest/globals';
|
import {beforeEach, describe, expect, jest, test} from '@jest/globals';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
import {Bake} from '@docker/actions-toolkit/lib/buildx/bake';
|
import {Bake} from '@docker/actions-toolkit/lib/buildx/bake';
|
||||||
import {Builder} from '@docker/actions-toolkit/lib/buildx/builder';
|
import {Builder} from '@docker/actions-toolkit/lib/buildx/builder';
|
||||||
import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx';
|
import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx';
|
||||||
@@ -8,6 +9,7 @@ import {Context} from '@docker/actions-toolkit/lib/context';
|
|||||||
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
||||||
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
||||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||||
|
|
||||||
import {BakeDefinition} from '@docker/actions-toolkit/lib/types/bake';
|
import {BakeDefinition} from '@docker/actions-toolkit/lib/types/bake';
|
||||||
import {BuilderInfo} from '@docker/actions-toolkit/lib/types/builder';
|
import {BuilderInfo} from '@docker/actions-toolkit/lib/types/builder';
|
||||||
import {GitHubRepo} from '@docker/actions-toolkit/lib/types/github';
|
import {GitHubRepo} from '@docker/actions-toolkit/lib/types/github';
|
||||||
@@ -56,7 +58,7 @@ jest.spyOn(Builder.prototype, 'inspect').mockImplementation(async (): Promise<Bu
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.spyOn(Bake.prototype, 'parseDefinitions').mockImplementation(async (): Promise<BakeDefinition> => {
|
jest.spyOn(Bake.prototype, 'getDefinition').mockImplementation(async (): Promise<BakeDefinition> => {
|
||||||
return JSON.parse(`{
|
return JSON.parse(`{
|
||||||
"group": {
|
"group": {
|
||||||
"default": {
|
"default": {
|
||||||
@@ -304,6 +306,25 @@ describe('getArgs', () => {
|
|||||||
'image-all'
|
'image-all'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
11,
|
||||||
|
'0.10.0',
|
||||||
|
new Map<string, string>([
|
||||||
|
['source', '{{defaultContext}}'],
|
||||||
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'false'],
|
||||||
|
['pull', 'false'],
|
||||||
|
['files', './foo.hcl'],
|
||||||
|
]),
|
||||||
|
[
|
||||||
|
'bake',
|
||||||
|
'https://github.com/docker/build-push-action.git#refs/heads/master',
|
||||||
|
'--file', './foo.hcl',
|
||||||
|
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||||
|
'--provenance', `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
|
||||||
|
]
|
||||||
|
],
|
||||||
])(
|
])(
|
||||||
'[%d] given %p with %p as inputs, returns %p',
|
'[%d] given %p with %p as inputs, returns %p',
|
||||||
async (num: number, buildxVersion: string, inputs: Map<string, string>, expected: Array<string>) => {
|
async (num: number, buildxVersion: string, inputs: Map<string, string>, expected: Array<string>) => {
|
||||||
@@ -315,7 +336,23 @@ describe('getArgs', () => {
|
|||||||
return buildxVersion;
|
return buildxVersion;
|
||||||
});
|
});
|
||||||
const inp = await context.getInputs();
|
const inp = await context.getInputs();
|
||||||
const res = await context.getArgs(inp, toolkit);
|
const definition = await toolkit.bake.getDefinition(
|
||||||
|
{
|
||||||
|
files: inp.files,
|
||||||
|
load: inp.load,
|
||||||
|
noCache: inp.noCache,
|
||||||
|
overrides: inp.set,
|
||||||
|
provenance: inp.provenance,
|
||||||
|
push: inp.push,
|
||||||
|
sbom: inp.sbom,
|
||||||
|
source: inp.source,
|
||||||
|
targets: inp.targets
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cwd: inp.workdir
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const res = await context.getArgs(inp, definition, toolkit);
|
||||||
expect(res).toEqual(expected);
|
expect(res).toEqual(expected);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
+7
-2
@@ -10,6 +10,9 @@ inputs:
|
|||||||
builder:
|
builder:
|
||||||
description: "Builder instance"
|
description: "Builder instance"
|
||||||
required: false
|
required: false
|
||||||
|
source:
|
||||||
|
description: "Context to build from. Can be either local or a remote bake definition"
|
||||||
|
required: false
|
||||||
files:
|
files:
|
||||||
description: "List of bake definition files"
|
description: "List of bake definition files"
|
||||||
required: false
|
required: false
|
||||||
@@ -45,8 +48,9 @@ inputs:
|
|||||||
set:
|
set:
|
||||||
description: "List of targets values to override (eg. targetpattern.key=value)"
|
description: "List of targets values to override (eg. targetpattern.key=value)"
|
||||||
required: false
|
required: false
|
||||||
source:
|
github-token:
|
||||||
description: "Remote bake definition to build from"
|
description: "API token used to authenticate to a Git repository for remote definitions"
|
||||||
|
default: ${{ github.token }}
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
@@ -56,3 +60,4 @@ outputs:
|
|||||||
runs:
|
runs:
|
||||||
using: 'node20'
|
using: 'node20'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
post: 'dist/index.js'
|
||||||
|
|||||||
+78
-8
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
+1918
-79
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -27,7 +27,8 @@
|
|||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
"@docker/actions-toolkit": "^0.14.0"
|
"@docker/actions-toolkit": "^0.22.0",
|
||||||
|
"handlebars": "^4.7.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.5.9",
|
"@types/node": "^20.5.9",
|
||||||
|
|||||||
+27
-11
@@ -1,10 +1,15 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
import * as handlebars from 'handlebars';
|
||||||
|
|
||||||
import {Bake} from '@docker/actions-toolkit/lib/buildx/bake';
|
import {Bake} from '@docker/actions-toolkit/lib/buildx/bake';
|
||||||
import {Inputs as BuildxInputs} from '@docker/actions-toolkit/lib/buildx/inputs';
|
import {Build} from '@docker/actions-toolkit/lib/buildx/build';
|
||||||
|
import {Context} from '@docker/actions-toolkit/lib/context';
|
||||||
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
||||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||||
import {Util} from '@docker/actions-toolkit/lib/util';
|
import {Util} from '@docker/actions-toolkit/lib/util';
|
||||||
|
|
||||||
|
import {BakeDefinition} from '@docker/actions-toolkit/lib/types/bake';
|
||||||
|
|
||||||
export interface Inputs {
|
export interface Inputs {
|
||||||
builder: string;
|
builder: string;
|
||||||
files: string[];
|
files: string[];
|
||||||
@@ -18,6 +23,7 @@ export interface Inputs {
|
|||||||
sbom: string;
|
sbom: string;
|
||||||
set: string[];
|
set: string[];
|
||||||
source: string;
|
source: string;
|
||||||
|
githubToken: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getInputs(): Promise<Inputs> {
|
export async function getInputs(): Promise<Inputs> {
|
||||||
@@ -29,24 +35,25 @@ export async function getInputs(): Promise<Inputs> {
|
|||||||
noCache: core.getBooleanInput('no-cache'),
|
noCache: core.getBooleanInput('no-cache'),
|
||||||
pull: core.getBooleanInput('pull'),
|
pull: core.getBooleanInput('pull'),
|
||||||
load: core.getBooleanInput('load'),
|
load: core.getBooleanInput('load'),
|
||||||
provenance: BuildxInputs.getProvenanceInput('provenance'),
|
provenance: Build.getProvenanceInput('provenance'),
|
||||||
push: core.getBooleanInput('push'),
|
push: core.getBooleanInput('push'),
|
||||||
sbom: core.getInput('sbom'),
|
sbom: core.getInput('sbom'),
|
||||||
set: Util.getInputList('set', {ignoreComma: true, quote: false}),
|
set: Util.getInputList('set', {ignoreComma: true, quote: false}),
|
||||||
source: core.getInput('source')
|
source: getSourceInput('source'),
|
||||||
|
githubToken: core.getInput('github-token')
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
|
export async function getArgs(inputs: Inputs, definition: BakeDefinition, toolkit: Toolkit): Promise<Array<string>> {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
return [
|
return [
|
||||||
...await getBakeArgs(inputs, toolkit),
|
...await getBakeArgs(inputs, definition, toolkit),
|
||||||
...await getCommonArgs(inputs),
|
...await getCommonArgs(inputs),
|
||||||
...inputs.targets
|
...inputs.targets
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getBakeArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
|
async function getBakeArgs(inputs: Inputs, definition: BakeDefinition, toolkit: Toolkit): Promise<Array<string>> {
|
||||||
const args: Array<string> = ['bake'];
|
const args: Array<string> = ['bake'];
|
||||||
if (inputs.source) {
|
if (inputs.source) {
|
||||||
args.push(inputs.source);
|
args.push(inputs.source);
|
||||||
@@ -58,23 +65,22 @@ async function getBakeArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<stri
|
|||||||
args.push('--set', set);
|
args.push('--set', set);
|
||||||
});
|
});
|
||||||
if (await toolkit.buildx.versionSatisfies('>=0.6.0')) {
|
if (await toolkit.buildx.versionSatisfies('>=0.6.0')) {
|
||||||
args.push('--metadata-file', BuildxInputs.getBuildMetadataFilePath());
|
args.push('--metadata-file', Bake.getMetadataFilePath());
|
||||||
}
|
}
|
||||||
if (await toolkit.buildx.versionSatisfies('>=0.10.0')) {
|
if (await toolkit.buildx.versionSatisfies('>=0.10.0')) {
|
||||||
const bakedef = await toolkit.bake.parseDefinitions([...inputs.files, inputs.source], inputs.targets, inputs.set, inputs.load, inputs.push, inputs.workdir);
|
|
||||||
if (inputs.provenance) {
|
if (inputs.provenance) {
|
||||||
args.push('--provenance', inputs.provenance);
|
args.push('--provenance', inputs.provenance);
|
||||||
} else if ((await toolkit.buildkit.versionSatisfies(inputs.builder, '>=0.11.0')) && !Bake.hasDockerExporter(bakedef, inputs.load)) {
|
} else if ((await toolkit.buildkit.versionSatisfies(inputs.builder, '>=0.11.0')) && !Bake.hasDockerExporter(definition, inputs.load)) {
|
||||||
// if provenance not specified and BuildKit version compatible for
|
// if provenance not specified and BuildKit version compatible for
|
||||||
// attestation, set default provenance. Also needs to make sure user
|
// attestation, set default provenance. Also needs to make sure user
|
||||||
// doesn't want to explicitly load the image to docker.
|
// doesn't want to explicitly load the image to docker.
|
||||||
if (GitHub.context.payload.repository?.private ?? false) {
|
if (GitHub.context.payload.repository?.private ?? false) {
|
||||||
// if this is a private repository, we set the default provenance
|
// if this is a private repository, we set the default provenance
|
||||||
// attributes being set in buildx: https://github.com/docker/buildx/blob/fb27e3f919dcbf614d7126b10c2bc2d0b1927eb6/build/build.go#L603
|
// attributes being set in buildx: https://github.com/docker/buildx/blob/fb27e3f919dcbf614d7126b10c2bc2d0b1927eb6/build/build.go#L603
|
||||||
args.push('--provenance', BuildxInputs.resolveProvenanceAttrs(`mode=min,inline-only=true`));
|
args.push('--provenance', Build.resolveProvenanceAttrs(`mode=min,inline-only=true`));
|
||||||
} else {
|
} else {
|
||||||
// for a public repository, we set max provenance mode.
|
// for a public repository, we set max provenance mode.
|
||||||
args.push('--provenance', BuildxInputs.resolveProvenanceAttrs(`mode=max`));
|
args.push('--provenance', Build.resolveProvenanceAttrs(`mode=max`));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (inputs.sbom) {
|
if (inputs.sbom) {
|
||||||
@@ -103,3 +109,13 @@ async function getCommonArgs(inputs: Inputs): Promise<Array<string>> {
|
|||||||
}
|
}
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSourceInput(name: string): string {
|
||||||
|
let source = handlebars.compile(core.getInput(name))({
|
||||||
|
defaultContext: Context.gitContext()
|
||||||
|
});
|
||||||
|
if (source === '.') {
|
||||||
|
source = '';
|
||||||
|
}
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|||||||
+42
-6
@@ -2,12 +2,15 @@ import * as fs from 'fs';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as actionsToolkit from '@docker/actions-toolkit';
|
import * as actionsToolkit from '@docker/actions-toolkit';
|
||||||
import {Inputs as BuildxInputs} from '@docker/actions-toolkit/lib/buildx/inputs';
|
|
||||||
|
import {Bake} from '@docker/actions-toolkit/lib/buildx/bake';
|
||||||
import {Context} from '@docker/actions-toolkit/lib/context';
|
import {Context} from '@docker/actions-toolkit/lib/context';
|
||||||
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
||||||
import {Exec} from '@docker/actions-toolkit/lib/exec';
|
import {Exec} from '@docker/actions-toolkit/lib/exec';
|
||||||
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
||||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||||
|
|
||||||
|
import {BakeDefinition} from '@docker/actions-toolkit/lib/types/bake';
|
||||||
import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker';
|
import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker';
|
||||||
|
|
||||||
import * as context from './context';
|
import * as context from './context';
|
||||||
@@ -18,6 +21,7 @@ actionsToolkit.run(
|
|||||||
async () => {
|
async () => {
|
||||||
const inputs: context.Inputs = await context.getInputs();
|
const inputs: context.Inputs = await context.getInputs();
|
||||||
const toolkit = new Toolkit();
|
const toolkit = new Toolkit();
|
||||||
|
const gitAuthToken = process.env.BUILDX_BAKE_GIT_AUTH_TOKEN ?? inputs.githubToken;
|
||||||
|
|
||||||
await core.group(`GitHub Actions runtime token ACs`, async () => {
|
await core.group(`GitHub Actions runtime token ACs`, async () => {
|
||||||
try {
|
try {
|
||||||
@@ -72,17 +76,48 @@ actionsToolkit.run(
|
|||||||
await toolkit.buildx.printVersion();
|
await toolkit.buildx.printVersion();
|
||||||
});
|
});
|
||||||
|
|
||||||
const args: string[] = await context.getArgs(inputs, toolkit);
|
let definition: BakeDefinition | undefined;
|
||||||
|
await core.group(`Parsing raw definition`, async () => {
|
||||||
|
definition = await toolkit.bake.getDefinition(
|
||||||
|
{
|
||||||
|
files: inputs.files,
|
||||||
|
load: inputs.load,
|
||||||
|
noCache: inputs.noCache,
|
||||||
|
overrides: inputs.set,
|
||||||
|
provenance: inputs.provenance,
|
||||||
|
push: inputs.push,
|
||||||
|
sbom: inputs.sbom,
|
||||||
|
source: inputs.source,
|
||||||
|
targets: inputs.targets,
|
||||||
|
githubToken: gitAuthToken
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cwd: inputs.workdir
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
if (!definition) {
|
||||||
|
throw new Error('Bake definition not set');
|
||||||
|
}
|
||||||
|
|
||||||
|
const args: string[] = await context.getArgs(inputs, definition, toolkit);
|
||||||
const buildCmd = await toolkit.buildx.getCommand(args);
|
const buildCmd = await toolkit.buildx.getCommand(args);
|
||||||
|
const buildEnv = Object.assign({}, process.env, {
|
||||||
|
BUILDX_BAKE_GIT_AUTH_TOKEN: gitAuthToken
|
||||||
|
}) as {
|
||||||
|
[key: string]: string;
|
||||||
|
};
|
||||||
|
|
||||||
await core.group(`Bake definition`, async () => {
|
await core.group(`Bake definition`, async () => {
|
||||||
await Exec.exec(buildCmd.command, [...buildCmd.args, '--print'], {
|
await Exec.exec(buildCmd.command, [...buildCmd.args, '--print'], {
|
||||||
cwd: inputs.workdir
|
cwd: inputs.workdir,
|
||||||
|
env: buildEnv
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
await Exec.getExecOutput(buildCmd.command, buildCmd.args, {
|
await Exec.getExecOutput(buildCmd.command, buildCmd.args, {
|
||||||
cwd: inputs.workdir,
|
cwd: inputs.workdir,
|
||||||
|
env: buildEnv,
|
||||||
ignoreReturnCode: true
|
ignoreReturnCode: true
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
@@ -90,11 +125,12 @@ actionsToolkit.run(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const metadata = await BuildxInputs.resolveBuildMetadata();
|
const metadata = Bake.resolveMetadata();
|
||||||
if (metadata) {
|
if (metadata) {
|
||||||
await core.group(`Metadata`, async () => {
|
await core.group(`Metadata`, async () => {
|
||||||
core.info(metadata);
|
const metadatadt = JSON.stringify(metadata, null, 2);
|
||||||
core.setOutput('metadata', metadata);
|
core.info(metadatadt);
|
||||||
|
core.setOutput('metadata', metadatadt);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ runs:
|
|||||||
-
|
-
|
||||||
name: Generate
|
name: Generate
|
||||||
id: generate
|
id: generate
|
||||||
uses: actions/github-script@v6
|
uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
let def;
|
let def;
|
||||||
|
|||||||
Reference in New Issue
Block a user