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(deployments): honor selected Docker image rollback tag (#11480)

Andras Bacsai5f5f30556978
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index 1e8450c1b9..451d4377c2 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -614,6 +614,10 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
return $this->dockerImagePreviewTag;
}
+ if ($this->rollback && str($this->commit)->isNotEmpty()) {
+ return $this->commit;
+ }
+
if (str($this->application->docker_registry_image_tag)->isNotEmpty()) {
return $this->application->docker_registry_image_tag;
}
diff --git a/tests/Unit/DockerImagePreviewTagResolutionTest.php b/tests/Unit/DockerImagePreviewTagResolutionTest.php
index 17f7d7b9b4..bb9a2c09dd 100644
--- a/tests/Unit/DockerImagePreviewTagResolutionTest.php
+++ b/tests/Unit/DockerImagePreviewTagResolutionTest.php
@@ -27,6 +27,102 @@ it('prefers the preview specific docker image tag for preview deployments', func
expect($method->invoke($job))->toBe('pr_42');
});
+it('prefers the selected tag for docker image rollback deployments', function () {
+ $reflection = new ReflectionClass(ApplicationDeploymentJob::class);
+ $job = $reflection->newInstanceWithoutConstructor();
+
+ $pullRequestProperty = $reflection->getProperty('pull_request_id');
+ $pullRequestProperty->setAccessible(true);
+ $pullRequestProperty->setValue($job, 0);
+
+ $rollbackProperty = $reflection->getProperty('rollback');
+ $rollbackProperty->setAccessible(true);
+ $rollbackProperty->setValue($job, true);
+
+ $commitProperty = $reflection->getProperty('commit');
+ $commitProperty->setAccessible(true);
+ $commitProperty->setValue($job, 'e487515a098c8d4f69c74712f1d0cc86e483e890');
+
+ $applicationProperty = $reflection->getProperty('application');
+ $applicationProperty->setAccessible(true);
+ $applicationProperty->setValue($job, new Application([
+ 'docker_registry_image_tag' => '6de68657a0e794e163ea2275c54c293a93fe065a',
+ ]));
+
+ $previewTagProperty = $reflection->getProperty('dockerImagePreviewTag');
+ $previewTagProperty->setAccessible(true);
+ $previewTagProperty->setValue($job, null);
+
+ $method = $reflection->getMethod('resolveDockerImageTag');
+ $method->setAccessible(true);
+
+ expect($method->invoke($job))->toBe('e487515a098c8d4f69c74712f1d0cc86e483e890');
+});
+
+it('falls back to the application docker image tag for rollbacks without a selected tag', function () {
+ $reflection = new ReflectionClass(ApplicationDeploymentJob::class);
+ $job = $reflection->newInstanceWithoutConstructor();
+
+ $pullRequestProperty = $reflection->getProperty('pull_request_id');
+ $pullRequestProperty->setAccessible(true);
+ $pullRequestProperty->setValue($job, 0);
+
+ $rollbackProperty = $reflection->getProperty('rollback');
+ $rollbackProperty->setAccessible(true);
+ $rollbackProperty->setValue($job, true);
+
+ $commitProperty = $reflection->getProperty('commit');
+ $commitProperty->setAccessible(true);
+ $commitProperty->setValue($job, '');
+
+ $applicationProperty = $reflection->getProperty('application');
+ $applicationProperty->setAccessible(true);
+ $applicationProperty->setValue($job, new Application([
+ 'docker_registry_image_tag' => 'stable',
+ ]));
+
+ $previewTagProperty = $reflection->getProperty('dockerImagePreviewTag');
+ $previewTagProperty->setAccessible(true);
+ $previewTagProperty->setValue($job, null);
+
+ $method = $reflection->getMethod('resolveDockerImageTag');
+ $method->setAccessible(true);
+
+ expect($method->invoke($job))->toBe('stable');
+});
+
+it('falls back to latest for rollbacks without selected or configured tags', function () {
+ $reflection = new ReflectionClass(ApplicationDeploymentJob::class);
+ $job = $reflection->newInstanceWithoutConstructor();
+
+ $pullRequestProperty = $reflection->getProperty('pull_request_id');
+ $pullRequestProperty->setAccessible(true);
+ $pullRequestProperty->setValue($job, 0);
+
+ $rollbackProperty = $reflection->getProperty('rollback');
+ $rollbackProperty->setAccessible(true);
+ $rollbackProperty->setValue($job, true);
+
+ $commitProperty = $reflection->getProperty('commit');
+ $commitProperty->setAccessible(true);
+ $commitProperty->setValue($job, '');
+
+ $applicationProperty = $reflection->getProperty('application');
+ $applicationProperty->setAccessible(true);
+ $applicationProperty->setValue($job, new Application([
+ 'docker_registry_image_tag' => '',
+ ]));
+
+ $previewTagProperty = $reflection->getProperty('dockerImagePreviewTag');
+ $previewTagProperty->setAccessible(true);
+ $previewTagProperty->setValue($job, null);
+
+ $method = $reflection->getMethod('resolveDockerImageTag');
+ $method->setAccessible(true);
+
+ expect($method->invoke($job))->toBe('latest');
+});
+
it('falls back to the application docker image tag for non preview deployments', function () {
$reflection = new ReflectionClass(ApplicationDeploymentJob::class);
$job = $reflection->newInstanceWithoutConstructor();
@@ -35,6 +131,10 @@ it('falls back to the application docker image tag for non preview deployments',
$pullRequestProperty->setAccessible(true);
$pullRequestProperty->setValue($job, 0);
+ $rollbackProperty = $reflection->getProperty('rollback');
+ $rollbackProperty->setAccessible(true);
+ $rollbackProperty->setValue($job, false);
+
$applicationProperty = $reflection->getProperty('application');
$applicationProperty->setAccessible(true);
$applicationProperty->setValue($job, new Application([
@@ -59,6 +159,10 @@ it('falls back to latest when neither preview nor application tags are set', fun
$pullRequestProperty->setAccessible(true);
$pullRequestProperty->setValue($job, 7);
+ $rollbackProperty = $reflection->getProperty('rollback');
+ $rollbackProperty->setAccessible(true);
+ $rollbackProperty->setValue($job, false);
+
$applicationProperty = $reflection->getProperty('application');
$applicationProperty->setAccessible(true);
$applicationProperty->setValue($job, new Application([