Add option to pull image before container update

This commit is contained in:
shamoon authored and Jarek Krochmalski committed 2026-02-03 09:25:01 +01:00
1 parent 610548ed66
commit 6b49d13236
3 files changed
+23 -2

No files matched your search

@@ -1,5 +1,5 @@
import { json } from '@sveltejs/kit';
import { updateContainer, type CreateContainerOptions } from '$lib/server/docker';
import { pullImage, updateContainer, type CreateContainerOptions } from '$lib/server/docker';
import { authorize } from '$lib/server/authorize';
import { auditContainer } from '$lib/server/audit';
import { removePendingContainerUpdate } from '$lib/server/db';
@@ -19,7 +19,18 @@ export const POST: RequestHandler = async (event) => {
try {
const body = await request.json();
const { startAfterUpdate, ...options } = body;
const { startAfterUpdate, repullImage, ...options } = body;
if (repullImage) {
console.log(`Pulling image...`);
try {
await pullImage(options.image, undefined, envIdNum);
console.log(`Image pulled successfully`);
} catch (pullError: any) {
console.log(`Pull failed: ${pullError.message}`);
throw pullError;
}
}
console.log(`Updating container ${params.id} with name: ${options.name}`);
@@ -70,6 +70,7 @@
restartMaxRetries: number | '';
networkMode: string;
startAfterCreate?: boolean;
repullImage?: boolean;
// Port mappings
portMappings: { hostPort: string; containerPort: string; protocol: string }[];
// Volume mappings
@@ -152,6 +153,7 @@
restartMaxRetries = $bindable(),
networkMode = $bindable(),
startAfterCreate = $bindable(true),
repullImage = $bindable(true),
portMappings = $bindable(),
volumeMappings = $bindable(),
envVars = $bindable(),
@@ -643,6 +645,11 @@
</div>
</div>
<div class="flex items-center gap-3 pt-1">
<Label class="text-xs font-normal">Pull image before update</Label>
<TogglePill bind:checked={repullImage} />
</div>
<div class="flex items-center gap-3 pt-1">
<Label class="text-xs font-normal">Start container after {mode === 'create' ? 'creation' : 'update'}</Label>
<TogglePill bind:checked={startAfterCreate} />
@@ -87,6 +87,7 @@
let restartMaxRetries = $state<number | ''>('');
let networkMode = $state('bridge');
let startAfterUpdate = $state(true);
let repullImage = $state(true);
// Port mappings
let portMappings = $state<{ hostPort: string; containerPort: string; protocol: string }[]>([
@@ -894,6 +895,7 @@
networkMode,
networks: selectedNetworks.length > 0 ? selectedNetworks : undefined,
startAfterUpdate,
repullImage,
user: containerUser.trim() || undefined,
privileged: privilegedMode || undefined,
healthcheck,
@@ -1055,6 +1057,7 @@
bind:restartMaxRetries
bind:networkMode
startAfterCreate={startAfterUpdate}
{repullImage}
bind:portMappings
bind:volumeMappings
bind:envVars