mirror of
https://github.com/docker/bake-action.git
synced 2026-01-22 12:22:21 +01:00
Merge pull request #162 from crazy-max/proxy-conf
display proxy configuration
This commit is contained in:
90
.github/workflows/ci.yml
vendored
90
.github/workflows/ci.yml
vendored
@@ -302,3 +302,93 @@ jobs:
|
|||||||
set: |
|
set: |
|
||||||
t1.tags=localhost:5000/name/app:t1
|
t1.tags=localhost:5000/name/app:t1
|
||||||
t2.tags=localhost:5000/name/app:t2
|
t2.tags=localhost:5000/name/app:t2
|
||||||
|
|
||||||
|
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:
|
||||||
|
files: |
|
||||||
|
./test/config.hcl
|
||||||
|
|
||||||
|
proxy-docker-config:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
services:
|
||||||
|
squid-proxy:
|
||||||
|
image: ubuntu/squid:latest
|
||||||
|
ports:
|
||||||
|
- 3128:3128
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Check proxy
|
||||||
|
run: |
|
||||||
|
netstat -aptn
|
||||||
|
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
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Set proxy config
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.docker
|
||||||
|
echo '{"proxies":{"default":{"httpProxy":"http://127.0.0.1:3128","httpsProxy":"http://127.0.0.1:3128"}}}' > ~/.docker/config.json
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
with:
|
||||||
|
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
|
||||||
|
driver-opts: |
|
||||||
|
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
|
||||||
|
network=host
|
||||||
|
buildkitd-flags: --debug
|
||||||
|
-
|
||||||
|
name: Build
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
./test/config.hcl
|
||||||
|
targets: app-proxy
|
||||||
|
|
||||||
|
proxy-buildkitd:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
services:
|
||||||
|
squid-proxy:
|
||||||
|
image: ubuntu/squid:latest
|
||||||
|
ports:
|
||||||
|
- 3128:3128
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Check proxy
|
||||||
|
run: |
|
||||||
|
netstat -aptn
|
||||||
|
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
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
with:
|
||||||
|
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
|
||||||
|
driver-opts: |
|
||||||
|
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
|
||||||
|
network=host
|
||||||
|
env.http_proxy=http://127.0.0.1:3128
|
||||||
|
env.https_proxy=http://127.0.0.1:3128
|
||||||
|
buildkitd-flags: --debug
|
||||||
|
-
|
||||||
|
name: Build
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
./test/config.hcl
|
||||||
|
|||||||
2
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
27
src/main.ts
27
src/main.ts
@@ -1,4 +1,5 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import * as path from 'path';
|
||||||
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';
|
||||||
import {Inputs as BuildxInputs} from '@docker/actions-toolkit/lib/buildx/inputs';
|
import {Inputs as BuildxInputs} from '@docker/actions-toolkit/lib/buildx/inputs';
|
||||||
@@ -7,6 +8,7 @@ import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
|||||||
import {Exec} from '@docker/actions-toolkit/lib/exec';
|
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 {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';
|
||||||
import * as stateHelper from './state-helper';
|
import * as stateHelper from './state-helper';
|
||||||
@@ -34,6 +36,31 @@ actionsToolkit.run(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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 (Object.keys(dockerConfig.proxies).length > 1) {
|
||||||
|
prefix = ' ';
|
||||||
|
core.info(host);
|
||||||
|
}
|
||||||
|
for (const key in dockerConfig.proxies[host]) {
|
||||||
|
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.`);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -37,3 +37,8 @@ target "app-plus" {
|
|||||||
IAMPLUS = "true"
|
IAMPLUS = "true"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
target "app-proxy" {
|
||||||
|
inherits = ["app"]
|
||||||
|
dockerfile = "proxy.Dockerfile"
|
||||||
|
}
|
||||||
|
|||||||
9
test/proxy.Dockerfile
Normal file
9
test/proxy.Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
FROM alpine
|
||||||
|
RUN apk add --no-cache curl net-tools
|
||||||
|
ARG HTTP_PROXY
|
||||||
|
ARG HTTPS_PROXY
|
||||||
|
RUN printenv HTTP_PROXY
|
||||||
|
RUN printenv HTTPS_PROXY
|
||||||
|
RUN netstat -aptn
|
||||||
|
RUN curl --retry 5 --retry-all-errors --retry-delay 0 --connect-timeout 5 --proxy $HTTP_PROXY -v --insecure --head https://www.google.com
|
||||||
Reference in New Issue
Block a user