From 62df33ba3ded6279d49eca13df4de4f3d656fd8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8F=94=EF=B8=8F=20Peak?= <122374094+peaklabs-dev@users.noreply.github.com> Date: Wed, 9 Sep 2026 15:01:53 +0200 Subject: [PATCH] feat(docker): use ISO 8601 timestamp suffix for generated container names (#11702) --- app/Jobs/ApplicationDeploymentJob.php | 2 +- bootstrap/helpers/docker.php | 16 +++++++++++++++- .../ApplicationDeploymentContainerNamingTest.php | 9 +++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 2eb6aa41b5..3a53d87a72 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -339,7 +339,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue if ($containerName === 'coolify-proxy') { continue; } - if (preg_match('/-(\d{12})/', $containerName)) { + if (isGeneratedContainerName($containerName)) { continue; } $containerIp = data_get($container, 'IPv4Address'); diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php index d1b02b8cf4..38cf3fefc4 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -350,7 +350,7 @@ function generateApplicationContainerName(Application $application, $pull_reques $consistent_container_name = $application->settings->is_consistent_container_name_enabled; $name = $consistent_container_name ? ($application->settings->custom_internal_name ?: $application->uuid) : $application->uuid; - $now = now()->format('Hisu'); + $now = now()->format('Ymd\THis'); if ($pull_request_id !== 0 && $pull_request_id !== null) { return $name.'-pr-'.$pull_request_id; } else { @@ -361,6 +361,20 @@ function generateApplicationContainerName(Application $application, $pull_reques return $application->uuid.'-'.$now; } } + +/** + * Generated (rolling update) container names end with the timestamp from generateApplicationContainerName(). + * Drop the legacy pattern once containers created before the ISO 8601 suffix are gone. + */ +function isGeneratedContainerName(string $containerName): bool +{ + $isoTimestampSuffix = '/-\d{8}T\d{6}$/'; + $legacyTimestampSuffix = '/-\d{12}$/'; + + return preg_match($isoTimestampSuffix, $containerName) === 1 + || preg_match($legacyTimestampSuffix, $containerName) === 1; +} + function get_port_from_dockerfile($dockerfile): ?int { $dockerfile_array = explode("\n", $dockerfile); diff --git a/tests/Unit/ApplicationDeploymentContainerNamingTest.php b/tests/Unit/ApplicationDeploymentContainerNamingTest.php index 68c47013f4..1a268d4f38 100644 --- a/tests/Unit/ApplicationDeploymentContainerNamingTest.php +++ b/tests/Unit/ApplicationDeploymentContainerNamingTest.php @@ -55,3 +55,12 @@ it('ignores the custom container name when consistent naming is disabled', funct expect(generateApplicationContainerName($application))->toStartWith('application-uuid-'); }); + +it('recognises generated container names in both timestamp formats', function () { + expect(isGeneratedContainerName('application-uuid-20260908T141530'))->toBeTrue() + ->and(isGeneratedContainerName('my-api-20260908T141530'))->toBeTrue() + ->and(isGeneratedContainerName('application-uuid-192238854305'))->toBeTrue() + ->and(isGeneratedContainerName('application-uuid'))->toBeFalse() + ->and(isGeneratedContainerName('application-uuid-pr-42'))->toBeFalse() + ->and(isGeneratedContainerName('my-api'))->toBeFalse(); +});