warn if docker config can't be parsed

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
pull/957/head
CrazyMax 2023-09-08 15:28:08 +02:00
parent 4e4ee680f6
commit f46044b799
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
2 changed files with 33 additions and 5 deletions

View File

@ -1013,6 +1013,23 @@ jobs:
build-contexts: | build-contexts: |
alpine=docker-image://localhost:5000/my-base-image:latest alpine=docker-image://localhost:5000/my-base-image:latest
docker-config-malformed:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set malformed docker config
run: |
mkdir -p ~/.docker
echo 'foo_bar' >> ~/.docker/config.json
-
name: Build
uses: ./
with:
context: ./test
proxy-docker-config: proxy-docker-config:
runs-on: ubuntu-latest runs-on: ubuntu-latest
services: services:

View File

@ -1,4 +1,5 @@
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path';
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 actionsToolkit from '@docker/actions-toolkit'; import * as actionsToolkit from '@docker/actions-toolkit';
@ -8,6 +9,7 @@ import {Exec} from '@docker/actions-toolkit/lib/exec';
import {GitHub} from '@docker/actions-toolkit/lib/github'; import {GitHub} from '@docker/actions-toolkit/lib/github';
import {Inputs as BuildxInputs} from '@docker/actions-toolkit/lib/buildx/inputs'; import {Inputs as BuildxInputs} from '@docker/actions-toolkit/lib/buildx/inputs';
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit'; import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker';
import * as context from './context'; import * as context from './context';
@ -34,9 +36,16 @@ actionsToolkit.run(
} }
}); });
const dockerConfig = await Docker.configFile(); await core.group(`Proxy configuration`, async () => {
let dockerConfig: ConfigFile | undefined;
let dockerConfigMalformed = false;
try {
dockerConfig = await Docker.configFile();
} catch (e) {
dockerConfigMalformed = true;
core.warning(`Unable to parse config file ${path.join(Docker.configDir, 'config.json')}: ${e}`);
}
if (dockerConfig && dockerConfig.proxies) { if (dockerConfig && dockerConfig.proxies) {
await core.group(`Proxy configuration found`, async () => {
for (const host in dockerConfig.proxies) { for (const host in dockerConfig.proxies) {
let prefix = ''; let prefix = '';
if (dockerConfig.proxies.length > 1) { if (dockerConfig.proxies.length > 1) {
@ -47,8 +56,10 @@ actionsToolkit.run(
core.info(`${prefix}${key}: ${dockerConfig.proxies[host][key]}`); core.info(`${prefix}${key}: ${dockerConfig.proxies[host][key]}`);
} }
} }
}); } else if (!dockerConfigMalformed) {
core.info('No proxy configuration found');
} }
});
if (!(await toolkit.buildx.isAvailable())) { if (!(await toolkit.buildx.isAvailable())) {
core.setFailed(`Docker buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`); core.setFailed(`Docker buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`);