mirror of
https://github.com/docker/setup-qemu-action.git
synced 2025-07-06 18:38:24 +02:00
switch to actions-toolkit implementation
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import * as core from '@actions/core';
|
||||
import {Util} from '@docker/actions-toolkit/lib/util';
|
||||
|
||||
export interface Inputs {
|
||||
image: string;
|
||||
@ -8,11 +9,6 @@ export interface Inputs {
|
||||
export function getInputs(): Inputs {
|
||||
return {
|
||||
image: core.getInput('image') || 'tonistiigi/binfmt:latest',
|
||||
platforms:
|
||||
core
|
||||
.getInput('platforms')
|
||||
.split(',')
|
||||
.map(v => v.trim())
|
||||
.join(',') || 'all'
|
||||
platforms: Util.getInputList('platforms').join(',') || 'all'
|
||||
};
|
||||
}
|
||||
|
53
src/main.ts
53
src/main.ts
@ -1,55 +1,48 @@
|
||||
import * as context from './context';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as actionsToolkit from '@docker/actions-toolkit';
|
||||
import {Docker} from '@docker/actions-toolkit/lib/docker';
|
||||
import {Exec} from '@docker/actions-toolkit/lib/exec';
|
||||
|
||||
interface Platforms {
|
||||
supported: string[];
|
||||
available: string[];
|
||||
}
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
actionsToolkit.run(
|
||||
// main
|
||||
async () => {
|
||||
const input: context.Inputs = context.getInputs();
|
||||
|
||||
await core.group(`Docker info`, async () => {
|
||||
await exec.exec('docker', ['version'], {
|
||||
failOnStdErr: false
|
||||
});
|
||||
await exec.exec('docker', ['info'], {
|
||||
failOnStdErr: false
|
||||
});
|
||||
await Docker.printVersion();
|
||||
await Docker.printInfo();
|
||||
});
|
||||
|
||||
await core.group(`Pulling binfmt Docker image`, async () => {
|
||||
await exec.exec('docker', ['pull', input.image]);
|
||||
await Exec.exec('docker', ['pull', input.image]);
|
||||
});
|
||||
|
||||
await core.group(`Image info`, async () => {
|
||||
await exec.exec('docker', ['image', 'inspect', input.image]);
|
||||
await Exec.exec('docker', ['image', 'inspect', input.image]);
|
||||
});
|
||||
|
||||
await core.group(`Installing QEMU static binaries`, async () => {
|
||||
await exec.exec('docker', ['run', '--rm', '--privileged', input.image, '--install', input.platforms]);
|
||||
await Exec.exec('docker', ['run', '--rm', '--privileged', input.image, '--install', input.platforms]);
|
||||
});
|
||||
|
||||
await core.group(`Extracting available platforms`, async () => {
|
||||
await exec
|
||||
.getExecOutput('docker', ['run', '--rm', '--privileged', input.image], {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
})
|
||||
.then(res => {
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
throw new Error(res.stderr.trim());
|
||||
}
|
||||
const platforms: Platforms = JSON.parse(res.stdout.trim());
|
||||
core.info(`${platforms.supported.join(',')}`);
|
||||
core.setOutput('platforms', platforms.supported.join(','));
|
||||
});
|
||||
await Exec.getExecOutput('docker', ['run', '--rm', '--privileged', input.image], {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
}).then(res => {
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
throw new Error(res.stderr.trim());
|
||||
}
|
||||
const platforms: Platforms = JSON.parse(res.stdout.trim());
|
||||
core.info(`${platforms.supported.join(',')}`);
|
||||
core.setOutput('platforms', platforms.supported.join(','));
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
);
|
||||
|
Reference in New Issue
Block a user