2020-08-16 06:36:41 +08:00
|
|
|
import * as os from 'os';
|
|
|
|
import * as buildx from './buildx';
|
2020-08-16 23:18:08 +08:00
|
|
|
import {Inputs, getInputs, getArgs} from './context';
|
2020-08-16 06:36:41 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-08-16 11:53:50 +08:00
|
|
|
if (!(await buildx.isAvailable())) {
|
|
|
|
core.setFailed(`Buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`);
|
|
|
|
return;
|
2020-08-16 06:36:41 +08:00
|
|
|
}
|
|
|
|
|
2020-08-17 04:31:37 +08:00
|
|
|
let inputs: Inputs = await getInputs();
|
2020-08-16 11:53:50 +08:00
|
|
|
if (inputs.builder) {
|
|
|
|
core.info(`📌 Using builder instance ${inputs.builder}`);
|
|
|
|
await buildx.use(inputs.builder);
|
|
|
|
}
|
2020-08-17 04:31:37 +08:00
|
|
|
|
2020-08-16 06:36:41 +08:00
|
|
|
core.info(`🏃 Starting build...`);
|
2020-08-17 04:41:18 +08:00
|
|
|
const args: string[] = await getArgs(inputs);
|
2020-08-16 23:24:31 +08:00
|
|
|
await exec.exec('docker', args);
|
2020-08-18 04:18:15 +08:00
|
|
|
|
|
|
|
const imageID = await buildx.getImageID();
|
|
|
|
if (imageID) {
|
|
|
|
core.info('🛒 Extracting digest...');
|
|
|
|
core.info(`${imageID}`);
|
|
|
|
core.setOutput('digest', imageID);
|
|
|
|
}
|
2020-08-16 06:36:41 +08:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-18 00:35:15 +08:00
|
|
|
run();
|