Merge pull request #276 from crazy-max/update-builder-inspect
builder: update inspect command parsing
This commit is contained in:
@@ -393,7 +393,71 @@ describe('parseInspect', () => {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
[
|
||||||
|
'inspect11.txt',
|
||||||
|
{
|
||||||
|
"name": "builder",
|
||||||
|
"driver": "docker-container",
|
||||||
|
"lastActivity": new Date("2024-03-01T14:25:03.000Z"),
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"buildkit": "37657a1",
|
||||||
|
"buildkitd-flags": "--debug --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host --allow-insecure-entitlement=network.host",
|
||||||
|
"driver-opts": [
|
||||||
|
"env.JAEGER_TRACE=localhost:6831",
|
||||||
|
"image=moby/buildkit:master",
|
||||||
|
"network=host",
|
||||||
|
"env.BUILDKIT_STEP_LOG_MAX_SIZE=10485760",
|
||||||
|
"env.BUILDKIT_STEP_LOG_MAX_SPEED=10485760",
|
||||||
|
],
|
||||||
|
"endpoint": "unix:///var/run/docker.sock",
|
||||||
|
"name": "builder0",
|
||||||
|
"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",
|
||||||
|
"features": {
|
||||||
|
"Cache export": true,
|
||||||
|
"Docker exporter": true,
|
||||||
|
"Multi-platform build": true,
|
||||||
|
"OCI exporter": true,
|
||||||
|
},
|
||||||
|
"labels": {
|
||||||
|
"org.mobyproject.buildkit.worker.executor": "oci",
|
||||||
|
"org.mobyproject.buildkit.worker.hostname": "docker-desktop",
|
||||||
|
"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": "94.06GiB",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"all": false,
|
||||||
|
"keepBytes": "94.06GiB",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"all": true,
|
||||||
|
"keepBytes": "94.06GiB",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
])('given %p', async (inspectFile, expected) => {
|
])('given %p', async (inspectFile, expected) => {
|
||||||
expect(await Builder.parseInspect(fs.readFileSync(path.join(fixturesDir, inspectFile)).toString())).toEqual(expected);
|
expect(await Builder.parseInspect(fs.readFileSync(path.join(fixturesDir, inspectFile)).toString())).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|||||||
39
__tests__/fixtures/inspect11.txt
Normal file
39
__tests__/fixtures/inspect11.txt
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
Name: builder
|
||||||
|
Driver: docker-container
|
||||||
|
Last Activity: 2024-03-01 14:25:03 +0000 UTC
|
||||||
|
|
||||||
|
Nodes:
|
||||||
|
Name: builder0
|
||||||
|
Endpoint: unix:///var/run/docker.sock
|
||||||
|
Driver Options: env.JAEGER_TRACE="localhost:6831" image="moby/buildkit:master" network="host" env.BUILDKIT_STEP_LOG_MAX_SIZE="10485760" env.BUILDKIT_STEP_LOG_MAX_SPEED="10485760"
|
||||||
|
Status: running
|
||||||
|
BuildKit daemon flags: --debug --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host --allow-insecure-entitlement=network.host
|
||||||
|
BuildKit version: 37657a1
|
||||||
|
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
|
||||||
|
Features:
|
||||||
|
Cache export: true
|
||||||
|
Docker exporter: true
|
||||||
|
Multi-platform build: true
|
||||||
|
OCI exporter: true
|
||||||
|
Labels:
|
||||||
|
org.mobyproject.buildkit.worker.executor: oci
|
||||||
|
org.mobyproject.buildkit.worker.hostname: docker-desktop
|
||||||
|
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: 94.06GiB
|
||||||
|
GC Policy rule#2:
|
||||||
|
All: false
|
||||||
|
Keep Bytes: 94.06GiB
|
||||||
|
GC Policy rule#3:
|
||||||
|
All: true
|
||||||
|
Keep Bytes: 94.06GiB
|
||||||
@@ -56,10 +56,19 @@ export class Builder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async inspect(name: string): Promise<BuilderInfo> {
|
public async inspect(name: string): Promise<BuilderInfo> {
|
||||||
|
// always enable debug for inspect command, so we can display additional
|
||||||
|
// fields such as features: https://github.com/docker/buildx/pull/1854
|
||||||
|
const envs = Object.assign({}, process.env, {
|
||||||
|
DEBUG: '1'
|
||||||
|
}) as {
|
||||||
|
[key: string]: string;
|
||||||
|
};
|
||||||
|
|
||||||
const cmd = await this.buildx.getCommand(['inspect', name]);
|
const cmd = await this.buildx.getCommand(['inspect', name]);
|
||||||
return await Exec.getExecOutput(cmd.command, cmd.args, {
|
return await Exec.getExecOutput(cmd.command, cmd.args, {
|
||||||
ignoreReturnCode: true,
|
ignoreReturnCode: true,
|
||||||
silent: true
|
silent: true,
|
||||||
|
env: envs
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
throw new Error(res.stderr.trim());
|
throw new Error(res.stderr.trim());
|
||||||
@@ -83,7 +92,7 @@ export class Builder {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case lkey == 'name': {
|
case lkey == 'name':
|
||||||
parsingType = undefined;
|
parsingType = undefined;
|
||||||
if (builder.name == undefined) {
|
if (builder.name == undefined) {
|
||||||
builder.name = value;
|
builder.name = value;
|
||||||
@@ -98,42 +107,36 @@ export class Builder {
|
|||||||
currentNode = {name: value};
|
currentNode = {name: value};
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
case lkey == 'driver':
|
||||||
case lkey == 'driver': {
|
|
||||||
parsingType = undefined;
|
parsingType = undefined;
|
||||||
builder.driver = value;
|
builder.driver = value;
|
||||||
break;
|
break;
|
||||||
}
|
case lkey == 'last activity':
|
||||||
case lkey == 'last activity': {
|
|
||||||
parsingType = undefined;
|
parsingType = undefined;
|
||||||
builder.lastActivity = new Date(value);
|
builder.lastActivity = new Date(value);
|
||||||
break;
|
break;
|
||||||
}
|
case lkey == 'endpoint':
|
||||||
case lkey == 'endpoint': {
|
|
||||||
parsingType = undefined;
|
parsingType = undefined;
|
||||||
currentNode.endpoint = value;
|
currentNode.endpoint = value;
|
||||||
break;
|
break;
|
||||||
}
|
case lkey == 'driver options':
|
||||||
case lkey == 'driver options': {
|
|
||||||
parsingType = undefined;
|
parsingType = undefined;
|
||||||
currentNode['driver-opts'] = (value.match(/([a-zA-Z0-9_.]+)="([^"]*)"/g) || []).map(v => v.replace(/^(.*)="(.*)"$/g, '$1=$2'));
|
currentNode['driver-opts'] = (value.match(/([a-zA-Z0-9_.]+)="([^"]*)"/g) || []).map(v => v.replace(/^(.*)="(.*)"$/g, '$1=$2'));
|
||||||
break;
|
break;
|
||||||
}
|
case lkey == 'status':
|
||||||
case lkey == 'status': {
|
|
||||||
parsingType = undefined;
|
parsingType = undefined;
|
||||||
currentNode.status = value;
|
currentNode.status = value;
|
||||||
break;
|
break;
|
||||||
}
|
case lkey == 'buildkit daemon flags':
|
||||||
case lkey == 'flags': {
|
case lkey == 'flags': // buildx < v0.13
|
||||||
parsingType = undefined;
|
parsingType = undefined;
|
||||||
currentNode['buildkitd-flags'] = value;
|
currentNode['buildkitd-flags'] = value;
|
||||||
break;
|
break;
|
||||||
}
|
case lkey == 'buildkit version':
|
||||||
case lkey == 'buildkit': {
|
case lkey == 'buildkit': // buildx < v0.13
|
||||||
parsingType = undefined;
|
parsingType = undefined;
|
||||||
currentNode.buildkit = value;
|
currentNode.buildkit = value;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case lkey == 'platforms': {
|
case lkey == 'platforms': {
|
||||||
parsingType = undefined;
|
parsingType = undefined;
|
||||||
if (!value) {
|
if (!value) {
|
||||||
@@ -155,21 +158,28 @@ export class Builder {
|
|||||||
currentNode.platforms = platforms.join(',');
|
currentNode.platforms = platforms.join(',');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case lkey == 'labels': {
|
case lkey == 'features':
|
||||||
|
parsingType = 'features';
|
||||||
|
currentNode.features = {};
|
||||||
|
break;
|
||||||
|
case lkey == 'labels':
|
||||||
parsingType = 'label';
|
parsingType = 'label';
|
||||||
currentNode.labels = {};
|
currentNode.labels = {};
|
||||||
break;
|
break;
|
||||||
}
|
case lkey.startsWith('gc policy rule#'):
|
||||||
case lkey.startsWith('gc policy rule#'): {
|
|
||||||
parsingType = 'gcpolicy';
|
parsingType = 'gcpolicy';
|
||||||
if (currentNode.gcPolicy && currentGCPolicy) {
|
if (currentNode.gcPolicy && currentGCPolicy) {
|
||||||
currentNode.gcPolicy.push(currentGCPolicy);
|
currentNode.gcPolicy.push(currentGCPolicy);
|
||||||
currentGCPolicy = undefined;
|
currentGCPolicy = undefined;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default: {
|
default: {
|
||||||
switch (parsingType || '') {
|
switch (parsingType || '') {
|
||||||
|
case 'features': {
|
||||||
|
currentNode.features = currentNode.features || {};
|
||||||
|
currentNode.features[key.trim()] = Boolean(value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'label': {
|
case 'label': {
|
||||||
currentNode.labels = currentNode.labels || {};
|
currentNode.labels = currentNode.labels || {};
|
||||||
currentNode.labels[key.trim()] = value;
|
currentNode.labels[key.trim()] = value;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export interface Node {
|
|||||||
export interface NodeInfo extends Node {
|
export interface NodeInfo extends Node {
|
||||||
status?: string;
|
status?: string;
|
||||||
buildkit?: string;
|
buildkit?: string;
|
||||||
|
features?: Record<string, boolean>;
|
||||||
labels?: Record<string, string>;
|
labels?: Record<string, string>;
|
||||||
gcPolicy?: Array<GCPolicy>;
|
gcPolicy?: Array<GCPolicy>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user