mirror of
https://gitea.com/docker/build-push-action.git
synced 2024-11-22 09:29:38 +01:00
Handle push without buildx
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
f0ffce7351
commit
ea0c8ed90e
2 changed files with 84 additions and 46 deletions
21
dist/index.js
generated
vendored
21
dist/index.js
generated
vendored
|
@ -1015,10 +1015,12 @@ function run() {
|
|||
}
|
||||
const inputs = yield context_helper_1.loadInputs();
|
||||
let buildArgs = [];
|
||||
const buildxEnabled = yield context_helper_1.mustBuildx(inputs);
|
||||
// Check buildx
|
||||
if (yield context_helper_1.mustBuildx(inputs)) {
|
||||
if (buildxEnabled) {
|
||||
if (yield !buildx.isAvailable()) {
|
||||
throw new Error(`Buildx is required but not available`);
|
||||
core.setFailed(`Buildx is required but not available`);
|
||||
return;
|
||||
}
|
||||
core.info(`🚀 Buildx will be used to build your image`);
|
||||
buildArgs.push('buildx', 'build');
|
||||
|
@ -1026,6 +1028,7 @@ function run() {
|
|||
else {
|
||||
buildArgs.push('build');
|
||||
}
|
||||
// Global options
|
||||
if (inputs.file) {
|
||||
buildArgs.push('--file', inputs.file);
|
||||
}
|
||||
|
@ -1047,6 +1050,8 @@ function run() {
|
|||
if (inputs.noCache) {
|
||||
buildArgs.push('--no-cache');
|
||||
}
|
||||
// Buildx options
|
||||
if (buildxEnabled) {
|
||||
if (inputs.builder) {
|
||||
core.info(`📌 Using build instance ${inputs.builder}`);
|
||||
yield buildx.use(inputs.builder);
|
||||
|
@ -1069,9 +1074,21 @@ function run() {
|
|||
yield asyncForEach(inputs.cacheTo, (cacheTo) => __awaiter(this, void 0, void 0, function* () {
|
||||
buildArgs.push('--cache-from', cacheTo);
|
||||
}));
|
||||
}
|
||||
buildArgs.push(inputs.context);
|
||||
core.info(`🏃 Starting build...`);
|
||||
yield exec.exec('docker', buildArgs);
|
||||
if (!buildxEnabled && inputs.push) {
|
||||
let pushRepos = [];
|
||||
yield asyncForEach(inputs.tags, (tag) => __awaiter(this, void 0, void 0, function* () {
|
||||
const repo = tag.split(':', -1)[0];
|
||||
if (!pushRepos.includes(repo)) {
|
||||
pushRepos.push(repo);
|
||||
core.info(`⬆️ Pushing ${repo}...`);
|
||||
yield exec.exec('docker', ['push', repo]);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
|
|
25
src/main.ts
25
src/main.ts
|
@ -13,11 +13,13 @@ async function run(): Promise<void> {
|
|||
|
||||
const inputs: Inputs = await loadInputs();
|
||||
let buildArgs: Array<string> = [];
|
||||
const buildxEnabled = await mustBuildx(inputs);
|
||||
|
||||
// Check buildx
|
||||
if (await mustBuildx(inputs)) {
|
||||
if (buildxEnabled) {
|
||||
if (await !buildx.isAvailable()) {
|
||||
throw new Error(`Buildx is required but not available`);
|
||||
core.setFailed(`Buildx is required but not available`);
|
||||
return;
|
||||
}
|
||||
core.info(`🚀 Buildx will be used to build your image`);
|
||||
buildArgs.push('buildx', 'build');
|
||||
|
@ -25,6 +27,7 @@ async function run(): Promise<void> {
|
|||
buildArgs.push('build');
|
||||
}
|
||||
|
||||
// Global options
|
||||
if (inputs.file) {
|
||||
buildArgs.push('--file', inputs.file);
|
||||
}
|
||||
|
@ -46,6 +49,9 @@ async function run(): Promise<void> {
|
|||
if (inputs.noCache) {
|
||||
buildArgs.push('--no-cache');
|
||||
}
|
||||
|
||||
// Buildx options
|
||||
if (buildxEnabled) {
|
||||
if (inputs.builder) {
|
||||
core.info(`📌 Using build instance ${inputs.builder}`);
|
||||
await buildx.use(inputs.builder);
|
||||
|
@ -68,10 +74,25 @@ async function run(): Promise<void> {
|
|||
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 repo = tag.split(':', -1)[0];
|
||||
if (!pushRepos.includes(repo)) {
|
||||
pushRepos.push(repo);
|
||||
|
||||
core.info(`⬆️ Pushing ${repo}...`);
|
||||
await exec.exec('docker', ['push', repo]);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue