builder: update inspect command parsing

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2024-03-08 11:40:09 +01:00
parent a98aa046a8
commit 225d61b701
No known key found for this signature in database
GPG Key ID: ADE44D8C9D44FBE4
3 changed files with 105 additions and 21 deletions

View File

@ -393,7 +393,65 @@ 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",
"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);
}); });

View File

@ -0,0 +1,34 @@
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
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

View File

@ -83,7 +83,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 +98,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,19 +149,17 @@ export class Builder {
currentNode.platforms = platforms.join(','); currentNode.platforms = platforms.join(',');
break; break;
} }
case lkey == 'labels': { 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 'label': { case 'label': {