mirror of
https://github.com/docker/build-push-action.git
synced 2026-06-29 01:41:40 +00:00
Merge 76e67e64a2 into 2a53c6ccda
This commit is contained in:
commit
1e38ae2df1
23
.github/workflows/ci.yml
vendored
23
.github/workflows/ci.yml
vendored
@ -1344,3 +1344,26 @@ jobs:
|
|||||||
name: Check docker
|
name: Check docker
|
||||||
run: |
|
run: |
|
||||||
docker image inspect localhost:5000/name/app:latest
|
docker image inspect localhost:5000/name/app:latest
|
||||||
|
|
||||||
|
disable-summary:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
path: action
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
|
||||||
|
driver-opts: |
|
||||||
|
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
|
||||||
|
-
|
||||||
|
name: Build
|
||||||
|
uses: ./action
|
||||||
|
with:
|
||||||
|
file: ./test/Dockerfile
|
||||||
|
env:
|
||||||
|
DOCKER_BUILD_NO_SUMMARY: true
|
||||||
|
|||||||
@ -256,6 +256,12 @@ The following outputs are available:
|
|||||||
| `digest` | String | Image digest |
|
| `digest` | String | Image digest |
|
||||||
| `metadata` | JSON | Build result metadata |
|
| `metadata` | JSON | Build result metadata |
|
||||||
|
|
||||||
|
### environment variables
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
|---------------------------|------|-------------------------------------------------|
|
||||||
|
| `DOCKER_BUILD_NO_SUMMARY` | Bool | If `true`, build summary generation is disabled |
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
See [TROUBLESHOOTING.md](TROUBLESHOOTING.md)
|
See [TROUBLESHOOTING.md](TROUBLESHOOTING.md)
|
||||||
|
|||||||
6
dist/index.js
generated
vendored
6
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
dist/licenses.txt
generated
vendored
27
dist/licenses.txt
generated
vendored
@ -2602,6 +2602,31 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
isarray
|
isarray
|
||||||
MIT
|
MIT
|
||||||
|
|
||||||
|
js-yaml
|
||||||
|
MIT
|
||||||
|
(The MIT License)
|
||||||
|
|
||||||
|
Copyright (C) 2011-2015 by Vitaly Puzrin
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
jwt-decode
|
jwt-decode
|
||||||
MIT
|
MIT
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
@ -2782,7 +2807,7 @@ minimatch
|
|||||||
ISC
|
ISC
|
||||||
The ISC License
|
The ISC License
|
||||||
|
|
||||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
Copyright (c) 2011-2023 Isaac Z. Schlueter and Contributors
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
"packageManager": "yarn@3.6.3",
|
"packageManager": "yarn@3.6.3",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
"@docker/actions-toolkit": "0.23.0",
|
"@docker/actions-toolkit": "https://github.com/crazy-max/docker-actions-toolkit#summary-test",
|
||||||
"handlebars": "^4.7.7"
|
"handlebars": "^4.7.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@ -79,6 +79,25 @@ export async function getInputs(): Promise<Inputs> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sanitizeInputs(inputs: Inputs) {
|
||||||
|
const res = {};
|
||||||
|
for (const key of Object.keys(inputs)) {
|
||||||
|
if (key === 'github-token') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const value: string | string[] | boolean = inputs[key];
|
||||||
|
if (typeof value === 'boolean' && value === false) {
|
||||||
|
continue;
|
||||||
|
} else if (Array.isArray(value) && value.length === 0) {
|
||||||
|
continue;
|
||||||
|
} else if (!value) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
res[key] = value;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
export async function getArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
|
export async function getArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
|
||||||
const context = handlebars.compile(inputs.context)({
|
const context = handlebars.compile(inputs.context)({
|
||||||
defaultContext: Context.gitContext()
|
defaultContext: Context.gitContext()
|
||||||
|
|||||||
66
src/main.ts
66
src/main.ts
@ -4,11 +4,14 @@ import * as stateHelper from './state-helper';
|
|||||||
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 {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx';
|
||||||
|
import {History as BuildxHistory} from '@docker/actions-toolkit/lib/buildx/history';
|
||||||
import {Context} from '@docker/actions-toolkit/lib/context';
|
import {Context} from '@docker/actions-toolkit/lib/context';
|
||||||
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
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 {Util} from '@docker/actions-toolkit/lib/util';
|
||||||
|
|
||||||
import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker';
|
import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker';
|
||||||
|
|
||||||
@ -17,8 +20,10 @@ import * as context from './context';
|
|||||||
actionsToolkit.run(
|
actionsToolkit.run(
|
||||||
// main
|
// main
|
||||||
async () => {
|
async () => {
|
||||||
|
const startedTime = new Date();
|
||||||
const inputs: context.Inputs = await context.getInputs();
|
const inputs: context.Inputs = await context.getInputs();
|
||||||
core.debug(`inputs: ${JSON.stringify(inputs)}`);
|
core.debug(`inputs: ${JSON.stringify(inputs)}`);
|
||||||
|
stateHelper.setInputs(inputs);
|
||||||
|
|
||||||
const toolkit = new Toolkit();
|
const toolkit = new Toolkit();
|
||||||
|
|
||||||
@ -82,11 +87,12 @@ actionsToolkit.run(
|
|||||||
core.debug(`buildCmd.command: ${buildCmd.command}`);
|
core.debug(`buildCmd.command: ${buildCmd.command}`);
|
||||||
core.debug(`buildCmd.args: ${JSON.stringify(buildCmd.args)}`);
|
core.debug(`buildCmd.args: ${JSON.stringify(buildCmd.args)}`);
|
||||||
|
|
||||||
|
let err: Error | undefined;
|
||||||
await Exec.getExecOutput(buildCmd.command, buildCmd.args, {
|
await Exec.getExecOutput(buildCmd.command, buildCmd.args, {
|
||||||
ignoreReturnCode: true
|
ignoreReturnCode: true
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
throw new Error(`buildx failed with: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
|
err = Error(`buildx failed with: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -113,9 +119,48 @@ actionsToolkit.run(
|
|||||||
core.setOutput('metadata', metadatadt);
|
core.setOutput('metadata', metadatadt);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
await core.group(`Reference`, async () => {
|
||||||
|
const ref = await buildRef(toolkit, startedTime, inputs.builder);
|
||||||
|
if (ref) {
|
||||||
|
core.info(ref);
|
||||||
|
stateHelper.setBuildRef(ref);
|
||||||
|
} else {
|
||||||
|
core.warning('No build ref found');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// post
|
// post
|
||||||
async () => {
|
async () => {
|
||||||
|
if (stateHelper.buildRef.length > 0) {
|
||||||
|
await core.group(`Generating build summary`, async () => {
|
||||||
|
if (process.env.DOCKER_BUILD_NO_SUMMARY && Util.parseBool(process.env.DOCKER_BUILD_NO_SUMMARY)) {
|
||||||
|
core.info('Summary disabled');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const buildxHistory = new BuildxHistory();
|
||||||
|
const exportRes = await buildxHistory.export({
|
||||||
|
refs: [stateHelper.buildRef]
|
||||||
|
});
|
||||||
|
core.info(`Build record exported to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`);
|
||||||
|
const uploadRes = await GitHub.uploadArtifact({
|
||||||
|
filename: exportRes.dockerbuildFilename,
|
||||||
|
mimeType: 'application/gzip',
|
||||||
|
retentionDays: 90
|
||||||
|
});
|
||||||
|
await GitHub.writeBuildSummary({
|
||||||
|
exportRes: exportRes,
|
||||||
|
uploadRes: uploadRes,
|
||||||
|
inputs: stateHelper.inputs
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
core.warning(e.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
if (stateHelper.tmpDir.length > 0) {
|
if (stateHelper.tmpDir.length > 0) {
|
||||||
await core.group(`Removing temp folder ${stateHelper.tmpDir}`, async () => {
|
await core.group(`Removing temp folder ${stateHelper.tmpDir}`, async () => {
|
||||||
fs.rmSync(stateHelper.tmpDir, {recursive: true});
|
fs.rmSync(stateHelper.tmpDir, {recursive: true});
|
||||||
@ -123,3 +168,22 @@ actionsToolkit.run(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
async function buildRef(toolkit: Toolkit, since: Date, builder?: string): Promise<string> {
|
||||||
|
// get ref from metadata file
|
||||||
|
const ref = toolkit.buildxBuild.resolveRef();
|
||||||
|
if (ref) {
|
||||||
|
return ref;
|
||||||
|
}
|
||||||
|
// otherwise, look for the very first build ref since the build has started
|
||||||
|
if (!builder) {
|
||||||
|
const currentBuilder = await toolkit.builder.inspect();
|
||||||
|
builder = currentBuilder.name;
|
||||||
|
}
|
||||||
|
const refs = Buildx.refs({
|
||||||
|
dir: Buildx.refsDir,
|
||||||
|
builderName: builder,
|
||||||
|
since: since
|
||||||
|
});
|
||||||
|
return Object.keys(refs).length > 0 ? Object.keys(refs)[0] : '';
|
||||||
|
}
|
||||||
|
|||||||
@ -1,7 +1,19 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
|
import {Inputs, sanitizeInputs} from './context';
|
||||||
|
|
||||||
export const tmpDir = process.env['STATE_tmpDir'] || '';
|
export const tmpDir = process.env['STATE_tmpDir'] || '';
|
||||||
|
export const inputs = process.env['STATE_inputs'] ? JSON.parse(process.env['STATE_inputs']) : undefined;
|
||||||
|
export const buildRef = process.env['STATE_buildRef'] || '';
|
||||||
|
|
||||||
export function setTmpDir(tmpDir: string) {
|
export function setTmpDir(tmpDir: string) {
|
||||||
core.saveState('tmpDir', tmpDir);
|
core.saveState('tmpDir', tmpDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setInputs(inputs: Inputs) {
|
||||||
|
core.saveState('inputs', JSON.stringify(sanitizeInputs(inputs)));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setBuildRef(buildRef: string) {
|
||||||
|
core.saveState('buildRef', buildRef);
|
||||||
|
}
|
||||||
|
|||||||
11
yarn.lock
11
yarn.lock
@ -1055,9 +1055,9 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@docker/actions-toolkit@npm:0.23.0":
|
"@docker/actions-toolkit@https://github.com/crazy-max/docker-actions-toolkit#summary-test":
|
||||||
version: 0.23.0
|
version: 0.0.0+unknown
|
||||||
resolution: "@docker/actions-toolkit@npm:0.23.0"
|
resolution: "@docker/actions-toolkit@https://github.com/crazy-max/docker-actions-toolkit.git#commit=bb135ac93a8bf3ff63207e56e2fdcd4c1f4fe8d2"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@actions/artifact": ^2.1.7
|
"@actions/artifact": ^2.1.7
|
||||||
"@actions/cache": ^3.2.4
|
"@actions/cache": ^3.2.4
|
||||||
@ -1073,10 +1073,11 @@ __metadata:
|
|||||||
async-retry: ^1.3.3
|
async-retry: ^1.3.3
|
||||||
csv-parse: ^5.5.6
|
csv-parse: ^5.5.6
|
||||||
handlebars: ^4.7.8
|
handlebars: ^4.7.8
|
||||||
|
js-yaml: ^4.1.0
|
||||||
jwt-decode: ^4.0.0
|
jwt-decode: ^4.0.0
|
||||||
semver: ^7.6.2
|
semver: ^7.6.2
|
||||||
tmp: ^0.2.3
|
tmp: ^0.2.3
|
||||||
checksum: 7bac57e9d1af6214a16509051d7ac1f276880f332d44a0d52a3d9d3601204c0cbf9a23933772c5a0974e705d4295b32d036c4d37afe8965330d8f116df07faac
|
checksum: 1bdcfebcb3d7d6a16942e8418e5b9ef93270eb686b3f00de831d0f26f6dc41f6aef4314c5321616789bcfd4adf2b5640092fffa17b07528aed18ce8a9ea4b54c
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@ -3137,7 +3138,7 @@ __metadata:
|
|||||||
resolution: "docker-build-push@workspace:."
|
resolution: "docker-build-push@workspace:."
|
||||||
dependencies:
|
dependencies:
|
||||||
"@actions/core": ^1.10.1
|
"@actions/core": ^1.10.1
|
||||||
"@docker/actions-toolkit": 0.23.0
|
"@docker/actions-toolkit": "https://github.com/crazy-max/docker-actions-toolkit#summary-test"
|
||||||
"@types/node": ^20.12.12
|
"@types/node": ^20.12.12
|
||||||
"@typescript-eslint/eslint-plugin": ^7.9.0
|
"@typescript-eslint/eslint-plugin": ^7.9.0
|
||||||
"@typescript-eslint/parser": ^7.9.0
|
"@typescript-eslint/parser": ^7.9.0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user