Permalink
Cannot retrieve contributors at this time
44 lines (37 sloc)
1.3 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
docker-qemu-action/src/main.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as os from 'os'; | |
import * as mexec from './exec'; | |
import * as core from '@actions/core'; | |
import * as exec from '@actions/exec'; | |
interface Platforms { | |
supported: string[]; | |
available: string[]; | |
} | |
async function run(): Promise<void> { | |
try { | |
if (os.platform() !== 'linux') { | |
core.setFailed('Only supported on linux platform'); | |
return; | |
} | |
const image: string = core.getInput('image') || 'tonistiigi/binfmt:latest'; | |
const platforms: string = core.getInput('platforms') || 'all'; | |
core.startGroup(`Pulling binfmt Docker image`); | |
await exec.exec('docker', ['pull', image]); | |
core.endGroup(); | |
core.startGroup(`Installing QEMU static binaries`); | |
await exec.exec('docker', ['run', '--rm', '--privileged', image, '--install', platforms]); | |
core.endGroup(); | |
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(',')}`); | |
core.setOutput('platforms', platforms.supported.join(',')); | |
}); | |
core.endGroup(); | |
} catch (error) { | |
core.setFailed(error.message); | |
} | |
} | |
run(); |