mirror of
https://github.com/docker/build-push-action.git
synced 2024-11-06 08:45:46 -05:00
Merge pull request #195 from crazy-max/docker-driver
Throw error message instead of exit code
This commit is contained in:
commit
99ba0e6cbf
6 changed files with 76 additions and 15 deletions
58
.github/workflows/ci.yml
vendored
58
.github/workflows/ci.yml
vendored
|
@ -197,6 +197,64 @@ jobs:
|
||||||
if: always()
|
if: always()
|
||||||
uses: crazy-max/ghaction-dump-context@v1
|
uses: crazy-max/ghaction-dump-context@v1
|
||||||
|
|
||||||
|
error:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v2.3.3
|
||||||
|
-
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v1
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
-
|
||||||
|
name: Build
|
||||||
|
continue-on-error: true
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
context: ./test
|
||||||
|
file: ./test/Dockerfile
|
||||||
|
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x
|
||||||
|
push: true
|
||||||
|
tags: localhost:5000/name/app:latest
|
||||||
|
-
|
||||||
|
name: Dump context
|
||||||
|
if: always()
|
||||||
|
uses: crazy-max/ghaction-dump-context@v1
|
||||||
|
|
||||||
|
docker-driver:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
push:
|
||||||
|
- true
|
||||||
|
- false
|
||||||
|
services:
|
||||||
|
registry:
|
||||||
|
image: registry:2
|
||||||
|
ports:
|
||||||
|
- 5000:5000
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v2.3.3
|
||||||
|
-
|
||||||
|
name: Build
|
||||||
|
continue-on-error: ${{ matrix.push }}
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
context: ./test
|
||||||
|
file: ./test/Dockerfile
|
||||||
|
push: ${{ matrix.push }}
|
||||||
|
tags: localhost:5000/name/app:latest
|
||||||
|
-
|
||||||
|
name: Dump context
|
||||||
|
if: always()
|
||||||
|
uses: crazy-max/ghaction-dump-context@v1
|
||||||
|
|
||||||
multi:
|
multi:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
|
|
|
@ -92,7 +92,6 @@ describe('isLocalOrTarExporter', () => {
|
||||||
|
|
||||||
describe('getVersion', () => {
|
describe('getVersion', () => {
|
||||||
it('valid', async () => {
|
it('valid', async () => {
|
||||||
await exec.exec('docker', ['buildx', 'version']);
|
|
||||||
const version = await buildx.getVersion();
|
const version = await buildx.getVersion();
|
||||||
console.log(`version: ${version}`);
|
console.log(`version: ${version}`);
|
||||||
expect(semver.valid(version)).not.toBeNull();
|
expect(semver.valid(version)).not.toBeNull();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as context from '../src/context';
|
|
||||||
import * as buildx from '../src/buildx';
|
import * as buildx from '../src/buildx';
|
||||||
|
import * as context from '../src/context';
|
||||||
|
|
||||||
jest.spyOn(context, 'defaultContext').mockImplementation((): string => {
|
jest.spyOn(context, 'defaultContext').mockImplementation((): string => {
|
||||||
return 'https://github.com/docker/build-push-action.git#test-jest';
|
return 'https://github.com/docker/build-push-action.git#test-jest';
|
||||||
|
|
14
dist/index.js
generated
vendored
14
dist/index.js
generated
vendored
|
@ -2377,19 +2377,17 @@ const fs = __importStar(__webpack_require__(747));
|
||||||
const os = __importStar(__webpack_require__(87));
|
const os = __importStar(__webpack_require__(87));
|
||||||
const buildx = __importStar(__webpack_require__(295));
|
const buildx = __importStar(__webpack_require__(295));
|
||||||
const context = __importStar(__webpack_require__(842));
|
const context = __importStar(__webpack_require__(842));
|
||||||
|
const exec = __importStar(__webpack_require__(757));
|
||||||
const stateHelper = __importStar(__webpack_require__(647));
|
const stateHelper = __importStar(__webpack_require__(647));
|
||||||
const core = __importStar(__webpack_require__(186));
|
const core = __importStar(__webpack_require__(186));
|
||||||
const exec = __importStar(__webpack_require__(514));
|
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
if (os.platform() !== 'linux') {
|
if (os.platform() !== 'linux') {
|
||||||
core.setFailed('Only supported on linux platform');
|
throw new Error(`Only supported on linux platform`);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!(yield buildx.isAvailable())) {
|
if (!(yield buildx.isAvailable())) {
|
||||||
core.setFailed(`Buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`);
|
throw new Error(`Buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
stateHelper.setTmpDir(context.tmpDir());
|
stateHelper.setTmpDir(context.tmpDir());
|
||||||
const buildxVersion = yield buildx.getVersion();
|
const buildxVersion = yield buildx.getVersion();
|
||||||
|
@ -2398,7 +2396,11 @@ function run() {
|
||||||
let inputs = yield context.getInputs(defContext);
|
let inputs = yield context.getInputs(defContext);
|
||||||
core.info(`🏃 Starting build...`);
|
core.info(`🏃 Starting build...`);
|
||||||
const args = yield context.getArgs(inputs, defContext, buildxVersion);
|
const args = yield context.getArgs(inputs, defContext, buildxVersion);
|
||||||
yield exec.exec('docker', args);
|
yield exec.exec('docker', args).then(res => {
|
||||||
|
if (res.stderr != '' && !res.success) {
|
||||||
|
throw new Error(`buildx call failed with: ${res.stderr.match(/(.*)\s*$/)[0]}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
const imageID = yield buildx.getImageID();
|
const imageID = yield buildx.getImageID();
|
||||||
if (imageID) {
|
if (imageID) {
|
||||||
core.info('🛒 Extracting digest...');
|
core.info('🛒 Extracting digest...');
|
||||||
|
|
|
@ -7,7 +7,7 @@ export interface ExecResult {
|
||||||
stderr: string;
|
stderr: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const exec = async (command: string, args: string[] = [], silent: boolean): Promise<ExecResult> => {
|
export const exec = async (command: string, args: string[] = [], silent?: boolean): Promise<ExecResult> => {
|
||||||
let stdout: string = '';
|
let stdout: string = '';
|
||||||
let stderr: string = '';
|
let stderr: string = '';
|
||||||
|
|
||||||
|
|
14
src/main.ts
14
src/main.ts
|
@ -2,20 +2,18 @@ import * as fs from 'fs';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as buildx from './buildx';
|
import * as buildx from './buildx';
|
||||||
import * as context from './context';
|
import * as context from './context';
|
||||||
|
import * as exec from './exec';
|
||||||
import * as stateHelper from './state-helper';
|
import * as stateHelper from './state-helper';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (os.platform() !== 'linux') {
|
if (os.platform() !== 'linux') {
|
||||||
core.setFailed('Only supported on linux platform');
|
throw new Error(`Only supported on linux platform`);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(await buildx.isAvailable())) {
|
if (!(await buildx.isAvailable())) {
|
||||||
core.setFailed(`Buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`);
|
throw new Error(`Buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
stateHelper.setTmpDir(context.tmpDir());
|
stateHelper.setTmpDir(context.tmpDir());
|
||||||
|
|
||||||
|
@ -27,7 +25,11 @@ async function run(): Promise<void> {
|
||||||
|
|
||||||
core.info(`🏃 Starting build...`);
|
core.info(`🏃 Starting build...`);
|
||||||
const args: string[] = await context.getArgs(inputs, defContext, buildxVersion);
|
const args: string[] = await context.getArgs(inputs, defContext, buildxVersion);
|
||||||
await exec.exec('docker', args);
|
await exec.exec('docker', args).then(res => {
|
||||||
|
if (res.stderr != '' && !res.success) {
|
||||||
|
throw new Error(`buildx call failed with: ${res.stderr.match(/(.*)\s*$/)![0]}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const imageID = await buildx.getImageID();
|
const imageID = await buildx.getImageID();
|
||||||
if (imageID) {
|
if (imageID) {
|
||||||
|
|
Loading…
Reference in a new issue