From 31fb4aea3cd90063df79902603311567811bc145 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Fri, 6 Feb 2026 15:05:46 +0000 Subject: [PATCH] feat(classes.dockerfile): support using a local base image as a build context in buildx commands --- changelog.md | 7 +++++++ ts/00_commitinfo_data.ts | 2 +- ts/classes.dockerfile.ts | 12 ++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index e4ad49d..40f011a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # 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:// 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) add verbose build output, progress logging, and timing for builds/tests diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index b4c5a27..e0c0437 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -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' } diff --git a/ts/classes.dockerfile.ts b/ts/classes.dockerfile.ts index 0559da7..8e66de1 100644 --- a/ts/classes.dockerfile.ts +++ b/ts/classes.dockerfile.ts @@ -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';