Skip to content

Commit

Permalink
Merge pull request #957 from crazy-max/warn-docker-config
Browse files Browse the repository at this point in the history
warn if docker config can't be parsed
  • Loading branch information
crazy-max authored Sep 8, 2023
2 parents 4e4ee68 + ec39ef3 commit 0a97817
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,23 @@ jobs:
build-contexts: |
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:
runs-on: ubuntu-latest
services:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from 'fs';
import * as path from 'path';
import * as stateHelper from './state-helper';
import * as core from '@actions/core';
import * as actionsToolkit from '@docker/actions-toolkit';
Expand All @@ -8,6 +9,7 @@ import {Exec} from '@docker/actions-toolkit/lib/exec';
import {GitHub} from '@docker/actions-toolkit/lib/github';
import {Inputs as BuildxInputs} from '@docker/actions-toolkit/lib/buildx/inputs';
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker';

import * as context from './context';

Expand All @@ -34,9 +36,16 @@ actionsToolkit.run(
}
});

const dockerConfig = await Docker.configFile();
if (dockerConfig && dockerConfig.proxies) {
await core.group(`Proxy configuration found`, async () => {
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) {
for (const host in dockerConfig.proxies) {
let prefix = '';
if (dockerConfig.proxies.length > 1) {
Expand All @@ -47,8 +56,10 @@ actionsToolkit.run(
core.info(`${prefix}${key}: ${dockerConfig.proxies[host][key]}`);
}
}
});
}
} else if (!dockerConfigMalformed) {
core.info('No proxy configuration found');
}
});

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

0 comments on commit 0a97817

Please sign in to comment.