Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 45 additions & 21 deletions src/lib/server/stacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ function findComposeOverrideFile(stackDir: string, composeFileName: string): str
* @param customComposePath - Optional path to existing compose file (for imported stacks, skips writing)
*/
async function executeLocalCompose(
operation: 'up' | 'down' | 'stop' | 'start' | 'restart' | 'pull',
operation: 'up' | 'down' | 'stop' | 'start' | 'restart' | 'pull' | 'build',
stackName: string,
composeContent: string,
dockerHost?: string,
Expand Down Expand Up @@ -1043,8 +1043,7 @@ async function executeLocalCompose(
case 'up':
args.push('up', '-d', '--remove-orphans');
if (forceRecreate) args.push('--force-recreate');
if (build) args.push('--build');
if (build && noBuildCache) args.push('--no-cache');
if (build && !noBuildCache) args.push('--build');
if (pullPolicy) args.push('--pull', pullPolicy);
// If targeting a specific service, only update that service
if (serviceName) {
Expand All @@ -1071,6 +1070,14 @@ async function executeLocalCompose(
args.push(serviceName);
}
break;
case 'build':
args.push('build');
if (noBuildCache) args.push('--no-cache');
if (pullPolicy) args.push('--pull');
if (serviceName) {
args.push(serviceName);
}
break;
}

const commandStr = args.join(' ');
Expand Down Expand Up @@ -1209,7 +1216,7 @@ async function executeLocalCompose(
* @param secretVars - Secret environment variables (injected via shell env on Hawser, NEVER in .env)
*/
async function executeComposeViaHawser(
operation: 'up' | 'down' | 'stop' | 'start' | 'restart' | 'pull',
operation: 'up' | 'down' | 'stop' | 'start' | 'restart' | 'pull' | 'build',
stackName: string,
composeContent: string,
envId: number,
Expand Down Expand Up @@ -1359,7 +1366,7 @@ async function executeComposeViaHawser(
* @param secretVars - Secret environment variables (from DB, injected via shell env)
*/
async function executeComposeCommand(
operation: 'up' | 'down' | 'stop' | 'start' | 'restart' | 'pull',
operation: 'up' | 'down' | 'stop' | 'start' | 'restart' | 'pull' | 'build',
options: ComposeCommandOptions,
composeContent: string,
envVars?: Record<string, string>,
Expand Down Expand Up @@ -2315,24 +2322,41 @@ export async function deployStack(options: DeployStackOptions): Promise<StackOpe
// so no override file is needed - only pass secrets for shell injection.
const isGitStack = !!sourceDir;

console.log(`${logPrefix} Calling executeComposeCommand...`);
const cmdOptions: ComposeCommandOptions = {
stackName: name,
envId,
forceRecreate,
build,
noBuildCache,
pullPolicy,
stackFiles,
workingDir,
composePath: actualComposePath,
envPath: actualEnvPath,
useOverrideFile: isGitStack,
// Pass compose filename for Hawser (extracted from path or provided explicitly)
composeFileName: composeFileName || (actualComposePath ? basename(actualComposePath) : undefined)
};

// If build and noBuildCache are true, run a separate build step first
if (build && noBuildCache) {
console.log(`${logPrefix} Running separate build step with --no-cache...`);
const buildResult = await executeComposeCommand(
'build',
cmdOptions,
compose,
isGitStack ? dbNonSecretVars : undefined,
secretVars
);
if (!buildResult.success) {
return buildResult;
}
}

console.log(`${logPrefix} Calling executeComposeCommand (up)...`);
const result = await executeComposeCommand(
'up',
{
stackName: name,
envId,
forceRecreate,
build,
noBuildCache,
pullPolicy,
stackFiles,
workingDir,
composePath: actualComposePath,
envPath: actualEnvPath,
useOverrideFile: isGitStack,
// Pass compose filename for Hawser (extracted from path or provided explicitly)
composeFileName: composeFileName || (actualComposePath ? basename(actualComposePath) : undefined)
},
cmdOptions,
compose,
isGitStack ? dbNonSecretVars : undefined,
secretVars
Expand Down