1
0
Files
setup-qemu-action/src/main.ts
T

72 lines
2.3 KiB
TypeScript
Raw Normal View History

import * as core from '@actions/core';
2023-02-19 20:49:10 +01:00
import * as actionsToolkit from '@docker/actions-toolkit';
2024-07-19 13:01:47 +02:00
2026-02-28 02:03:44 +01:00
import {Docker} from '@docker/actions-toolkit/lib/docker/docker.js';
import * as context from './context.js';
interface Platforms {
supported: string[];
available: string[];
}
2023-02-19 20:49:10 +01:00
actionsToolkit.run(
// main
async () => {
2022-10-08 18:39:00 +02:00
const input: context.Inputs = context.getInputs();
await core.group(`Docker info`, async () => {
2023-02-19 20:49:10 +01:00
await Docker.printVersion();
await Docker.printInfo();
2022-10-08 18:39:00 +02:00
});
await core.group(`Pulling binfmt Docker image`, async () => {
await Docker.pull(input.image, input.cacheImage);
2022-10-08 18:39:00 +02:00
});
await core.group(`Image info`, async () => {
2024-07-19 13:01:47 +02:00
await Docker.getExecOutput(['image', 'inspect', input.image], {
2024-04-12 12:59:01 +02:00
ignoreReturnCode: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
}
});
2025-02-15 12:13:25 +01:00
});
await core.group(`Binfmt version`, async () => {
await Docker.getExecOutput(['run', '--rm', '--privileged', input.image, '--version'], {
ignoreReturnCode: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
}
});
2022-10-08 18:39:00 +02:00
});
await core.group(`Installing QEMU static binaries`, async () => {
2024-07-19 13:01:47 +02:00
await Docker.getExecOutput(['run', '--rm', '--privileged', input.image, '--install', input.platforms], {
2024-04-12 12:59:01 +02:00
ignoreReturnCode: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
}
});
2022-10-08 18:39:00 +02:00
});
await core.group(`Extracting available platforms`, async () => {
2024-07-19 13:01:47 +02:00
await Docker.getExecOutput(['run', '--rm', '--privileged', input.image], {
2023-02-19 20:49:10 +01:00
ignoreReturnCode: true,
silent: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
2024-04-12 12:59:01 +02:00
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
2023-02-19 20:49:10 +01:00
}
const platforms: Platforms = JSON.parse(res.stdout.trim());
core.info(`${platforms.supported.join(',')}`);
core.setOutput('platforms', platforms.supported.join(','));
});
2022-10-08 18:39:00 +02:00
});
}
2023-02-19 20:49:10 +01:00
);