mirror of
https://gitee.com/actions-mirror/docker-setup-buildx-action.git
synced 2024-11-30 16:50:41 +08:00
add tests for inspect parsing
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
69d3837448
commit
c6ec880f34
@ -77,6 +77,124 @@ describe('inspect', () => {
|
|||||||
}, 100000);
|
}, 100000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('parseInspect', () => {
|
||||||
|
// prettier-ignore
|
||||||
|
test.each([
|
||||||
|
[
|
||||||
|
'inspect1.txt',
|
||||||
|
{
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"name": "builder-5cb467f7-0940-47e1-b94b-d51f54054d620",
|
||||||
|
"endpoint": "unix:///var/run/docker.sock",
|
||||||
|
"status": "running",
|
||||||
|
"buildkitd-flags": "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host",
|
||||||
|
"buildkit": "v0.10.4",
|
||||||
|
"platforms": "linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4,linux/arm64,linux/riscv64,linux/386,linux/arm/v7,linux/arm/v6"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "builder-5cb467f7-0940-47e1-b94b-d51f54054d62",
|
||||||
|
"driver": "docker-container"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'inspect2.txt',
|
||||||
|
{
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"name": "builder-5f449644-ff29-48af-8344-abb0292d06730",
|
||||||
|
"endpoint": "unix:///var/run/docker.sock",
|
||||||
|
"driver-opts": [
|
||||||
|
"image=moby/buildkit:latest"
|
||||||
|
],
|
||||||
|
"status": "running",
|
||||||
|
"buildkitd-flags": "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host",
|
||||||
|
"buildkit": "v0.10.4",
|
||||||
|
"platforms": "linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4,linux/386"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "builder-5f449644-ff29-48af-8344-abb0292d0673",
|
||||||
|
"driver": "docker-container"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'inspect3.txt',
|
||||||
|
{
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"name": "builder-9929e463-7954-4dc3-89cd-514cca29ff800",
|
||||||
|
"endpoint": "unix:///var/run/docker.sock",
|
||||||
|
"driver-opts": [
|
||||||
|
"image=moby/buildkit:master",
|
||||||
|
"network=host"
|
||||||
|
],
|
||||||
|
"status": "running",
|
||||||
|
"buildkitd-flags": "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host",
|
||||||
|
"buildkit": "3fab389",
|
||||||
|
"platforms": "linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4,linux/386"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "builder-9929e463-7954-4dc3-89cd-514cca29ff80",
|
||||||
|
"driver": "docker-container"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'inspect4.txt',
|
||||||
|
{
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"endpoint": "default",
|
||||||
|
"status": "running",
|
||||||
|
"buildkit": "20.10.17",
|
||||||
|
"platforms": "linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "default",
|
||||||
|
"driver": "docker"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'inspect5.txt',
|
||||||
|
{
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"name": "aws_graviton2",
|
||||||
|
"endpoint": "tcp://1.23.45.67:1234",
|
||||||
|
"driver-opts": [
|
||||||
|
"cert=/home/user/.certs/aws_graviton2/cert.pem",
|
||||||
|
"key=/home/user/.certs/aws_graviton2/key.pem",
|
||||||
|
"cacert=/home/user/.certs/aws_graviton2/ca.pem"
|
||||||
|
],
|
||||||
|
"status": "running",
|
||||||
|
"platforms": "darwin/arm64,linux/arm64,linux/arm/v5,linux/arm/v6,linux/arm/v7,windows/arm64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "remote-builder",
|
||||||
|
"driver": "remote"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'inspect6.txt',
|
||||||
|
{
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"name": "builder-17cfff01-48d9-4c3d-9332-9992e308a5100",
|
||||||
|
"endpoint": "unix:///var/run/docker.sock",
|
||||||
|
"status": "running",
|
||||||
|
"buildkitd-flags": "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host",
|
||||||
|
"platforms": "linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/386"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "builder-17cfff01-48d9-4c3d-9332-9992e308a510",
|
||||||
|
"driver": "docker-container"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
])('given %p', async (inspectFile, expected) => {
|
||||||
|
expect(await buildx.parseInspect(fs.readFileSync(path.join(__dirname, 'fixtures', inspectFile)).toString())).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('build', () => {
|
describe('build', () => {
|
||||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-buildx-'));
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-buildx-'));
|
||||||
|
|
||||||
|
10
__tests__/fixtures/inspect1.txt
Normal file
10
__tests__/fixtures/inspect1.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Name: builder-5cb467f7-0940-47e1-b94b-d51f54054d62
|
||||||
|
Driver: docker-container
|
||||||
|
|
||||||
|
Nodes:
|
||||||
|
Name: builder-5cb467f7-0940-47e1-b94b-d51f54054d620
|
||||||
|
Endpoint: unix:///var/run/docker.sock
|
||||||
|
Status: running
|
||||||
|
Flags: --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
|
||||||
|
Buildkit: v0.10.4
|
||||||
|
Platforms: linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/arm64, linux/riscv64, linux/386, linux/arm/v7, linux/arm/v6
|
11
__tests__/fixtures/inspect2.txt
Normal file
11
__tests__/fixtures/inspect2.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
Name: builder-5f449644-ff29-48af-8344-abb0292d0673
|
||||||
|
Driver: docker-container
|
||||||
|
|
||||||
|
Nodes:
|
||||||
|
Name: builder-5f449644-ff29-48af-8344-abb0292d06730
|
||||||
|
Endpoint: unix:///var/run/docker.sock
|
||||||
|
Driver Options: image="moby/buildkit:latest"
|
||||||
|
Status: running
|
||||||
|
Flags: --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
|
||||||
|
Buildkit: v0.10.4
|
||||||
|
Platforms: linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/386
|
11
__tests__/fixtures/inspect3.txt
Normal file
11
__tests__/fixtures/inspect3.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
Name: builder-9929e463-7954-4dc3-89cd-514cca29ff80
|
||||||
|
Driver: docker-container
|
||||||
|
|
||||||
|
Nodes:
|
||||||
|
Name: builder-9929e463-7954-4dc3-89cd-514cca29ff800
|
||||||
|
Endpoint: unix:///var/run/docker.sock
|
||||||
|
Driver Options: image="moby/buildkit:master" network="host"
|
||||||
|
Status: running
|
||||||
|
Flags: --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
|
||||||
|
Buildkit: 3fab389
|
||||||
|
Platforms: linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/386
|
9
__tests__/fixtures/inspect4.txt
Normal file
9
__tests__/fixtures/inspect4.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Name: default
|
||||||
|
Driver: docker
|
||||||
|
|
||||||
|
Nodes:
|
||||||
|
Name: default
|
||||||
|
Endpoint: default
|
||||||
|
Status: running
|
||||||
|
Buildkit: 20.10.17
|
||||||
|
Platforms: linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
|
9
__tests__/fixtures/inspect5.txt
Normal file
9
__tests__/fixtures/inspect5.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Name: remote-builder
|
||||||
|
Driver: remote
|
||||||
|
|
||||||
|
Nodes:
|
||||||
|
Name: aws_graviton2
|
||||||
|
Endpoint: tcp://1.23.45.67:1234
|
||||||
|
Driver Options: cert="/home/user/.certs/aws_graviton2/cert.pem" key="/home/user/.certs/aws_graviton2/key.pem" cacert="/home/user/.certs/aws_graviton2/ca.pem"
|
||||||
|
Status: running
|
||||||
|
Platforms: darwin/arm64*, linux/arm64*, linux/arm/v5*, linux/arm/v6*, linux/arm/v7*, windows/arm64*, linux/amd64, linux/amd64/v2, linux/riscv64, linux/ppc64le, linux/s390x, linux/mips64le, linux/mips64
|
9
__tests__/fixtures/inspect6.txt
Normal file
9
__tests__/fixtures/inspect6.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Name: builder-17cfff01-48d9-4c3d-9332-9992e308a510
|
||||||
|
Driver: docker-container
|
||||||
|
|
||||||
|
Nodes:
|
||||||
|
Name: builder-17cfff01-48d9-4c3d-9332-9992e308a5100
|
||||||
|
Endpoint: unix:///var/run/docker.sock
|
||||||
|
Status: running
|
||||||
|
Flags: --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
|
||||||
|
Platforms: linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/386
|
@ -104,11 +104,16 @@ export async function inspect(name: string, standalone?: boolean): Promise<Build
|
|||||||
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());
|
||||||
}
|
}
|
||||||
|
return parseInspect(res.stdout);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function parseInspect(data: string): Promise<Builder> {
|
||||||
const builder: Builder = {
|
const builder: Builder = {
|
||||||
nodes: []
|
nodes: []
|
||||||
};
|
};
|
||||||
let node: Node = {};
|
let node: Node = {};
|
||||||
for (const line of res.stdout.trim().split(`\n`)) {
|
for (const line of data.trim().split(`\n`)) {
|
||||||
const [key, ...rest] = line.split(':');
|
const [key, ...rest] = line.split(':');
|
||||||
const value = rest.map(v => v.trim()).join(':');
|
const value = rest.map(v => v.trim()).join(':');
|
||||||
if (key.length == 0 || value.length == 0) {
|
if (key.length == 0 || value.length == 0) {
|
||||||
@ -174,7 +179,6 @@ export async function inspect(name: string, standalone?: boolean): Promise<Build
|
|||||||
builder.nodes.push(node);
|
builder.nodes.push(node);
|
||||||
}
|
}
|
||||||
return builder;
|
return builder;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function build(inputBuildRef: string, dest: string, standalone: boolean): Promise<string> {
|
export async function build(inputBuildRef: string, dest: string, standalone: boolean): Promise<string> {
|
||||||
|
Loading…
Reference in New Issue
Block a user