mirror of
https://github.com/docker/setup-buildx-action.git
synced 2024-11-15 13:43:50 +08:00
Merge pull request #162 from crazy-max/nodes-output
nodes metadata JSON ouput
This commit is contained in:
commit
d5234d6605
7
.github/workflows/ci.yml
vendored
7
.github/workflows/ci.yml
vendored
@ -30,9 +30,16 @@ jobs:
|
||||
uses: actions/checkout@v3
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: ./
|
||||
with:
|
||||
version: ${{ matrix.buildx-version }}
|
||||
-
|
||||
name: Nodes output
|
||||
run: |
|
||||
cat << EOF
|
||||
${{ steps.buildx.outputs.nodes }}
|
||||
EOF
|
||||
|
||||
multi:
|
||||
runs-on: ubuntu-latest
|
||||
|
44
README.md
44
README.md
@ -29,6 +29,7 @@ ___
|
||||
* [outputs](#outputs)
|
||||
* [environment variables](#environment-variables)
|
||||
* [Notes](#notes)
|
||||
* [`nodes` output](#nodes-output)
|
||||
* [BuildKit container logs](#buildkit-container-logs)
|
||||
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
|
||||
|
||||
@ -98,14 +99,12 @@ Following inputs can be used as `step.with` keys
|
||||
|
||||
Following outputs are available
|
||||
|
||||
| Name | Type | Description |
|
||||
|---------------|---------|---------------------------------------|
|
||||
| `name` | String | Builder name |
|
||||
| `driver` | String | Builder driver |
|
||||
| `endpoint` | String | Builder node endpoint |
|
||||
| `status` | String | Builder node status |
|
||||
| `flags` | String | Builder node flags (if applicable) |
|
||||
| `platforms` | String | Builder node platforms available (comma separated) |
|
||||
| Name | Type | Description |
|
||||
|-------------|--------|-------------------------------------------------|
|
||||
| `name` | String | Builder name |
|
||||
| `driver` | String | Builder driver |
|
||||
| `platforms` | String | Builder node platforms (preferred or available) |
|
||||
| `nodes` | JSON | Builder [nodes metadata](#nodes-output) |
|
||||
|
||||
### environment variables
|
||||
|
||||
@ -117,6 +116,35 @@ The following [official docker environment variables](https://docs.docker.com/en
|
||||
|
||||
## Notes
|
||||
|
||||
### `nodes` output
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"name": "builder-3820d274-502c-4498-ae24-d4c32b3023d90",
|
||||
"endpoint": "unix:///var/run/docker.sock",
|
||||
"driver-opts": [
|
||||
"network=host",
|
||||
"image=moby/buildkit:master"
|
||||
],
|
||||
"status": "running",
|
||||
"buildkitd-flags": "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host",
|
||||
"buildkit": "3fab389",
|
||||
"platforms": "linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4,linux/386"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
| Name | Type | Description |
|
||||
|-------------------|--------|----------------------------|
|
||||
| `name` | String | Node name |
|
||||
| `endpoint` | String | Node endpoint |
|
||||
| `driver-opts` | List | Options for the driver |
|
||||
| `status` | String | Node status |
|
||||
| `buildkitd-flags` | String | Flags for buildkitd daemon |
|
||||
| `buildkit` | String | BuildKit version |
|
||||
| `platforms` | String | Platforms available |
|
||||
|
||||
### BuildKit container logs
|
||||
|
||||
To display BuildKit container logs (when `docker-container` driver is used) you have to [enable step debug logging](https://docs.github.com/en/actions/managing-workflow-runs/enabling-debug-logging#enabling-step-debug-logging),
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {describe, expect, jest, test, beforeEach} from '@jest/globals';
|
||||
import {describe, expect, test, beforeEach} from '@jest/globals';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
@ -73,10 +73,128 @@ describe('inspect', () => {
|
||||
expect(builder).not.toBeUndefined();
|
||||
expect(builder.name).not.toEqual('');
|
||||
expect(builder.driver).not.toEqual('');
|
||||
expect(builder.node_platforms).not.toEqual('');
|
||||
expect(builder.nodes).not.toEqual({});
|
||||
}, 100000);
|
||||
});
|
||||
|
||||
describe('parseInspect', () => {
|
||||
// prettier-ignore
|
||||
test.each([
|
||||
[
|
||||
'inspect1.txt',
|
||||
{
|
||||
"nodes": [
|
||||
{
|
||||
"name": "builder-5cb467f7-0940-47e1-b94b-d51f54054d620",
|
||||
"endpoint": "unix:///var/run/docker.sock",
|
||||
"status": "running",
|
||||
"buildkitd-flags": "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host",
|
||||
"buildkit": "v0.10.4",
|
||||
"platforms": "linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4,linux/arm64,linux/riscv64,linux/386,linux/arm/v7,linux/arm/v6"
|
||||
}
|
||||
],
|
||||
"name": "builder-5cb467f7-0940-47e1-b94b-d51f54054d62",
|
||||
"driver": "docker-container"
|
||||
}
|
||||
],
|
||||
[
|
||||
'inspect2.txt',
|
||||
{
|
||||
"nodes": [
|
||||
{
|
||||
"name": "builder-5f449644-ff29-48af-8344-abb0292d06730",
|
||||
"endpoint": "unix:///var/run/docker.sock",
|
||||
"driver-opts": [
|
||||
"image=moby/buildkit:latest"
|
||||
],
|
||||
"status": "running",
|
||||
"buildkitd-flags": "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host",
|
||||
"buildkit": "v0.10.4",
|
||||
"platforms": "linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4,linux/386"
|
||||
}
|
||||
],
|
||||
"name": "builder-5f449644-ff29-48af-8344-abb0292d0673",
|
||||
"driver": "docker-container"
|
||||
}
|
||||
],
|
||||
[
|
||||
'inspect3.txt',
|
||||
{
|
||||
"nodes": [
|
||||
{
|
||||
"name": "builder-9929e463-7954-4dc3-89cd-514cca29ff800",
|
||||
"endpoint": "unix:///var/run/docker.sock",
|
||||
"driver-opts": [
|
||||
"image=moby/buildkit:master",
|
||||
"network=host"
|
||||
],
|
||||
"status": "running",
|
||||
"buildkitd-flags": "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host",
|
||||
"buildkit": "3fab389",
|
||||
"platforms": "linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4,linux/386"
|
||||
}
|
||||
],
|
||||
"name": "builder-9929e463-7954-4dc3-89cd-514cca29ff80",
|
||||
"driver": "docker-container"
|
||||
}
|
||||
],
|
||||
[
|
||||
'inspect4.txt',
|
||||
{
|
||||
"nodes": [
|
||||
{
|
||||
"name": "default",
|
||||
"endpoint": "default",
|
||||
"status": "running",
|
||||
"buildkit": "20.10.17",
|
||||
"platforms": "linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6"
|
||||
}
|
||||
],
|
||||
"name": "default",
|
||||
"driver": "docker"
|
||||
}
|
||||
],
|
||||
[
|
||||
'inspect5.txt',
|
||||
{
|
||||
"nodes": [
|
||||
{
|
||||
"name": "aws_graviton2",
|
||||
"endpoint": "tcp://1.23.45.67:1234",
|
||||
"driver-opts": [
|
||||
"cert=/home/user/.certs/aws_graviton2/cert.pem",
|
||||
"key=/home/user/.certs/aws_graviton2/key.pem",
|
||||
"cacert=/home/user/.certs/aws_graviton2/ca.pem"
|
||||
],
|
||||
"status": "running",
|
||||
"platforms": "darwin/arm64,linux/arm64,linux/arm/v5,linux/arm/v6,linux/arm/v7,windows/arm64"
|
||||
}
|
||||
],
|
||||
"name": "remote-builder",
|
||||
"driver": "remote"
|
||||
}
|
||||
],
|
||||
[
|
||||
'inspect6.txt',
|
||||
{
|
||||
"nodes": [
|
||||
{
|
||||
"name": "builder-17cfff01-48d9-4c3d-9332-9992e308a5100",
|
||||
"endpoint": "unix:///var/run/docker.sock",
|
||||
"status": "running",
|
||||
"buildkitd-flags": "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host",
|
||||
"platforms": "linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/386"
|
||||
}
|
||||
],
|
||||
"name": "builder-17cfff01-48d9-4c3d-9332-9992e308a510",
|
||||
"driver": "docker-container"
|
||||
}
|
||||
],
|
||||
])('given %p', async (inspectFile, expected) => {
|
||||
expect(await buildx.parseInspect(fs.readFileSync(path.join(__dirname, 'fixtures', inspectFile)).toString())).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('build', () => {
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-buildx-'));
|
||||
|
||||
|
10
__tests__/fixtures/inspect1.txt
Normal file
10
__tests__/fixtures/inspect1.txt
Normal file
@ -0,0 +1,10 @@
|
||||
Name: builder-5cb467f7-0940-47e1-b94b-d51f54054d62
|
||||
Driver: docker-container
|
||||
|
||||
Nodes:
|
||||
Name: builder-5cb467f7-0940-47e1-b94b-d51f54054d620
|
||||
Endpoint: unix:///var/run/docker.sock
|
||||
Status: running
|
||||
Flags: --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
|
||||
Buildkit: v0.10.4
|
||||
Platforms: linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/arm64, linux/riscv64, linux/386, linux/arm/v7, linux/arm/v6
|
11
__tests__/fixtures/inspect2.txt
Normal file
11
__tests__/fixtures/inspect2.txt
Normal file
@ -0,0 +1,11 @@
|
||||
Name: builder-5f449644-ff29-48af-8344-abb0292d0673
|
||||
Driver: docker-container
|
||||
|
||||
Nodes:
|
||||
Name: builder-5f449644-ff29-48af-8344-abb0292d06730
|
||||
Endpoint: unix:///var/run/docker.sock
|
||||
Driver Options: image="moby/buildkit:latest"
|
||||
Status: running
|
||||
Flags: --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
|
||||
Buildkit: v0.10.4
|
||||
Platforms: linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/386
|
11
__tests__/fixtures/inspect3.txt
Normal file
11
__tests__/fixtures/inspect3.txt
Normal file
@ -0,0 +1,11 @@
|
||||
Name: builder-9929e463-7954-4dc3-89cd-514cca29ff80
|
||||
Driver: docker-container
|
||||
|
||||
Nodes:
|
||||
Name: builder-9929e463-7954-4dc3-89cd-514cca29ff800
|
||||
Endpoint: unix:///var/run/docker.sock
|
||||
Driver Options: image="moby/buildkit:master" network="host"
|
||||
Status: running
|
||||
Flags: --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
|
||||
Buildkit: 3fab389
|
||||
Platforms: linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/386
|
9
__tests__/fixtures/inspect4.txt
Normal file
9
__tests__/fixtures/inspect4.txt
Normal file
@ -0,0 +1,9 @@
|
||||
Name: default
|
||||
Driver: docker
|
||||
|
||||
Nodes:
|
||||
Name: default
|
||||
Endpoint: default
|
||||
Status: running
|
||||
Buildkit: 20.10.17
|
||||
Platforms: linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
|
9
__tests__/fixtures/inspect5.txt
Normal file
9
__tests__/fixtures/inspect5.txt
Normal file
@ -0,0 +1,9 @@
|
||||
Name: remote-builder
|
||||
Driver: remote
|
||||
|
||||
Nodes:
|
||||
Name: aws_graviton2
|
||||
Endpoint: tcp://1.23.45.67:1234
|
||||
Driver Options: cert="/home/user/.certs/aws_graviton2/cert.pem" key="/home/user/.certs/aws_graviton2/key.pem" cacert="/home/user/.certs/aws_graviton2/ca.pem"
|
||||
Status: running
|
||||
Platforms: darwin/arm64*, linux/arm64*, linux/arm/v5*, linux/arm/v6*, linux/arm/v7*, windows/arm64*, linux/amd64, linux/amd64/v2, linux/riscv64, linux/ppc64le, linux/s390x, linux/mips64le, linux/mips64
|
9
__tests__/fixtures/inspect6.txt
Normal file
9
__tests__/fixtures/inspect6.txt
Normal file
@ -0,0 +1,9 @@
|
||||
Name: builder-17cfff01-48d9-4c3d-9332-9992e308a510
|
||||
Driver: docker-container
|
||||
|
||||
Nodes:
|
||||
Name: builder-17cfff01-48d9-4c3d-9332-9992e308a5100
|
||||
Endpoint: unix:///var/run/docker.sock
|
||||
Status: running
|
||||
Flags: --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
|
||||
Platforms: linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/386
|
16
action.yml
16
action.yml
@ -44,14 +44,16 @@ outputs:
|
||||
description: 'Builder name'
|
||||
driver:
|
||||
description: 'Builder driver'
|
||||
endpoint:
|
||||
description: 'Builder node endpoint'
|
||||
status:
|
||||
description: 'Builder node status'
|
||||
flags:
|
||||
description: 'Builder node flags (if applicable)'
|
||||
platforms:
|
||||
description: 'Builder node platforms available (comma separated)'
|
||||
description: 'Builder node platforms (preferred or available)'
|
||||
nodes:
|
||||
description: 'Builder nodes metadata'
|
||||
endpoint:
|
||||
description: 'Builder node endpoint (deprecated, use nodes output instead)'
|
||||
status:
|
||||
description: 'Builder node status (deprecated, use nodes output instead)'
|
||||
flags:
|
||||
description: 'Builder node flags (deprecated, use nodes output instead)'
|
||||
|
||||
runs:
|
||||
using: 'node16'
|
||||
|
4
dist/index.js
generated
vendored
4
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
129
src/buildx.ts
129
src/buildx.ts
@ -12,11 +12,17 @@ import * as tc from '@actions/tool-cache';
|
||||
export type Builder = {
|
||||
name?: string;
|
||||
driver?: string;
|
||||
node_name?: string;
|
||||
node_endpoint?: string;
|
||||
node_status?: string;
|
||||
node_flags?: string;
|
||||
node_platforms?: string;
|
||||
nodes: Node[];
|
||||
};
|
||||
|
||||
export type Node = {
|
||||
name?: string;
|
||||
endpoint?: string;
|
||||
'driver-opts'?: Array<string>;
|
||||
status?: string;
|
||||
'buildkitd-flags'?: string;
|
||||
buildkit?: string;
|
||||
platforms?: string;
|
||||
};
|
||||
|
||||
export async function getConfigInline(s: string): Promise<string> {
|
||||
@ -98,48 +104,83 @@ export async function inspect(name: string, standalone?: boolean): Promise<Build
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
throw new Error(res.stderr.trim());
|
||||
}
|
||||
const builder: Builder = {};
|
||||
itlines: for (const line of res.stdout.trim().split(`\n`)) {
|
||||
const [key, ...rest] = line.split(':');
|
||||
const value = rest.map(v => v.trim()).join(':');
|
||||
if (key.length == 0 || value.length == 0) {
|
||||
continue;
|
||||
}
|
||||
switch (key) {
|
||||
case 'Name': {
|
||||
if (builder.name == undefined) {
|
||||
builder.name = value;
|
||||
} else {
|
||||
builder.node_name = value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'Driver': {
|
||||
builder.driver = value;
|
||||
break;
|
||||
}
|
||||
case 'Endpoint': {
|
||||
builder.node_endpoint = value;
|
||||
break;
|
||||
}
|
||||
case 'Status': {
|
||||
builder.node_status = value;
|
||||
break;
|
||||
}
|
||||
case 'Flags': {
|
||||
builder.node_flags = value;
|
||||
break;
|
||||
}
|
||||
case 'Platforms': {
|
||||
builder.node_platforms = value.replace(/\s/g, '');
|
||||
break itlines;
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
return parseInspect(res.stdout);
|
||||
});
|
||||
}
|
||||
|
||||
export async function parseInspect(data: string): Promise<Builder> {
|
||||
const builder: Builder = {
|
||||
nodes: []
|
||||
};
|
||||
let node: Node = {};
|
||||
for (const line of data.trim().split(`\n`)) {
|
||||
const [key, ...rest] = line.split(':');
|
||||
const value = rest.map(v => v.trim()).join(':');
|
||||
if (key.length == 0 || value.length == 0) {
|
||||
continue;
|
||||
}
|
||||
switch (key.toLowerCase()) {
|
||||
case 'name': {
|
||||
if (builder.name == undefined) {
|
||||
builder.name = value;
|
||||
} else {
|
||||
if (Object.keys(node).length > 0) {
|
||||
builder.nodes.push(node);
|
||||
node = {};
|
||||
}
|
||||
node.name = value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'driver': {
|
||||
builder.driver = value;
|
||||
break;
|
||||
}
|
||||
case 'endpoint': {
|
||||
node.endpoint = value;
|
||||
break;
|
||||
}
|
||||
case 'driver options': {
|
||||
node['driver-opts'] = (value.match(/(\w+)="([^"]*)"/g) || []).map(v => v.replace(/^(.*)="(.*)"$/g, '$1=$2'));
|
||||
break;
|
||||
}
|
||||
case 'status': {
|
||||
node.status = value;
|
||||
break;
|
||||
}
|
||||
case 'flags': {
|
||||
node['buildkitd-flags'] = value;
|
||||
break;
|
||||
}
|
||||
case 'buildkit': {
|
||||
node.buildkit = value;
|
||||
break;
|
||||
}
|
||||
case 'platforms': {
|
||||
let platforms: Array<string> = [];
|
||||
// if a preferred platform is being set then use only these
|
||||
// https://docs.docker.com/engine/reference/commandline/buildx_inspect/#get-information-about-a-builder-instance
|
||||
if (value.includes('*')) {
|
||||
for (const platform of value.split(', ')) {
|
||||
if (platform.includes('*')) {
|
||||
platforms.push(platform.replace('*', ''));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// otherwise set all platforms available
|
||||
platforms = value.split(', ');
|
||||
}
|
||||
node.platforms = platforms.join(',');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Object.keys(node).length > 0) {
|
||||
builder.nodes.push(node);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
export async function build(inputBuildRef: string, dest: string, standalone: boolean): Promise<string> {
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [repo, ref] = inputBuildRef.split('#');
|
||||
|
21
src/main.ts
21
src/main.ts
@ -115,21 +115,26 @@ async function run(): Promise<void> {
|
||||
|
||||
core.startGroup(`Inspect builder`);
|
||||
const builder = await buildx.inspect(builderName, standalone);
|
||||
const firstNode = builder.nodes[0];
|
||||
core.info(JSON.stringify(builder, undefined, 2));
|
||||
context.setOutput('driver', builder.driver);
|
||||
context.setOutput('endpoint', builder.node_endpoint);
|
||||
context.setOutput('status', builder.node_status);
|
||||
context.setOutput('flags', builder.node_flags);
|
||||
context.setOutput('platforms', builder.node_platforms);
|
||||
context.setOutput('platforms', firstNode.platforms);
|
||||
context.setOutput('nodes', JSON.stringify(builder.nodes, undefined, 2));
|
||||
context.setOutput('endpoint', firstNode.endpoint); // TODO: deprecated, to be removed in a later version
|
||||
context.setOutput('status', firstNode.status); // TODO: deprecated, to be removed in a later version
|
||||
context.setOutput('flags', firstNode['buildkitd-flags']); // TODO: deprecated, to be removed in a later version
|
||||
core.endGroup();
|
||||
|
||||
if (!standalone && inputs.driver == 'docker-container') {
|
||||
stateHelper.setContainerName(`buildx_buildkit_${builder.node_name}`);
|
||||
if (!standalone && builder.driver == 'docker-container') {
|
||||
stateHelper.setContainerName(`buildx_buildkit_${firstNode.name}`);
|
||||
core.startGroup(`BuildKit version`);
|
||||
core.info(await buildx.getBuildKitVersion(`buildx_buildkit_${builder.node_name}`));
|
||||
for (const node of builder.nodes) {
|
||||
const bkvers = await buildx.getBuildKitVersion(`buildx_buildkit_${node.name}`);
|
||||
core.info(`${node.name}: ${bkvers}`);
|
||||
}
|
||||
core.endGroup();
|
||||
}
|
||||
if (core.isDebug() || builder.node_flags?.includes('--debug')) {
|
||||
if (core.isDebug() || firstNode['buildkitd-flags']?.includes('--debug')) {
|
||||
stateHelper.setDebug('true');
|
||||
}
|
||||
} catch (error) {
|
||||
|
Loading…
Reference in New Issue
Block a user