3
0
Fork 0
mirror of https://gitea.com/docker/setup-qemu-action.git synced 2024-11-24 18:39:33 +01:00
docker-setup-qemu/src/main.ts
CrazyMax 31629f69bf
switch to Docker exec
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-07-19 13:01:51 +02:00

66 lines
2.2 KiB
TypeScript

import * as context from './context';
import * as core from '@actions/core';
import * as actionsToolkit from '@docker/actions-toolkit';
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
interface Platforms {
supported: string[];
available: string[];
}
actionsToolkit.run(
// main
async () => {
const input: context.Inputs = context.getInputs();
await core.group(`Docker info`, async () => {
await Docker.printVersion();
await Docker.printInfo();
});
await core.group(`Pulling binfmt Docker image`, async () => {
await Docker.getExecOutput(['pull', input.image], {
ignoreReturnCode: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
}
});
});
await core.group(`Image info`, async () => {
await Docker.getExecOutput(['image', 'inspect', input.image], {
ignoreReturnCode: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
}
});
});
await core.group(`Installing QEMU static binaries`, async () => {
await Docker.getExecOutput(['run', '--rm', '--privileged', input.image, '--install', input.platforms], {
ignoreReturnCode: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
}
});
});
await core.group(`Extracting available platforms`, async () => {
await Docker.getExecOutput(['run', '--rm', '--privileged', input.image], {
ignoreReturnCode: true,
silent: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
}
const platforms: Platforms = JSON.parse(res.stdout.trim());
core.info(`${platforms.supported.join(',')}`);
core.setOutput('platforms', platforms.supported.join(','));
});
});
}
);