Skip to content

Commit 225d61b

Browse files
committed
builder: update inspect command parsing
Signed-off-by: CrazyMax <[email protected]>
1 parent a98aa04 commit 225d61b

3 files changed

Lines changed: 105 additions & 21 deletions

File tree

__tests__/buildx/builder.test.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,65 @@ describe('parseInspect', () => {
393393
}
394394
],
395395
}
396-
]
396+
],
397+
[
398+
'inspect11.txt',
399+
{
400+
"name": "builder",
401+
"driver": "docker-container",
402+
"lastActivity": new Date("2024-03-01T14:25:03.000Z"),
403+
"nodes": [
404+
{
405+
"buildkit": "37657a1",
406+
"buildkitd-flags": "--debug --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host --allow-insecure-entitlement=network.host",
407+
"driver-opts": [
408+
"env.JAEGER_TRACE=localhost:6831",
409+
"image=moby/buildkit:master",
410+
"network=host",
411+
"env.BUILDKIT_STEP_LOG_MAX_SIZE=10485760",
412+
"env.BUILDKIT_STEP_LOG_MAX_SPEED=10485760",
413+
],
414+
"endpoint": "unix:///var/run/docker.sock",
415+
"name": "builder0",
416+
"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",
417+
"status": "running",
418+
"labels": {
419+
"org.mobyproject.buildkit.worker.executor": "oci",
420+
"org.mobyproject.buildkit.worker.hostname": "docker-desktop",
421+
"org.mobyproject.buildkit.worker.network": "host",
422+
"org.mobyproject.buildkit.worker.oci.process-mode": "sandbox",
423+
"org.mobyproject.buildkit.worker.selinux.enabled": "false",
424+
"org.mobyproject.buildkit.worker.snapshotter": "overlayfs",
425+
},
426+
"gcPolicy": [
427+
{
428+
"all": false,
429+
"filter": [
430+
"type==source.local",
431+
"type==exec.cachemount",
432+
"type==source.git.checkout"
433+
],
434+
"keepDuration": "48h0m0s",
435+
"keepBytes": "488.3MiB",
436+
},
437+
{
438+
"all": false,
439+
"keepDuration": "1440h0m0s",
440+
"keepBytes": "94.06GiB",
441+
},
442+
{
443+
"all": false,
444+
"keepBytes": "94.06GiB",
445+
},
446+
{
447+
"all": true,
448+
"keepBytes": "94.06GiB",
449+
}
450+
]
451+
}
452+
]
453+
}
454+
],
397455
])('given %p', async (inspectFile, expected) => {
398456
expect(await Builder.parseInspect(fs.readFileSync(path.join(fixturesDir, inspectFile)).toString())).toEqual(expected);
399457
});

__tests__/fixtures/inspect11.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Name: builder
2+
Driver: docker-container
3+
Last Activity: 2024-03-01 14:25:03 +0000 UTC
4+
5+
Nodes:
6+
Name: builder0
7+
Endpoint: unix:///var/run/docker.sock
8+
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"
9+
Status: running
10+
BuildKit daemon flags: --debug --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host --allow-insecure-entitlement=network.host
11+
BuildKit version: 37657a1
12+
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
13+
Labels:
14+
org.mobyproject.buildkit.worker.executor: oci
15+
org.mobyproject.buildkit.worker.hostname: docker-desktop
16+
org.mobyproject.buildkit.worker.network: host
17+
org.mobyproject.buildkit.worker.oci.process-mode: sandbox
18+
org.mobyproject.buildkit.worker.selinux.enabled: false
19+
org.mobyproject.buildkit.worker.snapshotter: overlayfs
20+
GC Policy rule#0:
21+
All: false
22+
Filters: type==source.local,type==exec.cachemount,type==source.git.checkout
23+
Keep Duration: 48h0m0s
24+
Keep Bytes: 488.3MiB
25+
GC Policy rule#1:
26+
All: false
27+
Keep Duration: 1440h0m0s
28+
Keep Bytes: 94.06GiB
29+
GC Policy rule#2:
30+
All: false
31+
Keep Bytes: 94.06GiB
32+
GC Policy rule#3:
33+
All: true
34+
Keep Bytes: 94.06GiB

src/buildx/builder.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class Builder {
8383
continue;
8484
}
8585
switch (true) {
86-
case lkey == 'name': {
86+
case lkey == 'name':
8787
parsingType = undefined;
8888
if (builder.name == undefined) {
8989
builder.name = value;
@@ -98,42 +98,36 @@ export class Builder {
9898
currentNode = {name: value};
9999
}
100100
break;
101-
}
102-
case lkey == 'driver': {
101+
case lkey == 'driver':
103102
parsingType = undefined;
104103
builder.driver = value;
105104
break;
106-
}
107-
case lkey == 'last activity': {
105+
case lkey == 'last activity':
108106
parsingType = undefined;
109107
builder.lastActivity = new Date(value);
110108
break;
111-
}
112-
case lkey == 'endpoint': {
109+
case lkey == 'endpoint':
113110
parsingType = undefined;
114111
currentNode.endpoint = value;
115112
break;
116-
}
117-
case lkey == 'driver options': {
113+
case lkey == 'driver options':
118114
parsingType = undefined;
119115
currentNode['driver-opts'] = (value.match(/([a-zA-Z0-9_.]+)="([^"]*)"/g) || []).map(v => v.replace(/^(.*)="(.*)"$/g, '$1=$2'));
120116
break;
121-
}
122-
case lkey == 'status': {
117+
case lkey == 'status':
123118
parsingType = undefined;
124119
currentNode.status = value;
125120
break;
126-
}
127-
case lkey == 'flags': {
121+
case lkey == 'buildkit daemon flags':
122+
case lkey == 'flags': // buildx < v0.13
128123
parsingType = undefined;
129124
currentNode['buildkitd-flags'] = value;
130125
break;
131-
}
132-
case lkey == 'buildkit': {
126+
case lkey == 'buildkit version':
127+
case lkey == 'buildkit': // buildx < v0.13
133128
parsingType = undefined;
134129
currentNode.buildkit = value;
135130
break;
136-
}
137131
case lkey == 'platforms': {
138132
parsingType = undefined;
139133
if (!value) {
@@ -155,19 +149,17 @@ export class Builder {
155149
currentNode.platforms = platforms.join(',');
156150
break;
157151
}
158-
case lkey == 'labels': {
152+
case lkey == 'labels':
159153
parsingType = 'label';
160154
currentNode.labels = {};
161155
break;
162-
}
163-
case lkey.startsWith('gc policy rule#'): {
156+
case lkey.startsWith('gc policy rule#'):
164157
parsingType = 'gcpolicy';
165158
if (currentNode.gcPolicy && currentGCPolicy) {
166159
currentNode.gcPolicy.push(currentGCPolicy);
167160
currentGCPolicy = undefined;
168161
}
169162
break;
170-
}
171163
default: {
172164
switch (parsingType || '') {
173165
case 'label': {

0 commit comments

Comments
 (0)