Skip to content

Commit

Permalink
Merge pull request #560 from crazy-max/builder-inspect-file
Browse files Browse the repository at this point in the history
builder: support files in inspect command
  • Loading branch information
crazy-max authored Jan 23, 2025
2 parents 2c62255 + f3bf577 commit 3c328a5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
12 changes: 12 additions & 0 deletions __tests__/.fixtures/inspect11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@ GC Policy rule#2:
GC Policy rule#3:
All: true
Keep Bytes: 94.06GiB
File#buildkitd.toml:
> debug = true
> insecure-entitlements = ["network.host", "security.insecure"]
> trace = true
>
> [log]
> format = "text"
>
File#foo.txt:
> foo = bar
> baz = qux
>
14 changes: 13 additions & 1 deletion __tests__/buildx/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,19 @@ describe('parseInspect', () => {
"all": true,
"keepBytes": "94.06GiB",
}
]
],
"files": {
"buildkitd.toml": `debug = true
insecure-entitlements = ["network.host", "security.insecure"]
trace = true
[log]
format = "text"
`,
"foo.txt": `foo = bar
baz = qux
`,
}
}
]
}
Expand Down
16 changes: 16 additions & 0 deletions src/buildx/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class Builder {
let parsingType: string | undefined;
let currentNode: NodeInfo = {};
let currentGCPolicy: GCPolicy | undefined;
let currentFile: string | undefined;
for (const line of data.trim().split(`\n`)) {
const [key, ...rest] = line.split(':');
const lkey = key.toLowerCase();
Expand Down Expand Up @@ -178,6 +179,12 @@ export class Builder {
currentGCPolicy = undefined;
}
break;
case lkey.startsWith('file#'):
parsingType = 'file';
currentFile = key.split('#')[1];
currentNode.files = currentNode.files || {};
currentNode.files[currentFile] = '';
break;
default: {
switch (parsingType || '') {
case 'features': {
Expand Down Expand Up @@ -215,6 +222,15 @@ export class Builder {
}
break;
}
case 'file': {
if (currentFile && currentNode.files) {
if (currentNode.files[currentFile].length > 0) {
currentNode.files[currentFile] += '\n';
}
currentNode.files[currentFile] += line.replace(/^\s>\s?/, '');
}
break;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/types/buildx/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface NodeInfo extends Node {
features?: Record<string, boolean>;
labels?: Record<string, string>;
gcPolicy?: Array<GCPolicy>;
files?: Record<string, string>;
}

export interface GCPolicy {
Expand Down

0 comments on commit 3c328a5

Please sign in to comment.