feat(classes.dockerfile): support using a local base image as a build context in buildx commands

This commit is contained in:
2026-02-06 15:05:46 +00:00
parent 907048fa87
commit 31fb4aea3c
3 changed files with 18 additions and 3 deletions

View File

@@ -1,5 +1,12 @@
# Changelog # Changelog
## 2026-02-06 - 1.10.0 - feat(classes.dockerfile)
support using a local base image as a build context in buildx commands
- Adds --build-context flag mapping base image to docker-image://<localTag> when localBaseImageDependent && localBaseDockerfile are set
- Appends the build context flag to both single-platform and multi-platform docker buildx commands
- Logs an info message indicating the local build context mapping
## 2026-02-06 - 1.9.0 - feat(build) ## 2026-02-06 - 1.9.0 - feat(build)
add verbose build output, progress logging, and timing for builds/tests add verbose build output, progress logging, and timing for builds/tests

View File

@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@git.zone/tsdocker', name: '@git.zone/tsdocker',
version: '1.9.0', version: '1.10.0',
description: 'develop npm modules cross platform with docker' description: 'develop npm modules cross platform with docker'
} }

View File

@@ -409,15 +409,23 @@ export class Dockerfile {
const noCacheFlag = options?.noCache ? ' --no-cache' : ''; const noCacheFlag = options?.noCache ? ' --no-cache' : '';
const verbose = options?.verbose ?? false; 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; let buildCommand: string;
if (platformOverride) { if (platformOverride) {
// Single platform override via buildx // 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) { } else if (config.platforms && config.platforms.length > 1) {
// Multi-platform build using buildx // Multi-platform build using buildx
const platformString = config.platforms.join(','); 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) { if (config.push) {
buildCommand += ' --push'; buildCommand += ' --push';