Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix(upgrade): persist target image before container recreation (#11401)

Andras Bacsaic3a86b054a78
diff --git a/other/nightly/upgrade.sh b/other/nightly/upgrade.sh
index 94fb77607f..c5f38df6e0 100644
--- a/other/nightly/upgrade.sh
+++ b/other/nightly/upgrade.sh
@@ -216,6 +216,9 @@ done
log "All images pulled successfully"
echo " All images pulled successfully."
+set_env_var "LATEST_IMAGE" "$LATEST_IMAGE"
+set_env_var "COOLIFY_VERSION" "$LATEST_IMAGE"
+
log_section "Step 4/6: Stopping and restarting containers"
write_status "4" "Stopping containers"
echo ""
diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh
index 516a9d7ebc..5baac23acb 100644
--- a/scripts/upgrade.sh
+++ b/scripts/upgrade.sh
@@ -229,6 +229,9 @@ done
log "All images pulled successfully"
echo " All images pulled successfully."
+set_env_var "LATEST_IMAGE" "$LATEST_IMAGE"
+set_env_var "COOLIFY_VERSION" "$LATEST_IMAGE"
+
log_section "Step 4/6: Stopping and restarting containers"
write_status "4" "Stopping containers"
echo ""
diff --git a/tests/Unit/UpgradePostgresScriptTest.php b/tests/Unit/UpgradePostgresScriptTest.php
index a888bc3a41..677a8fec3e 100644
--- a/tests/Unit/UpgradePostgresScriptTest.php
+++ b/tests/Unit/UpgradePostgresScriptTest.php
@@ -62,6 +62,35 @@ it('persists the selected registry url during upgrades', function (string $path)
'nightly upgrade' => 'other/nightly/upgrade.sh',
]);
+it('persists the target image and runtime version before recreating containers', function (string $path) {
+ $script = file_get_contents(getcwd().'/'.$path);
+ if ($script === false) {
+ throw new RuntimeException("Unable to read {$path}");
+ }
+
+ $position = static function (string $needle) use ($script): int {
+ $offset = strpos($script, $needle);
+ if ($offset === false) {
+ throw new RuntimeException("Missing marker: {$needle}");
+ }
+
+ return $offset;
+ };
+
+ $latestImagePosition = $position('set_env_var "LATEST_IMAGE" "$LATEST_IMAGE"');
+ $coolifyVersionPosition = $position('set_env_var "COOLIFY_VERSION" "$LATEST_IMAGE"');
+ $imagesPulledPosition = $position('log "All images pulled successfully"');
+ $composeUpPosition = $position('docker compose --env-file /data/coolify/source/.env');
+
+ expect($latestImagePosition)->toBeGreaterThan($imagesPulledPosition)
+ ->and($coolifyVersionPosition)->toBeGreaterThan($imagesPulledPosition)
+ ->and($latestImagePosition)->toBeLessThan($composeUpPosition)
+ ->and($coolifyVersionPosition)->toBeLessThan($composeUpPosition);
+})->with([
+ 'stable upgrade' => 'scripts/upgrade.sh',
+ 'nightly upgrade' => 'other/nightly/upgrade.sh',
+]);
+
it('uses the existing env registry url when old callers do not pass a registry argument', function (string $path) {
$script = file_get_contents(getcwd().'/'.$path);