Skip to content

Commit

Permalink
builder: update inspect command parsing
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Mar 12, 2024
1 parent a98aa04 commit 225d61b
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 21 deletions.
60 changes: 59 additions & 1 deletion __tests__/buildx/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
expect(await Builder.parseInspect(fs.readFileSync(path.join(fixturesDir, inspectFile)).toString())).toEqual(expected);
});
Expand Down
34 changes: 34 additions & 0 deletions __tests__/fixtures/inspect11.txt
Original file line number Diff line number Diff line change
@@ -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
32 changes: 12 additions & 20 deletions src/buildx/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class Builder {
continue;
}
switch (true) {
case lkey == 'name': {
case lkey == 'name':
parsingType = undefined;
if (builder.name == undefined) {
builder.name = value;
Expand All @@ -98,42 +98,36 @@ export class Builder {
currentNode = {name: value};
}
break;
}
case lkey == 'driver': {
case lkey == 'driver':
parsingType = undefined;
builder.driver = value;
break;
}
case lkey == 'last activity': {
case lkey == 'last activity':
parsingType = undefined;
builder.lastActivity = new Date(value);
break;
}
case lkey == 'endpoint': {
case lkey == 'endpoint':
parsingType = undefined;
currentNode.endpoint = value;
break;
}
case lkey == 'driver options': {
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 lkey == 'status': {
case lkey == 'status':
parsingType = undefined;
currentNode.status = value;
break;
}
case lkey == 'flags': {
case lkey == 'buildkit daemon flags':
case lkey == 'flags': // buildx < v0.13
parsingType = undefined;
currentNode['buildkitd-flags'] = value;
break;
}
case lkey == 'buildkit': {
case lkey == 'buildkit version':
case lkey == 'buildkit': // buildx < v0.13
parsingType = undefined;
currentNode.buildkit = value;
break;
}
case lkey == 'platforms': {
parsingType = undefined;
if (!value) {
Expand All @@ -155,19 +149,17 @@ export class Builder {
currentNode.platforms = platforms.join(',');
break;
}
case lkey == 'labels': {
case lkey == 'labels':
parsingType = 'label';
currentNode.labels = {};
break;
}
case lkey.startsWith('gc policy rule#'): {
case lkey.startsWith('gc policy rule#'):
parsingType = 'gcpolicy';
if (currentNode.gcPolicy && currentGCPolicy) {
currentNode.gcPolicy.push(currentGCPolicy);
currentGCPolicy = undefined;
}
break;
}
default: {
switch (parsingType || '') {
case 'label': {
Expand Down

0 comments on commit 225d61b

Please sign in to comment.