2022-10-08 16:39:00 +00:00
|
|
|
import * as context from './context';
|
2020-08-18 16:19:47 +00:00
|
|
|
import * as core from '@actions/core';
|
2023-02-19 19:49:10 +00:00
|
|
|
import * as actionsToolkit from '@docker/actions-toolkit';
|
2023-04-17 01:09:30 +00:00
|
|
|
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
2023-02-19 19:49:10 +00:00
|
|
|
import {Exec} from '@docker/actions-toolkit/lib/exec';
|
2020-08-18 16:19:47 +00:00
|
|
|
|
|
|
|
interface Platforms {
|
|
|
|
supported: string[];
|
|
|
|
available: string[];
|
|
|
|
}
|
|
|
|
|
2023-02-19 19:49:10 +00:00
|
|
|
actionsToolkit.run(
|
|
|
|
// main
|
|
|
|
async () => {
|
2022-10-08 16:39:00 +00:00
|
|
|
const input: context.Inputs = context.getInputs();
|
|
|
|
|
|
|
|
await core.group(`Docker info`, async () => {
|
2023-02-19 19:49:10 +00:00
|
|
|
await Docker.printVersion();
|
|
|
|
await Docker.printInfo();
|
2022-10-08 16:39:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
await core.group(`Pulling binfmt Docker image`, async () => {
|
2024-04-12 10:59:01 +00:00
|
|
|
await Exec.getExecOutput('docker', ['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');
|
|
|
|
}
|
|
|
|
});
|
2022-10-08 16:39:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
await core.group(`Image info`, async () => {
|
2024-04-12 10:59:01 +00:00
|
|
|
await Exec.getExecOutput('docker', ['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');
|
|
|
|
}
|
|
|
|
});
|
2022-10-08 16:39:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
await core.group(`Installing QEMU static binaries`, async () => {
|
2024-04-12 10:59:01 +00:00
|
|
|
await Exec.getExecOutput('docker', ['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');
|
|
|
|
}
|
|
|
|
});
|
2022-10-08 16:39:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
await core.group(`Extracting available platforms`, async () => {
|
2023-02-19 19:49:10 +00:00
|
|
|
await Exec.getExecOutput('docker', ['run', '--rm', '--privileged', input.image], {
|
|
|
|
ignoreReturnCode: true,
|
|
|
|
silent: true
|
|
|
|
}).then(res => {
|
|
|
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
2024-04-12 10:59:01 +00:00
|
|
|
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
|
2023-02-19 19:49:10 +00:00
|
|
|
}
|
|
|
|
const platforms: Platforms = JSON.parse(res.stdout.trim());
|
|
|
|
core.info(`${platforms.supported.join(',')}`);
|
|
|
|
core.setOutput('platforms', platforms.supported.join(','));
|
|
|
|
});
|
2022-10-08 16:39:00 +00:00
|
|
|
});
|
2020-08-18 16:19:47 +00:00
|
|
|
}
|
2023-02-19 19:49:10 +00:00
|
|
|
);
|