Skip to content

Commit 3529f9f

Browse files
authored
Merge pull request #162 from crazy-max/proxy-conf
display proxy configuration
2 parents 1b6be70 + 3a006c6 commit 3529f9f

6 files changed

Lines changed: 133 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,93 @@ jobs:
302302
set: |
303303
t1.tags=localhost:5000/name/app:t1
304304
t2.tags=localhost:5000/name/app:t2
305+
306+
docker-config-malformed:
307+
runs-on: ubuntu-latest
308+
steps:
309+
-
310+
name: Checkout
311+
uses: actions/checkout@v4
312+
-
313+
name: Set malformed docker config
314+
run: |
315+
mkdir -p ~/.docker
316+
echo 'foo_bar' >> ~/.docker/config.json
317+
-
318+
name: Build
319+
uses: ./
320+
with:
321+
files: |
322+
./test/config.hcl
323+
324+
proxy-docker-config:
325+
runs-on: ubuntu-latest
326+
services:
327+
squid-proxy:
328+
image: ubuntu/squid:latest
329+
ports:
330+
- 3128:3128
331+
steps:
332+
-
333+
name: Check proxy
334+
run: |
335+
netstat -aptn
336+
curl --retry 5 --retry-all-errors --retry-delay 0 --connect-timeout 5 --proxy http://127.0.0.1:3128 -v --insecure --head https://www.google.com
337+
-
338+
name: Checkout
339+
uses: actions/checkout@v4
340+
-
341+
name: Set proxy config
342+
run: |
343+
mkdir -p ~/.docker
344+
echo '{"proxies":{"default":{"httpProxy":"http://127.0.0.1:3128","httpsProxy":"http://127.0.0.1:3128"}}}' > ~/.docker/config.json
345+
-
346+
name: Set up Docker Buildx
347+
uses: docker/setup-buildx-action@v2
348+
with:
349+
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
350+
driver-opts: |
351+
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
352+
network=host
353+
buildkitd-flags: --debug
354+
-
355+
name: Build
356+
uses: ./
357+
with:
358+
files: |
359+
./test/config.hcl
360+
targets: app-proxy
361+
362+
proxy-buildkitd:
363+
runs-on: ubuntu-latest
364+
services:
365+
squid-proxy:
366+
image: ubuntu/squid:latest
367+
ports:
368+
- 3128:3128
369+
steps:
370+
-
371+
name: Check proxy
372+
run: |
373+
netstat -aptn
374+
curl --retry 5 --retry-all-errors --retry-delay 0 --connect-timeout 5 --proxy http://127.0.0.1:3128 -v --insecure --head https://www.google.com
375+
-
376+
name: Checkout
377+
uses: actions/checkout@v4
378+
-
379+
name: Set up Docker Buildx
380+
uses: docker/setup-buildx-action@v2
381+
with:
382+
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
383+
driver-opts: |
384+
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
385+
network=host
386+
env.http_proxy=http://127.0.0.1:3128
387+
env.https_proxy=http://127.0.0.1:3128
388+
buildkitd-flags: --debug
389+
-
390+
name: Build
391+
uses: ./
392+
with:
393+
files: |
394+
./test/config.hcl

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 27 additions & 0 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 core from '@actions/core';
34
import * as actionsToolkit from '@docker/actions-toolkit';
45
import {Inputs as BuildxInputs} from '@docker/actions-toolkit/lib/buildx/inputs';
@@ -7,6 +8,7 @@ import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
78
import {Exec} from '@docker/actions-toolkit/lib/exec';
89
import {GitHub} from '@docker/actions-toolkit/lib/github';
910
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
11+
import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker';
1012

1113
import * as context from './context';
1214
import * as stateHelper from './state-helper';
@@ -34,6 +36,31 @@ actionsToolkit.run(
3436
}
3537
});
3638

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) {
49+
for (const host in dockerConfig.proxies) {
50+
let prefix = '';
51+
if (Object.keys(dockerConfig.proxies).length > 1) {
52+
prefix = ' ';
53+
core.info(host);
54+
}
55+
for (const key in dockerConfig.proxies[host]) {
56+
core.info(`${prefix}${key}: ${dockerConfig.proxies[host][key]}`);
57+
}
58+
}
59+
} else if (!dockerConfigMalformed) {
60+
core.info('No proxy configuration found');
61+
}
62+
});
63+
3764
if (!(await toolkit.buildx.isAvailable())) {
3865
core.setFailed(`Docker buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`);
3966
return;

test/config.hcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ target "app-plus" {
3737
IAMPLUS = "true"
3838
}
3939
}
40+
41+
target "app-proxy" {
42+
inherits = ["app"]
43+
dockerfile = "proxy.Dockerfile"
44+
}

test/proxy.Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# syntax=docker/dockerfile:1
2+
FROM alpine
3+
RUN apk add --no-cache curl net-tools
4+
ARG HTTP_PROXY
5+
ARG HTTPS_PROXY
6+
RUN printenv HTTP_PROXY
7+
RUN printenv HTTPS_PROXY
8+
RUN netstat -aptn
9+
RUN curl --retry 5 --retry-all-errors --retry-delay 0 --connect-timeout 5 --proxy $HTTP_PROXY -v --insecure --head https://www.google.com

0 commit comments

Comments
 (0)