This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
/
main.ts
92 lines (80 loc) · 2.57 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import * as child_process from 'child_process';
import * as os from 'os';
import * as path from 'path';
import * as installer from './installer';
import * as stateHelper from './state-helper';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
async function run(): Promise<void> {
try {
if (os.platform() !== 'linux') {
core.setFailed('Only supported on linux platform');
return;
}
core.warning(
'This action is ARCHIVED and will not receive any updates, update your workflows to use the official Docker action docker/setup-buildx-action@v1'
);
const buildxVer: string = core.getInput('buildx-version') || 'latest';
const qemuVer: string = core.getInput('qemu-version') || 'latest';
const dockerConfigHome: string = process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker');
await installer.buildx(buildxVer, dockerConfigHome);
core.info('📣 Buildx info');
await exec.exec('docker', ['buildx', 'version']);
core.info(`⬇️ Downloading qemu-user-static Docker image...`);
await exec.exec('docker', ['pull', '-q', `multiarch/qemu-user-static:${qemuVer}`]);
core.info(`💎 Installing QEMU static binaries...`);
await exec.exec('docker', [
'run',
'--rm',
'--privileged',
`multiarch/qemu-user-static:${qemuVer}`,
'--reset',
'-p',
'yes',
'--credential',
'yes'
]);
core.info('🔨 Creating a new builder instance...');
await exec.exec('docker', [
'buildx',
'create',
'--name',
`builder-${process.env.GITHUB_SHA}`,
'--driver',
'docker-container',
'--use'
]);
core.info('🏃 Booting builder...');
await exec.exec('docker', ['buildx', 'inspect', '--bootstrap']);
core.info('🐳 Docker info');
await exec.exec('docker', ['info']);
core.info('🛒 Extracting available platforms...');
const inspect = child_process.execSync('docker buildx inspect', {
encoding: 'utf8'
});
for (const line of inspect.split(os.EOL)) {
if (line.startsWith('Platforms')) {
core.setOutput('platforms', line.replace('Platforms: ', '').replace(/\s/g, '').trim());
break;
}
}
} catch (error) {
core.setFailed(error.message);
}
}
async function cleanup(): Promise<void> {
try {
core.info('🚿 Removing builder instance...');
await exec.exec('docker', ['buildx', 'rm', `builder-${process.env.GITHUB_SHA}`]);
} catch (error) {
core.warning(error.message);
}
}
// Main
if (!stateHelper.IsPost) {
run();
}
// Post
else {
cleanup();
}