feat(classes.dockerfile): support using a local base image as a build context in buildx commands
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tsdocker',
|
||||
version: '1.9.0',
|
||||
version: '1.10.0',
|
||||
description: 'develop npm modules cross platform with docker'
|
||||
}
|
||||
|
||||
@@ -409,15 +409,23 @@ export class Dockerfile {
|
||||
const noCacheFlag = options?.noCache ? ' --no-cache' : '';
|
||||
const verbose = options?.verbose ?? false;
|
||||
|
||||
let buildContextFlag = '';
|
||||
if (this.localBaseImageDependent && this.localBaseDockerfile) {
|
||||
const fromImage = this.baseImage;
|
||||
const localTag = this.localBaseDockerfile.buildTag;
|
||||
buildContextFlag = ` --build-context "${fromImage}=docker-image://${localTag}"`;
|
||||
logger.log('info', `Using local build context: ${fromImage} -> docker-image://${localTag}`);
|
||||
}
|
||||
|
||||
let buildCommand: string;
|
||||
|
||||
if (platformOverride) {
|
||||
// Single platform override via buildx
|
||||
buildCommand = `docker buildx build --platform ${platformOverride}${noCacheFlag} --load -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`;
|
||||
buildCommand = `docker buildx build --platform ${platformOverride}${noCacheFlag}${buildContextFlag} --load -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`;
|
||||
} else if (config.platforms && config.platforms.length > 1) {
|
||||
// Multi-platform build using buildx
|
||||
const platformString = config.platforms.join(',');
|
||||
buildCommand = `docker buildx build --platform ${platformString}${noCacheFlag} -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`;
|
||||
buildCommand = `docker buildx build --platform ${platformString}${noCacheFlag}${buildContextFlag} -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`;
|
||||
|
||||
if (config.push) {
|
||||
buildCommand += ' --push';
|
||||
|
||||
Reference in New Issue
Block a user