mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-23 03:16:09 +08:00
Merge pull request #410 from crazy-max/export-build-image-env
buildx(history): env var to override export build image
This commit is contained in:
commit
8d807b6902
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {describe, expect, test} from '@jest/globals';
|
import {afterEach, beforeEach, describe, expect, it, jest, test} from '@jest/globals';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
@ -147,3 +147,52 @@ maybe('exportBuild', () => {
|
|||||||
expect(exportRes?.summaries).toBeDefined();
|
expect(exportRes?.summaries).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
maybe('exportBuild custom image', () => {
|
||||||
|
const originalEnv = process.env;
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
|
process.env = {
|
||||||
|
...originalEnv,
|
||||||
|
DOCKER_BUILD_EXPORT_BUILD_IMAGE: 'docker.io/dockereng/export-build:0.2.2'
|
||||||
|
};
|
||||||
|
});
|
||||||
|
afterEach(() => {
|
||||||
|
process.env = originalEnv;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with custom image', async () => {
|
||||||
|
const buildx = new Buildx();
|
||||||
|
const build = new Build({buildx: buildx});
|
||||||
|
|
||||||
|
fs.mkdirSync(tmpDir, {recursive: true});
|
||||||
|
await expect(
|
||||||
|
(async () => {
|
||||||
|
// prettier-ignore
|
||||||
|
const buildCmd = await buildx.getCommand([
|
||||||
|
'--builder', process.env.CTN_BUILDER_NAME ?? 'default',
|
||||||
|
'build', '-f', path.join(fixturesDir, 'hello.Dockerfile'),
|
||||||
|
'--metadata-file', build.getMetadataFilePath(),
|
||||||
|
fixturesDir
|
||||||
|
]);
|
||||||
|
await Exec.exec(buildCmd.command, buildCmd.args);
|
||||||
|
})()
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
|
||||||
|
const metadata = build.resolveMetadata();
|
||||||
|
expect(metadata).toBeDefined();
|
||||||
|
const buildRef = build.resolveRef(metadata);
|
||||||
|
expect(buildRef).toBeDefined();
|
||||||
|
|
||||||
|
const history = new History({buildx: buildx});
|
||||||
|
const exportRes = await history.export({
|
||||||
|
refs: [buildRef ?? '']
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(exportRes).toBeDefined();
|
||||||
|
expect(exportRes?.dockerbuildFilename).toBeDefined();
|
||||||
|
expect(exportRes?.dockerbuildSize).toBeDefined();
|
||||||
|
expect(fs.existsSync(exportRes?.dockerbuildFilename)).toBe(true);
|
||||||
|
expect(exportRes?.summaries).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -36,7 +36,8 @@ export interface HistoryOpts {
|
|||||||
export class History {
|
export class History {
|
||||||
private readonly buildx: Buildx;
|
private readonly buildx: Buildx;
|
||||||
|
|
||||||
private static readonly EXPORT_TOOL_IMAGE: string = 'docker.io/dockereng/export-build:latest';
|
private static readonly EXPORT_BUILD_IMAGE_DEFAULT: string = 'docker.io/dockereng/export-build:latest';
|
||||||
|
private static readonly EXPORT_BUILD_IMAGE_ENV: string = 'DOCKER_BUILD_EXPORT_BUILD_IMAGE';
|
||||||
|
|
||||||
constructor(opts?: HistoryOpts) {
|
constructor(opts?: HistoryOpts) {
|
||||||
this.buildx = opts?.buildx || new Buildx();
|
this.buildx = opts?.buildx || new Buildx();
|
||||||
@ -131,7 +132,7 @@ export class History {
|
|||||||
'run', '--rm', '-i',
|
'run', '--rm', '-i',
|
||||||
'-v', `${Buildx.refsDir}:/buildx-refs`,
|
'-v', `${Buildx.refsDir}:/buildx-refs`,
|
||||||
'-v', `${outDir}:/out`,
|
'-v', `${outDir}:/out`,
|
||||||
opts.image || History.EXPORT_TOOL_IMAGE,
|
opts.image || process.env[History.EXPORT_BUILD_IMAGE_ENV] || History.EXPORT_BUILD_IMAGE_DEFAULT,
|
||||||
...ebargs
|
...ebargs
|
||||||
]
|
]
|
||||||
core.info(`[command]docker ${dockerRunArgs.join(' ')}`);
|
core.info(`[command]docker ${dockerRunArgs.join(' ')}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user