2020-08-17 16:18:15 -04:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
import * as context from './context';
|
2020-08-15 18:36:41 -04:00
|
|
|
import * as exec from './exec';
|
|
|
|
|
2020-08-17 16:18:15 -04:00
|
|
|
export async function getImageIDFile(): Promise<string> {
|
|
|
|
return path.join(context.tmpDir, 'iidfile');
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getImageID(): Promise<string | undefined> {
|
|
|
|
const iidFile = await getImageIDFile();
|
|
|
|
if (!fs.existsSync(iidFile)) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return fs.readFileSync(iidFile, {encoding: 'utf-8'});
|
|
|
|
}
|
|
|
|
|
2020-08-15 18:36:41 -04:00
|
|
|
export async function isAvailable(): Promise<Boolean> {
|
|
|
|
return await exec.exec(`docker`, ['buildx'], true).then(res => {
|
|
|
|
if (res.stderr != '' && !res.success) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return res.success;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function use(builder: string): Promise<void> {
|
|
|
|
return await exec.exec(`docker`, ['buildx', 'use', '--builder', builder], false).then(res => {
|
|
|
|
if (res.stderr != '' && !res.success) {
|
|
|
|
throw new Error(res.stderr);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|