3 Commits

Author SHA1 Message Date
CrazyMax
988b5a0280 Merge pull request #347 from crazy-max/skip-malformed-context
Some checks failed
ci / debug (push) Has been cancelled
ci / install (push) Has been cancelled
ci / use (false) (push) Has been cancelled
ci / use (true) (push) Has been cancelled
ci / driver (image=moby/buildkit:latest) (push) Has been cancelled
ci / driver (image=moby/buildkit:master network=host ) (push) Has been cancelled
ci / docker-driver (push) Has been cancelled
ci / endpoint (push) Has been cancelled
ci / config (push) Has been cancelled
ci / config-inline (push) Has been cancelled
ci / with-qemu (, all) (push) Has been cancelled
ci / with-qemu (, arm64,riscv64,arm) (push) Has been cancelled
ci / with-qemu (v0.9.1, all) (push) Has been cancelled
ci / with-qemu (v0.9.1, arm64,riscv64,arm) (push) Has been cancelled
ci / build-ref (cb185f095fd3d9444e0aa605d3789e9e05f2a1e7) (push) Has been cancelled
ci / build-ref (master) (push) Has been cancelled
ci / build-ref (refs/pull/731/head) (push) Has been cancelled
ci / build-ref (refs/tags/v0.5.1) (push) Has been cancelled
ci / standalone-cmd (push) Has been cancelled
ci / standalone-action (push) Has been cancelled
ci / standalone-install-error (push) Has been cancelled
ci / append (push) Has been cancelled
ci / platforms (push) Has been cancelled
ci / docker-context (push) Has been cancelled
ci / cleanup (false) (push) Has been cancelled
ci / cleanup (true) (push) Has been cancelled
ci / k3s (v0.10.5) (push) Has been cancelled
ci / k3s (v0.11.0) (push) Has been cancelled
ci / cache-binary (false) (push) Has been cancelled
ci / cache-binary (true) (push) Has been cancelled
check for malformed docker context
2024-07-29 18:29:31 +02:00
CrazyMax
2c215620b8 chore: update generated content
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-07-29 18:25:27 +02:00
CrazyMax
3382292cd5 check for malformed docker context
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-07-29 18:24:18 +02:00
3 changed files with 27 additions and 8 deletions

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -12,6 +12,7 @@ import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
import {Util} from '@docker/actions-toolkit/lib/util';
import {Node} from '@docker/actions-toolkit/lib/types/buildx/builder';
import {ContextInfo} from '@docker/actions-toolkit/lib/types/docker/docker';
import * as context from './context';
import * as stateHelper from './state-helper';
@@ -74,18 +75,36 @@ actionsToolkit.run(
// https://github.com/docker/buildx/blob/b96ad59f64d40873e4959336d294b648bb3937fe/builder/builder.go#L489
// https://github.com/docker/setup-buildx-action/issues/105
if (!standalone && inputs.driver == 'docker-container' && (await Docker.context()) == 'default' && inputs.endpoint.length == 0) {
const contextInfo = await Docker.contextInspect('default');
core.debug(`context info: ${JSON.stringify(contextInfo, undefined, 2)}`);
const hasTLSData = Object.keys(contextInfo.Endpoints).length > 0 && Object.values(contextInfo.Endpoints)[0].TLSData;
const hasTLSMaterial = Object.keys(contextInfo.TLSMaterial).length > 0 && Object.values(contextInfo.TLSMaterial)[0].length > 0;
if (hasTLSData || hasTLSMaterial) {
let defaultContextWithTLS: boolean = false;
await core.group(`Inspecting default docker context`, async () => {
await Docker.getExecOutput(['context', 'inspect', '--format=json', 'default'], {
ignoreReturnCode: true,
silent: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
core.info(`Cannot inspect default docker context: ${res.stderr.trim()}`);
} else {
try {
const contextInfo = (<Array<ContextInfo>>JSON.parse(res.stdout.trim()))[0];
core.info(JSON.stringify(JSON.parse(res.stdout.trim()), undefined, 2));
const hasTLSData = Object.keys(contextInfo.Endpoints).length > 0 && Object.values(contextInfo.Endpoints)[0].TLSData !== undefined;
const hasTLSMaterial = Object.keys(contextInfo.TLSMaterial).length > 0 && Object.values(contextInfo.TLSMaterial)[0].length > 0;
defaultContextWithTLS = hasTLSData || hasTLSMaterial;
} catch (e) {
core.info(`Unable to parse default docker context info: ${e}`);
core.info(res.stdout.trim());
}
}
});
});
if (defaultContextWithTLS) {
const tmpDockerContext = `buildx-${uuid.v4()}`;
await core.group(`Creating temp docker context (TLS data loaded in default one)`, async () => {
await Docker.getExecOutput(['context', 'create', tmpDockerContext], {
ignoreReturnCode: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
core.warning(`cannot create docker context ${tmpDockerContext}: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
core.warning(`Cannot create docker context ${tmpDockerContext}: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
} else {
core.info(`Setting builder endpoint to ${tmpDockerContext} context`);
inputs.endpoint = tmpDockerContext;