2020-09-02 04:07:11 -04:00
|
|
|
import * as fs from 'fs';
|
2020-08-15 18:36:41 -04:00
|
|
|
import * as os from 'os';
|
|
|
|
import * as buildx from './buildx';
|
2020-09-02 04:07:11 -04:00
|
|
|
import * as context from './context';
|
|
|
|
import * as stateHelper from './state-helper';
|
2020-08-15 18:36:41 -04: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-15 23:53:50 -04: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-15 18:36:41 -04:00
|
|
|
}
|
2020-09-02 04:07:11 -04:00
|
|
|
stateHelper.setTmpDir(context.tmpDir);
|
2020-08-15 18:36:41 -04:00
|
|
|
|
2020-08-22 21:31:38 -04:00
|
|
|
const buildxVersion = await buildx.getVersion();
|
|
|
|
core.info(`📣 Buildx version: ${buildxVersion}`);
|
|
|
|
|
2020-09-02 04:07:11 -04:00
|
|
|
let inputs: context.Inputs = await context.getInputs();
|
2020-08-16 16:31:37 -04:00
|
|
|
|
2020-08-15 18:36:41 -04:00
|
|
|
core.info(`🏃 Starting build...`);
|
2020-09-02 04:07:11 -04:00
|
|
|
const args: string[] = await context.getArgs(inputs, buildxVersion);
|
2020-08-16 11:24:31 -04:00
|
|
|
await exec.exec('docker', args);
|
2020-08-17 16:18:15 -04:00
|
|
|
|
|
|
|
const imageID = await buildx.getImageID();
|
|
|
|
if (imageID) {
|
|
|
|
core.info('🛒 Extracting digest...');
|
|
|
|
core.info(`${imageID}`);
|
|
|
|
core.setOutput('digest', imageID);
|
|
|
|
}
|
2020-08-15 18:36:41 -04:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-02 04:07:11 -04:00
|
|
|
async function cleanup(): Promise<void> {
|
|
|
|
if (stateHelper.tmpDir.length > 0) {
|
|
|
|
core.info(`🚿 Removing temp folder ${stateHelper.tmpDir}`);
|
|
|
|
fs.rmdirSync(stateHelper.tmpDir, {recursive: true});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stateHelper.IsPost) {
|
|
|
|
run();
|
|
|
|
} else {
|
|
|
|
cleanup();
|
|
|
|
}
|