Compare commits

...

2 Commits

Author SHA1 Message Date
3a8b301b3e v1.6.0
Some checks failed
Default (tags) / security (push) Successful in 39s
Default (tags) / test (push) Failing after 4m0s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-02-06 13:25:22 +00:00
c09bef33c3 feat(docker): add support for no-cache builds and tag built images for local dependency resolution 2026-02-06 13:25:21 +00:00
7 changed files with 43 additions and 8 deletions

View File

@@ -1,5 +1,14 @@
# Changelog
## 2026-02-06 - 1.6.0 - feat(docker)
add support for no-cache builds and tag built images for local dependency resolution
- Introduce IBuildCommandOptions.noCache to control --no-cache behavior
- Propagate noCache from CLI (via cache flag) through TsDockerManager to Dockerfile.build
- Append --no-cache to docker build/buildx commands when noCache is true
- After building an image, tag it with full base image references used by dependent Dockerfiles so their FROM lines resolve to the locally-built image
- Log tagging actions and execute docker tag via smartshellInstance
## 2026-02-06 - 1.5.0 - feat(build)
add support for selective builds, platform override and build timeout

View File

@@ -1,6 +1,6 @@
{
"name": "@git.zone/tsdocker",
"version": "1.5.0",
"version": "1.6.0",
"private": false,
"description": "develop npm modules cross platform with docker",
"main": "dist_ts/index.js",

View File

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

View File

@@ -138,10 +138,23 @@ export class Dockerfile {
*/
public static async buildDockerfiles(
sortedArrayArg: Dockerfile[],
options?: { platform?: string; timeout?: number },
options?: { platform?: string; timeout?: number; noCache?: boolean },
): Promise<Dockerfile[]> {
for (const dockerfileArg of sortedArrayArg) {
await dockerfileArg.build(options);
// Tag the built image with the full base image references used by dependent Dockerfiles,
// so their FROM lines resolve to the locally-built image instead of pulling from a registry.
const dependentBaseImages = new Set<string>();
for (const other of sortedArrayArg) {
if (other.localBaseDockerfile === dockerfileArg && other.baseImage !== dockerfileArg.buildTag) {
dependentBaseImages.add(other.baseImage);
}
}
for (const fullTag of dependentBaseImages) {
logger.log('info', `Tagging ${dockerfileArg.buildTag} as ${fullTag} for local dependency resolution`);
await smartshellInstance.exec(`docker tag ${dockerfileArg.buildTag} ${fullTag}`);
}
}
return sortedArrayArg;
}
@@ -365,22 +378,23 @@ export class Dockerfile {
/**
* Builds the Dockerfile
*/
public async build(options?: { platform?: string; timeout?: number }): Promise<void> {
public async build(options?: { platform?: string; timeout?: number; noCache?: boolean }): Promise<void> {
logger.log('info', 'now building Dockerfile for ' + this.cleanTag);
const buildArgsString = await Dockerfile.getDockerBuildArgs(this.managerRef);
const config = this.managerRef.config;
const platformOverride = options?.platform;
const timeout = options?.timeout;
const noCacheFlag = options?.noCache ? ' --no-cache' : '';
let buildCommand: string;
if (platformOverride) {
// Single platform override via buildx
buildCommand = `docker buildx build --platform ${platformOverride} --load -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`;
buildCommand = `docker buildx build --platform ${platformOverride}${noCacheFlag} --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} -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`;
buildCommand = `docker buildx build --platform ${platformString}${noCacheFlag} -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`;
if (config.push) {
buildCommand += ' --push';
@@ -390,7 +404,7 @@ export class Dockerfile {
} else {
// Standard build
const versionLabel = this.managerRef.projectInfo?.npm?.version || 'unknown';
buildCommand = `docker build --label="version=${versionLabel}" -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`;
buildCommand = `docker build --label="version=${versionLabel}"${noCacheFlag} -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`;
}
if (timeout) {

View File

@@ -139,6 +139,7 @@ export class TsDockerManager {
await Dockerfile.buildDockerfiles(toBuild, {
platform: options?.platform,
timeout: options?.timeout,
noCache: options?.noCache,
});
logger.log('success', 'All Dockerfiles built successfully');

View File

@@ -76,4 +76,5 @@ export interface IBuildCommandOptions {
patterns?: string[]; // Dockerfile name patterns (e.g., ['Dockerfile_base', 'Dockerfile_*'])
platform?: string; // Single platform override (e.g., 'linux/arm64')
timeout?: number; // Build timeout in seconds
noCache?: boolean; // Force rebuild without Docker layer cache (--no-cache)
}

View File

@@ -44,6 +44,9 @@ export let run = () => {
if (argvArg.timeout) {
buildOptions.timeout = Number(argvArg.timeout);
}
if (argvArg.cache === false) {
buildOptions.noCache = true;
}
await manager.build(buildOptions);
logger.log('success', 'Build completed successfully');
@@ -78,6 +81,9 @@ export let run = () => {
if (argvArg.timeout) {
buildOptions.timeout = Number(argvArg.timeout);
}
if (argvArg.cache === false) {
buildOptions.noCache = true;
}
// Build images first (if not already built)
await manager.build(buildOptions);
@@ -130,7 +136,11 @@ export let run = () => {
await manager.prepare();
// Build images first
await manager.build();
const buildOptions: IBuildCommandOptions = {};
if (argvArg.cache === false) {
buildOptions.noCache = true;
}
await manager.build(buildOptions);
// Run tests
await manager.test();