Skip to content

Commit f46044b

Browse files
committed
warn if docker config can't be parsed
Signed-off-by: CrazyMax <[email protected]>
1 parent 4e4ee68 commit f46044b

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,23 @@ jobs:
10131013
build-contexts: |
10141014
alpine=docker-image://localhost:5000/my-base-image:latest
10151015
1016+
docker-config-malformed:
1017+
runs-on: ubuntu-latest
1018+
steps:
1019+
-
1020+
name: Checkout
1021+
uses: actions/checkout@v4
1022+
-
1023+
name: Set malformed docker config
1024+
run: |
1025+
mkdir -p ~/.docker
1026+
echo 'foo_bar' >> ~/.docker/config.json
1027+
-
1028+
name: Build
1029+
uses: ./
1030+
with:
1031+
context: ./test
1032+
10161033
proxy-docker-config:
10171034
runs-on: ubuntu-latest
10181035
services:

src/main.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from 'fs';
2+
import * as path from 'path';
23
import * as stateHelper from './state-helper';
34
import * as core from '@actions/core';
45
import * as actionsToolkit from '@docker/actions-toolkit';
@@ -8,6 +9,7 @@ import {Exec} from '@docker/actions-toolkit/lib/exec';
89
import {GitHub} from '@docker/actions-toolkit/lib/github';
910
import {Inputs as BuildxInputs} from '@docker/actions-toolkit/lib/buildx/inputs';
1011
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
12+
import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker';
1113

1214
import * as context from './context';
1315

@@ -34,9 +36,16 @@ actionsToolkit.run(
3436
}
3537
});
3638

37-
const dockerConfig = await Docker.configFile();
38-
if (dockerConfig && dockerConfig.proxies) {
39-
await core.group(`Proxy configuration found`, async () => {
39+
await core.group(`Proxy configuration`, async () => {
40+
let dockerConfig: ConfigFile | undefined;
41+
let dockerConfigMalformed = false;
42+
try {
43+
dockerConfig = await Docker.configFile();
44+
} catch (e) {
45+
dockerConfigMalformed = true;
46+
core.warning(`Unable to parse config file ${path.join(Docker.configDir, 'config.json')}: ${e}`);
47+
}
48+
if (dockerConfig && dockerConfig.proxies) {
4049
for (const host in dockerConfig.proxies) {
4150
let prefix = '';
4251
if (dockerConfig.proxies.length > 1) {
@@ -47,8 +56,10 @@ actionsToolkit.run(
4756
core.info(`${prefix}${key}: ${dockerConfig.proxies[host][key]}`);
4857
}
4958
}
50-
});
51-
}
59+
} else if (!dockerConfigMalformed) {
60+
core.info('No proxy configuration found');
61+
}
62+
});
5263

5364
if (!(await toolkit.buildx.isAvailable())) {
5465
core.setFailed(`Docker buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`);

0 commit comments

Comments
 (0)