Skip to content

Commit

Permalink
Handle push without buildx
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
CrazyMax committed Aug 15, 2020
1 parent f0ffce7 commit ea0c8ed
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 46 deletions.
63 changes: 40 additions & 23 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 44 additions & 23 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ 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');
} else {
buildArgs.push('build');
}

// Global options
if (inputs.file) {
buildArgs.push('--file', inputs.file);
}
Expand All @@ -46,32 +49,50 @@ async function run(): Promise<void> {
if (inputs.noCache) {
buildArgs.push('--no-cache');
}
if (inputs.builder) {
core.info(`📌 Using build 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');

// Buildx options
if (buildxEnabled) {
if (inputs.builder) {
core.info(`📌 Using build 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);
});
}
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 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);
}
Expand Down

0 comments on commit ea0c8ed

Please sign in to comment.