mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-14 02:15:51 +00:00
fix(deployment): include commit in preview image tags
Generate pull request preview image tags with both the PR id and commit so different commits on the same PR do not reuse the same image tag. Sanitize and truncate generated tags to stay within Docker tag limits.
This commit is contained in:
1 parent
27b44fce4d
commit
2253c40e01
2 files changed
+131
-4
No files matched your search
@@ -1154,12 +1154,15 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
|
||||
$this->production_image_name = "{$this->dockerImage}:{$this->dockerImageTag}";
|
||||
}
|
||||
} elseif ($this->pull_request_id !== 0) {
|
||||
$previewImageTag = $this->previewImageTag();
|
||||
$previewBuildImageTag = $this->previewImageTag(build: true);
|
||||
|
||||
if ($this->application->docker_registry_image_name) {
|
||||
$this->build_image_name = "{$this->application->docker_registry_image_name}:pr-{$this->pull_request_id}-build";
|
||||
$this->production_image_name = "{$this->application->docker_registry_image_name}:pr-{$this->pull_request_id}";
|
||||
$this->build_image_name = "{$this->application->docker_registry_image_name}:{$previewBuildImageTag}";
|
||||
$this->production_image_name = "{$this->application->docker_registry_image_name}:{$previewImageTag}";
|
||||
} else {
|
||||
$this->build_image_name = "{$this->application->uuid}:pr-{$this->pull_request_id}-build";
|
||||
$this->production_image_name = "{$this->application->uuid}:pr-{$this->pull_request_id}";
|
||||
$this->build_image_name = "{$this->application->uuid}:{$previewBuildImageTag}";
|
||||
$this->production_image_name = "{$this->application->uuid}:{$previewImageTag}";
|
||||
}
|
||||
} else {
|
||||
$this->dockerImageTag = str($this->commit)->substr(0, 128);
|
||||
@@ -1176,6 +1179,23 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
|
||||
}
|
||||
}
|
||||
|
||||
private function previewImageTag(bool $build = false): string
|
||||
{
|
||||
$prefix = "pr-{$this->pull_request_id}-";
|
||||
$suffix = $build ? '-build' : '';
|
||||
$maxCommitLength = max(1, 128 - strlen($prefix) - strlen($suffix));
|
||||
$commit = Str::of($this->commit ?: 'HEAD')
|
||||
->replaceMatches('/[^A-Za-z0-9_.-]/', '-')
|
||||
->substr(0, $maxCommitLength)
|
||||
->toString();
|
||||
|
||||
if ($commit === '') {
|
||||
$commit = 'HEAD';
|
||||
}
|
||||
|
||||
return "{$prefix}{$commit}{$suffix}";
|
||||
}
|
||||
|
||||
private function just_restart()
|
||||
{
|
||||
$this->application_deployment_queue->addLogEntry("Restarting {$this->customRepository}:{$this->application->git_branch} on {$this->server->name}.");
|
||||
|
||||
Reference in new issue
Block a user