mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-23 11:36:10 +08:00
buildx: handle new fields for inspect output
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
495c96b050
commit
ab02f62089
@ -210,6 +210,189 @@ describe('parseInspect', () => {
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
[
|
||||
'inspect8.txt',
|
||||
{
|
||||
"name": "builder-52aa0611-faf0-42ac-a940-461e4e287d68",
|
||||
"driver": "docker-container",
|
||||
"lastActivity": new Date("2023-06-13T13:52:31.000Z"),
|
||||
"nodes": [
|
||||
{
|
||||
"buildkit": "v0.11.6",
|
||||
"buildkitd-flags": "--debug --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host",
|
||||
"driver-opts": [
|
||||
"image=moby/buildkit:buildx-stable-1",
|
||||
"network=host",
|
||||
],
|
||||
"endpoint": "unix:///var/run/docker.sock",
|
||||
"name": "builder-52aa0611-faf0-42ac-a940-461e4e287d680",
|
||||
"platforms": "linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6",
|
||||
"status": "running",
|
||||
"labels": {
|
||||
"org.mobyproject.buildkit.worker.executor": "oci",
|
||||
"org.mobyproject.buildkit.worker.hostname": "fv-az572-38",
|
||||
"org.mobyproject.buildkit.worker.network": "host",
|
||||
"org.mobyproject.buildkit.worker.oci.process-mode": "sandbox",
|
||||
"org.mobyproject.buildkit.worker.selinux.enabled": "false",
|
||||
"org.mobyproject.buildkit.worker.snapshotter": "overlayfs",
|
||||
},
|
||||
"gcPolicy": [
|
||||
{
|
||||
"all": false,
|
||||
"filter": [
|
||||
"type==source.local",
|
||||
"type==exec.cachemount",
|
||||
"type==source.git.checkout"
|
||||
],
|
||||
"keepDuration": "48h0m0s",
|
||||
"keepBytes": "488.3MiB",
|
||||
},
|
||||
{
|
||||
"all": false,
|
||||
"keepDuration": "1440h0m0s",
|
||||
"keepBytes": "8.382GiB",
|
||||
},
|
||||
{
|
||||
"all": false,
|
||||
"keepBytes": "8.382GiB",
|
||||
},
|
||||
{
|
||||
"all": true,
|
||||
"keepBytes": "8.382GiB",
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
[
|
||||
'inspect9.txt',
|
||||
{
|
||||
"name": "default",
|
||||
"driver": "docker",
|
||||
"lastActivity": new Date("2023-06-13T18:13:43.000Z"),
|
||||
"nodes": [
|
||||
{
|
||||
"buildkit": "v0.11.7-0.20230525183624-798ad6b0ce9f",
|
||||
"endpoint": "default",
|
||||
"name": "default",
|
||||
"platforms": "linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6",
|
||||
"status": "running",
|
||||
"gcPolicy": [
|
||||
{
|
||||
"all": true,
|
||||
"keepBytes": "100GiB",
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
[
|
||||
'inspect10.txt',
|
||||
{
|
||||
"name": "remote-builder",
|
||||
"driver": "remote",
|
||||
"lastActivity": new Date("2023-04-20T12:47:49.000Z"),
|
||||
"nodes": [
|
||||
{
|
||||
"name": "remote-builder0",
|
||||
"endpoint": "docker-container://buildx_buildkit_dk-remote-builder0",
|
||||
"status": "inactive"
|
||||
},
|
||||
{
|
||||
"name": "aws_graviton2",
|
||||
"endpoint": "tcp://10.0.0.1:1234",
|
||||
"driver-opts": [
|
||||
"cacert=/home/user/.certs/aws_graviton2/ca.pem",
|
||||
"cert=/home/user/.certs/aws_graviton2/cert.pem",
|
||||
"key=/home/user/.certs/aws_graviton2/key.pem"
|
||||
],
|
||||
"status": "running",
|
||||
"buildkit": "v0.11.6",
|
||||
"platforms": "darwin/arm64,linux/arm64,linux/arm/v5,linux/arm/v6,linux/arm/v7,windows/arm64",
|
||||
"labels": {
|
||||
"org.mobyproject.buildkit.worker.executor": "oci",
|
||||
"org.mobyproject.buildkit.worker.hostname": "77ebc22e2d82",
|
||||
"org.mobyproject.buildkit.worker.network": "host",
|
||||
"org.mobyproject.buildkit.worker.oci.process-mode": "sandbox",
|
||||
"org.mobyproject.buildkit.worker.selinux.enabled": "false",
|
||||
"org.mobyproject.buildkit.worker.snapshotter": "overlayfs"
|
||||
},
|
||||
"gcPolicy": [
|
||||
{
|
||||
"all": false,
|
||||
"filter": [
|
||||
"type==source.local",
|
||||
"type==exec.cachemount",
|
||||
"type==source.git.checkout"
|
||||
],
|
||||
"keepDuration": "48h0m0s",
|
||||
"keepBytes": "488.3MiB"
|
||||
},
|
||||
{
|
||||
"all": false,
|
||||
"keepDuration": "1440h0m0s",
|
||||
"keepBytes": "23.28GiB"
|
||||
},
|
||||
{
|
||||
"all": false,
|
||||
"keepBytes": "23.28GiB"
|
||||
},
|
||||
{
|
||||
"all": true,
|
||||
"keepBytes": "23.28GiB"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "linuxone_s390x",
|
||||
"endpoint": "tcp://10.0.0.2:1234",
|
||||
"driver-opts": [
|
||||
"cacert=/home/user/.certs/linuxone_s390x/ca.pem",
|
||||
"cert=/home/user/.certs/linuxone_s390x/cert.pem",
|
||||
"key=/home/user/.certs/linuxone_s390x/key.pem"
|
||||
],
|
||||
"status": "running",
|
||||
"buildkit": "v0.11.6",
|
||||
"platforms": "linux/s390x",
|
||||
"labels": {
|
||||
"org.mobyproject.buildkit.worker.executor": "oci",
|
||||
"org.mobyproject.buildkit.worker.hostname": "9d0d62a96818",
|
||||
"org.mobyproject.buildkit.worker.network": "host",
|
||||
"org.mobyproject.buildkit.worker.oci.process-mode": "sandbox",
|
||||
"org.mobyproject.buildkit.worker.selinux.enabled": "false",
|
||||
"org.mobyproject.buildkit.worker.snapshotter": "overlayfs"
|
||||
},
|
||||
"gcPolicy": [
|
||||
{
|
||||
"all": false,
|
||||
"keepBytes": "488.3MiB",
|
||||
"filter": [
|
||||
"type==source.local",
|
||||
"type==exec.cachemount",
|
||||
"type==source.git.checkout"
|
||||
],
|
||||
"keepDuration": "48h0m0s"
|
||||
},
|
||||
{
|
||||
"all": false,
|
||||
"keepDuration": "1440h0m0s",
|
||||
"keepBytes": "9.313GiB"
|
||||
},
|
||||
{
|
||||
"all": false,
|
||||
"keepBytes": "9.313GiB"
|
||||
},
|
||||
{
|
||||
"all": true,
|
||||
"keepBytes": "9.313GiB"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
])('given %p', async (inspectFile, expected) => {
|
||||
expect(await Builder.parseInspect(fs.readFileSync(path.join(fixturesDir, inspectFile)).toString())).toEqual(expected);
|
||||
|
67
__tests__/fixtures/inspect10.txt
Normal file
67
__tests__/fixtures/inspect10.txt
Normal file
@ -0,0 +1,67 @@
|
||||
Name: remote-builder
|
||||
Driver: remote
|
||||
Last Activity: 2023-04-20 12:47:49 +0000 UTC
|
||||
|
||||
Nodes:
|
||||
Name: remote-builder0
|
||||
Endpoint: docker-container://buildx_buildkit_dk-remote-builder0
|
||||
Status: inactive
|
||||
Platforms:
|
||||
|
||||
Name: aws_graviton2
|
||||
Endpoint: tcp://10.0.0.1:1234
|
||||
Driver Options: cacert="/home/user/.certs/aws_graviton2/ca.pem" cert="/home/user/.certs/aws_graviton2/cert.pem" key="/home/user/.certs/aws_graviton2/key.pem"
|
||||
Status: running
|
||||
Buildkit: v0.11.6
|
||||
Platforms: darwin/arm64*, linux/arm64*, linux/arm/v5*, linux/arm/v6*, linux/arm/v7*, windows/arm64*
|
||||
Labels:
|
||||
org.mobyproject.buildkit.worker.executor: oci
|
||||
org.mobyproject.buildkit.worker.hostname: 77ebc22e2d82
|
||||
org.mobyproject.buildkit.worker.network: host
|
||||
org.mobyproject.buildkit.worker.oci.process-mode: sandbox
|
||||
org.mobyproject.buildkit.worker.selinux.enabled: false
|
||||
org.mobyproject.buildkit.worker.snapshotter: overlayfs
|
||||
GC Policy rule#0:
|
||||
All: false
|
||||
Filters: type==source.local,type==exec.cachemount,type==source.git.checkout
|
||||
Keep Duration: 48h0m0s
|
||||
Keep Bytes: 488.3MiB
|
||||
GC Policy rule#1:
|
||||
All: false
|
||||
Keep Duration: 1440h0m0s
|
||||
Keep Bytes: 23.28GiB
|
||||
GC Policy rule#2:
|
||||
All: false
|
||||
Keep Bytes: 23.28GiB
|
||||
GC Policy rule#3:
|
||||
All: true
|
||||
Keep Bytes: 23.28GiB
|
||||
|
||||
Name: linuxone_s390x
|
||||
Endpoint: tcp://10.0.0.2:1234
|
||||
Driver Options: cacert="/home/user/.certs/linuxone_s390x/ca.pem" cert="/home/user/.certs/linuxone_s390x/cert.pem" key="/home/user/.certs/linuxone_s390x/key.pem"
|
||||
Status: running
|
||||
Buildkit: v0.11.6
|
||||
Platforms: linux/s390x*
|
||||
Labels:
|
||||
org.mobyproject.buildkit.worker.executor: oci
|
||||
org.mobyproject.buildkit.worker.hostname: 9d0d62a96818
|
||||
org.mobyproject.buildkit.worker.network: host
|
||||
org.mobyproject.buildkit.worker.oci.process-mode: sandbox
|
||||
org.mobyproject.buildkit.worker.selinux.enabled: false
|
||||
org.mobyproject.buildkit.worker.snapshotter: overlayfs
|
||||
GC Policy rule#0:
|
||||
All: false
|
||||
Filters: type==source.local,type==exec.cachemount,type==source.git.checkout
|
||||
Keep Duration: 48h0m0s
|
||||
Keep Bytes: 488.3MiB
|
||||
GC Policy rule#1:
|
||||
All: false
|
||||
Keep Duration: 1440h0m0s
|
||||
Keep Bytes: 9.313GiB
|
||||
GC Policy rule#2:
|
||||
All: false
|
||||
Keep Bytes: 9.313GiB
|
||||
GC Policy rule#3:
|
||||
All: true
|
||||
Keep Bytes: 9.313GiB
|
34
__tests__/fixtures/inspect8.txt
Normal file
34
__tests__/fixtures/inspect8.txt
Normal file
@ -0,0 +1,34 @@
|
||||
Name: builder-52aa0611-faf0-42ac-a940-461e4e287d68
|
||||
Driver: docker-container
|
||||
Last Activity: 2023-06-13 13:52:31 +0000 UTC
|
||||
|
||||
Nodes:
|
||||
Name: builder-52aa0611-faf0-42ac-a940-461e4e287d680
|
||||
Endpoint: unix:///var/run/docker.sock
|
||||
Driver Options: image="moby/buildkit:buildx-stable-1" network="host"
|
||||
Status: running
|
||||
Flags: --debug --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
|
||||
Buildkit: v0.11.6
|
||||
Platforms: linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
|
||||
Labels:
|
||||
org.mobyproject.buildkit.worker.executor: oci
|
||||
org.mobyproject.buildkit.worker.hostname: fv-az572-38
|
||||
org.mobyproject.buildkit.worker.network: host
|
||||
org.mobyproject.buildkit.worker.oci.process-mode: sandbox
|
||||
org.mobyproject.buildkit.worker.selinux.enabled: false
|
||||
org.mobyproject.buildkit.worker.snapshotter: overlayfs
|
||||
GC Policy rule#0:
|
||||
All: false
|
||||
Filters: type==source.local,type==exec.cachemount,type==source.git.checkout
|
||||
Keep Duration: 48h0m0s
|
||||
Keep Bytes: 488.3MiB
|
||||
GC Policy rule#1:
|
||||
All: false
|
||||
Keep Duration: 1440h0m0s
|
||||
Keep Bytes: 8.382GiB
|
||||
GC Policy rule#2:
|
||||
All: false
|
||||
Keep Bytes: 8.382GiB
|
||||
GC Policy rule#3:
|
||||
All: true
|
||||
Keep Bytes: 8.382GiB
|
14
__tests__/fixtures/inspect9.txt
Normal file
14
__tests__/fixtures/inspect9.txt
Normal file
@ -0,0 +1,14 @@
|
||||
Name: default
|
||||
Driver: docker
|
||||
Last Activity: 2023-06-13 18:13:43 +0000 UTC
|
||||
|
||||
Nodes:
|
||||
Name: default
|
||||
Endpoint: default
|
||||
Status: running
|
||||
Buildkit: v0.11.7-0.20230525183624-798ad6b0ce9f
|
||||
Platforms: linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
|
||||
GC Policy rule#0:
|
||||
All: true
|
||||
Filters:
|
||||
Keep Bytes: 100GiB
|
@ -19,7 +19,7 @@ import * as core from '@actions/core';
|
||||
import {Buildx} from './buildx';
|
||||
import {Exec} from '../exec';
|
||||
|
||||
import {BuilderInfo, NodeInfo} from '../types/builder';
|
||||
import {BuilderInfo, GCPolicy, NodeInfo} from '../types/builder';
|
||||
|
||||
export interface BuilderOpts {
|
||||
buildx?: Buildx;
|
||||
@ -72,55 +72,73 @@ export class Builder {
|
||||
const builder: BuilderInfo = {
|
||||
nodes: []
|
||||
};
|
||||
let node: NodeInfo = {};
|
||||
let parsingType: string | undefined;
|
||||
let currentNode: NodeInfo = {};
|
||||
let currentGCPolicy: GCPolicy | undefined;
|
||||
for (const line of data.trim().split(`\n`)) {
|
||||
const [key, ...rest] = line.split(':');
|
||||
const lkey = key.toLowerCase();
|
||||
const value = rest.map(v => v.trim()).join(':');
|
||||
if (key.length == 0 || value.length == 0) {
|
||||
if (key.length == 0) {
|
||||
continue;
|
||||
}
|
||||
switch (key.toLowerCase()) {
|
||||
case 'name': {
|
||||
switch (true) {
|
||||
case lkey == 'name': {
|
||||
parsingType = undefined;
|
||||
if (builder.name == undefined) {
|
||||
builder.name = value;
|
||||
} else {
|
||||
if (Object.keys(node).length > 0) {
|
||||
builder.nodes.push(node);
|
||||
node = {};
|
||||
if (currentGCPolicy && currentNode.gcPolicy) {
|
||||
currentNode.gcPolicy.push(currentGCPolicy);
|
||||
currentGCPolicy = undefined;
|
||||
}
|
||||
node.name = value;
|
||||
if (currentNode.name) {
|
||||
builder.nodes.push(currentNode);
|
||||
}
|
||||
currentNode = {name: value};
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'driver': {
|
||||
case lkey == 'driver': {
|
||||
parsingType = undefined;
|
||||
builder.driver = value;
|
||||
break;
|
||||
}
|
||||
case 'last activity': {
|
||||
case lkey == 'last activity': {
|
||||
parsingType = undefined;
|
||||
builder.lastActivity = new Date(value);
|
||||
break;
|
||||
}
|
||||
case 'endpoint': {
|
||||
node.endpoint = value;
|
||||
case lkey == 'endpoint': {
|
||||
parsingType = undefined;
|
||||
currentNode.endpoint = value;
|
||||
break;
|
||||
}
|
||||
case 'driver options': {
|
||||
node['driver-opts'] = (value.match(/([a-zA-Z0-9_.]+)="([^"]*)"/g) || []).map(v => v.replace(/^(.*)="(.*)"$/g, '$1=$2'));
|
||||
case lkey == 'driver options': {
|
||||
parsingType = undefined;
|
||||
currentNode['driver-opts'] = (value.match(/([a-zA-Z0-9_.]+)="([^"]*)"/g) || []).map(v => v.replace(/^(.*)="(.*)"$/g, '$1=$2'));
|
||||
break;
|
||||
}
|
||||
case 'status': {
|
||||
node.status = value;
|
||||
case lkey == 'status': {
|
||||
parsingType = undefined;
|
||||
currentNode.status = value;
|
||||
break;
|
||||
}
|
||||
case 'flags': {
|
||||
node['buildkitd-flags'] = value;
|
||||
case lkey == 'flags': {
|
||||
parsingType = undefined;
|
||||
currentNode['buildkitd-flags'] = value;
|
||||
break;
|
||||
}
|
||||
case 'buildkit': {
|
||||
node.buildkit = value;
|
||||
case lkey == 'buildkit': {
|
||||
parsingType = undefined;
|
||||
currentNode.buildkit = value;
|
||||
break;
|
||||
}
|
||||
case 'platforms': {
|
||||
case lkey == 'platforms': {
|
||||
parsingType = undefined;
|
||||
if (!value) {
|
||||
break;
|
||||
}
|
||||
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
|
||||
@ -134,13 +152,63 @@ export class Builder {
|
||||
// otherwise set all platforms available
|
||||
platforms = value.split(', ');
|
||||
}
|
||||
node.platforms = platforms.join(',');
|
||||
currentNode.platforms = platforms.join(',');
|
||||
break;
|
||||
}
|
||||
case lkey == 'labels': {
|
||||
parsingType = 'label';
|
||||
currentNode.labels = {};
|
||||
break;
|
||||
}
|
||||
case lkey.startsWith('gc policy rule#'): {
|
||||
parsingType = 'gcpolicy';
|
||||
if (currentNode.gcPolicy && currentGCPolicy) {
|
||||
currentNode.gcPolicy.push(currentGCPolicy);
|
||||
currentGCPolicy = undefined;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
switch (parsingType || '') {
|
||||
case 'label': {
|
||||
currentNode.labels = currentNode.labels || {};
|
||||
currentNode.labels[key.trim()] = value;
|
||||
break;
|
||||
}
|
||||
case 'gcpolicy': {
|
||||
currentNode.gcPolicy = currentNode.gcPolicy || [];
|
||||
currentGCPolicy = currentGCPolicy || {};
|
||||
switch (lkey.trim()) {
|
||||
case 'all': {
|
||||
currentGCPolicy.all = value == 'true';
|
||||
break;
|
||||
}
|
||||
case 'filters': {
|
||||
if (value) {
|
||||
currentGCPolicy.filter = value.split(',');
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'keep duration': {
|
||||
currentGCPolicy.keepDuration = value;
|
||||
break;
|
||||
}
|
||||
case 'keep bytes': {
|
||||
currentGCPolicy.keepBytes = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Object.keys(node).length > 0) {
|
||||
builder.nodes.push(node);
|
||||
if (currentGCPolicy && currentNode.gcPolicy) {
|
||||
currentNode.gcPolicy.push(currentGCPolicy);
|
||||
}
|
||||
if (currentNode.name) {
|
||||
builder.nodes.push(currentNode);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
@ -32,4 +32,13 @@ export interface Node {
|
||||
export interface NodeInfo extends Node {
|
||||
status?: string;
|
||||
buildkit?: string;
|
||||
labels?: Record<string, string>;
|
||||
gcPolicy?: Array<GCPolicy>;
|
||||
}
|
||||
|
||||
export interface GCPolicy {
|
||||
all?: boolean;
|
||||
filter?: string[];
|
||||
keepDuration?: string;
|
||||
keepBytes?: string;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user