|
|
@@ -1,53 +1,48 @@ |
|
|
import * as mexec from './exec'; |
|
|
import * as context from './context'; |
|
|
import * as core from '@actions/core'; |
|
|
import * as exec from '@actions/exec'; |
|
|
import {issueCommand} from '@actions/core/lib/command'; |
|
|
import * as actionsToolkit from '@docker/actions-toolkit'; |
|
|
import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; |
|
|
import {Exec} from '@docker/actions-toolkit/lib/exec'; |
|
|
|
|
|
interface Platforms { |
|
|
supported: string[]; |
|
|
available: string[]; |
|
|
} |
|
|
|
|
|
async function run(): Promise<void> { |
|
|
try { |
|
|
core.startGroup(`Docker info`); |
|
|
await exec.exec('docker', ['version']); |
|
|
await exec.exec('docker', ['info']); |
|
|
core.endGroup(); |
|
|
actionsToolkit.run( |
|
|
// main |
|
|
async () => { |
|
|
const input: context.Inputs = context.getInputs(); |
|
|
|
|
|
const image: string = core.getInput('image') || 'tonistiigi/binfmt:latest'; |
|
|
const platforms: string = core.getInput('platforms') || 'all'; |
|
|
await core.group(`Docker info`, async () => { |
|
|
await Docker.printVersion(); |
|
|
await Docker.printInfo(); |
|
|
}); |
|
|
|
|
|
core.startGroup(`Pulling binfmt Docker image`); |
|
|
await exec.exec('docker', ['pull', image]); |
|
|
core.endGroup(); |
|
|
await core.group(`Pulling binfmt Docker image`, async () => { |
|
|
await Exec.exec('docker', ['pull', input.image]); |
|
|
}); |
|
|
|
|
|
core.startGroup(`Image info`); |
|
|
await exec.exec('docker', ['image', 'inspect', image]); |
|
|
core.endGroup(); |
|
|
await core.group(`Image info`, async () => { |
|
|
await Exec.exec('docker', ['image', 'inspect', input.image]); |
|
|
}); |
|
|
|
|
|
core.startGroup(`Installing QEMU static binaries`); |
|
|
await exec.exec('docker', ['run', '--rm', '--privileged', image, '--install', platforms]); |
|
|
core.endGroup(); |
|
|
await core.group(`Installing QEMU static binaries`, async () => { |
|
|
await Exec.exec('docker', ['run', '--rm', '--privileged', input.image, '--install', input.platforms]); |
|
|
}); |
|
|
|
|
|
core.startGroup(`Extracting available platforms`); |
|
|
await mexec.exec(`docker`, ['run', '--rm', '--privileged', image], true).then(res => { |
|
|
if (res.stderr != '' && !res.success) { |
|
|
throw new Error(res.stderr); |
|
|
} |
|
|
const platforms: Platforms = JSON.parse(res.stdout.trim()); |
|
|
core.info(`${platforms.supported.join(',')}`); |
|
|
setOutput('platforms', platforms.supported.join(',')); |
|
|
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(',')); |
|
|
}); |
|
|
}); |
|
|
core.endGroup(); |
|
|
} catch (error) { |
|
|
core.setFailed(error.message); |
|
|
} |
|
|
} |
|
|
|
|
|
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777 |
|
|
function setOutput(name: string, value: any): void { |
|
|
issueCommand('set-output', {name}, value); |
|
|
} |
|
|
|
|
|
run(); |
|
|
); |