mirror of
https://github.com/docker/build-push-action.git
synced 2025-04-19 01:46:45 +00:00
Remove builder v1 support
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
585c2ae3b7
commit
78a1e0d9a3
8 changed files with 70 additions and 344 deletions
|
@ -1,4 +1,3 @@
|
|||
import * as docker from './docker';
|
||||
import * as exec from './exec';
|
||||
|
||||
export async function isAvailable(): Promise<Boolean> {
|
||||
|
@ -10,11 +9,6 @@ export async function isAvailable(): Promise<Boolean> {
|
|||
});
|
||||
}
|
||||
|
||||
export async function isInstalled(): Promise<Boolean> {
|
||||
const dockerCfg = await docker.config();
|
||||
return dockerCfg?.aliases?.builder == 'buildx';
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -38,17 +38,6 @@ export async function loadInputs(): Promise<Inputs> {
|
|||
};
|
||||
}
|
||||
|
||||
export async function mustBuildx(inputs: Inputs): Promise<boolean> {
|
||||
return (
|
||||
inputs.builder.length > 0 ||
|
||||
inputs.platforms.length > 0 ||
|
||||
inputs.load ||
|
||||
inputs.outputs.length > 0 ||
|
||||
inputs.cacheFrom.length > 0 ||
|
||||
inputs.cacheTo.length > 0
|
||||
);
|
||||
}
|
||||
|
||||
async function getInputList(name: string): Promise<string[]> {
|
||||
const items = core.getInput(name);
|
||||
if (items == '') {
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
import path from 'path';
|
||||
import os from 'os';
|
||||
import fs from 'fs';
|
||||
|
||||
export interface Config {
|
||||
credsStore?: string;
|
||||
experimental?: string;
|
||||
stackOrchestrator?: string;
|
||||
aliases?: {
|
||||
builder?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface Image {
|
||||
registry?: string;
|
||||
namespace?: string;
|
||||
repository: string;
|
||||
tag?: string;
|
||||
}
|
||||
|
||||
export async function config(): Promise<Config | undefined> {
|
||||
const dockerHome: string = process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker');
|
||||
|
||||
const file: string = path.join(dockerHome, 'config.json');
|
||||
if (!fs.existsSync(file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return JSON.parse(fs.readFileSync(file, {encoding: 'utf-8'})) as Config;
|
||||
}
|
||||
|
||||
export const parseImage = async (image: string): Promise<Image | undefined> => {
|
||||
const match = image.match(/^(?:([^\/]+)\/)?(?:([^\/]+)\/)?([^@:\/]+)(?:[@:](.+))?$/);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
|
||||
let res: Image = {
|
||||
registry: match[1],
|
||||
namespace: match[2],
|
||||
repository: match[3],
|
||||
tag: match[4]
|
||||
};
|
||||
|
||||
if (!res.namespace && res.registry && !/[:.]/.test(res.registry)) {
|
||||
res.namespace = res.registry;
|
||||
res.registry = undefined;
|
||||
}
|
||||
|
||||
res.registry = res.registry ? `${res.registry}/` : '';
|
||||
res.namespace = res.namespace && res.namespace !== 'library' ? `${res.namespace}/` : '';
|
||||
res.tag = res.tag && res.tag !== 'latest' ? `:${res.tag}` : '';
|
||||
return res;
|
||||
};
|
87
src/main.ts
87
src/main.ts
|
@ -1,7 +1,6 @@
|
|||
import * as os from 'os';
|
||||
import * as buildx from './buildx';
|
||||
import {Inputs, loadInputs, mustBuildx} from './context-helper';
|
||||
import {Image, parseImage} from './docker';
|
||||
import {Inputs, loadInputs} from './context-helper';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
|
@ -13,24 +12,18 @@ async function run(): Promise<void> {
|
|||
}
|
||||
|
||||
const inputs: Inputs = await loadInputs();
|
||||
const buildxAvailable = await buildx.isAvailable();
|
||||
const buildxInstalled = buildxAvailable && (await buildx.isInstalled());
|
||||
const buildxEnabled = (await mustBuildx(inputs)) || buildxInstalled;
|
||||
let buildArgs: Array<string> = [];
|
||||
|
||||
// Check buildx
|
||||
if (buildxEnabled) {
|
||||
if (!buildxAvailable) {
|
||||
core.setFailed(`Buildx is required but not available`);
|
||||
return;
|
||||
}
|
||||
core.info(`🚀 Buildx will be used to build your image`);
|
||||
buildArgs.push('buildx', 'build');
|
||||
} else {
|
||||
buildArgs.push('build');
|
||||
if (!(await buildx.isAvailable())) {
|
||||
core.setFailed(`Buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Global options
|
||||
let buildArgs: Array<string> = ['buildx', 'build'];
|
||||
|
||||
if (inputs.builder) {
|
||||
core.info(`📌 Using builder instance ${inputs.builder}`);
|
||||
await buildx.use(inputs.builder);
|
||||
}
|
||||
if (inputs.file) {
|
||||
buildArgs.push('--file', inputs.file);
|
||||
}
|
||||
|
@ -52,54 +45,28 @@ async function run(): Promise<void> {
|
|||
if (inputs.noCache) {
|
||||
buildArgs.push('--no-cache');
|
||||
}
|
||||
|
||||
// Buildx options
|
||||
if (buildxEnabled) {
|
||||
if (inputs.builder) {
|
||||
core.info(`📌 Using builder instance ${inputs.builder}`);
|
||||
await buildx.use(inputs.builder);
|
||||
}
|
||||
if (inputs.platforms) {
|
||||
buildArgs.push('--platform', inputs.platforms);
|
||||
}
|
||||
if (inputs.load) {
|
||||
buildArgs.push('--load');
|
||||
}
|
||||
if (inputs.push) {
|
||||
buildArgs.push('--push');
|
||||
}
|
||||
await asyncForEach(inputs.outputs, async output => {
|
||||
buildArgs.push('--output', output);
|
||||
});
|
||||
await asyncForEach(inputs.cacheFrom, async cacheFrom => {
|
||||
buildArgs.push('--cache-from', cacheFrom);
|
||||
});
|
||||
await asyncForEach(inputs.cacheTo, async cacheTo => {
|
||||
buildArgs.push('--cache-from', cacheTo);
|
||||
});
|
||||
if (inputs.platforms) {
|
||||
buildArgs.push('--platform', inputs.platforms);
|
||||
}
|
||||
|
||||
if (inputs.load) {
|
||||
buildArgs.push('--load');
|
||||
}
|
||||
if (inputs.push) {
|
||||
buildArgs.push('--push');
|
||||
}
|
||||
await asyncForEach(inputs.outputs, async output => {
|
||||
buildArgs.push('--output', output);
|
||||
});
|
||||
await asyncForEach(inputs.cacheFrom, async cacheFrom => {
|
||||
buildArgs.push('--cache-from', cacheFrom);
|
||||
});
|
||||
await asyncForEach(inputs.cacheTo, async cacheTo => {
|
||||
buildArgs.push('--cache-from', cacheTo);
|
||||
});
|
||||
buildArgs.push(inputs.context);
|
||||
|
||||
core.info(`🏃 Starting build...`);
|
||||
await exec.exec('docker', buildArgs);
|
||||
|
||||
if (!buildxEnabled && inputs.push) {
|
||||
let pushRepos: Array<string> = [];
|
||||
await asyncForEach(inputs.tags, async tag => {
|
||||
const img: Image | undefined = await parseImage(tag);
|
||||
if (!img) {
|
||||
core.warning(`Cannot parse image reference ${tag}`);
|
||||
return;
|
||||
}
|
||||
const repo: string = `${img.registry}${img.namespace}${img.repository}`;
|
||||
if (!pushRepos.includes(repo)) {
|
||||
pushRepos.push(repo);
|
||||
core.info(`⬆️ Pushing ${repo}...`);
|
||||
await exec.exec('docker', ['push', repo]);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue