mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
Merge remote-tracking branch 'origin/main' into next
This commit is contained in:
@@ -31,6 +31,7 @@ class ConfigureCloudflared
|
||||
'interval' => '5s',
|
||||
'timeout' => '30s',
|
||||
'retries' => 5,
|
||||
'start_period' => '120s',
|
||||
],
|
||||
],
|
||||
],
|
||||
@@ -46,7 +47,7 @@ class ConfigureCloudflared
|
||||
'echo Stopping existing Cloudflare Tunnel container.',
|
||||
'docker rm -f coolify-cloudflared || true',
|
||||
'echo Starting new Cloudflare Tunnel container.',
|
||||
'docker compose up --wait --wait-timeout 15 --remove-orphans || docker logs coolify-cloudflared',
|
||||
'docker compose up --wait --wait-timeout 180 --remove-orphans || docker logs coolify-cloudflared',
|
||||
]);
|
||||
|
||||
return remote_process($commands, $server, callEventOnFinish: 'CloudflareTunnelChanged', callEventData: [
|
||||
|
||||
@@ -307,6 +307,43 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the --add-host flags for the containers on the destination network.
|
||||
*
|
||||
* Build helper containers are named after their deployment uuid and only live for the
|
||||
* duration of that deployment. BuildKit keys every RUN layer on the --add-host set,
|
||||
* so letting one in gives the next build a different set and forces a full rebuild.
|
||||
*/
|
||||
private function addHostFlags(Collection $containers): string
|
||||
{
|
||||
$containers = $containers->sort()->values();
|
||||
$buildHelperNames = ApplicationDeploymentQueue::query()
|
||||
->whereIn('deployment_uuid', $containers->pluck('Name')->filter())
|
||||
->pluck('deployment_uuid');
|
||||
|
||||
$ips = collect([]);
|
||||
foreach ($containers as $container) {
|
||||
$containerName = data_get($container, 'Name');
|
||||
if ($containerName === 'coolify-proxy') {
|
||||
continue;
|
||||
}
|
||||
if (isGeneratedContainerName($containerName)) {
|
||||
continue;
|
||||
}
|
||||
if ($buildHelperNames->contains($containerName)) {
|
||||
continue;
|
||||
}
|
||||
$containerIp = data_get($container, 'IPv4Address');
|
||||
if ($containerName && $containerIp) {
|
||||
$ips->put($containerName, str($containerIp)->before('/')->value());
|
||||
}
|
||||
}
|
||||
|
||||
return $ips->map(function ($ip, $name) {
|
||||
return "--add-host $name:$ip";
|
||||
})->implode(' ');
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
// Check if deployment was cancelled before we even started
|
||||
@@ -347,28 +384,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
|
||||
|
||||
if (! is_null($allContainers)) {
|
||||
$allContainers = format_docker_command_output_to_json($allContainers);
|
||||
$ips = collect([]);
|
||||
if (count($allContainers) > 0) {
|
||||
$allContainers = $allContainers[0];
|
||||
$allContainers = collect($allContainers)->sort()->values();
|
||||
foreach ($allContainers as $container) {
|
||||
$containerName = data_get($container, 'Name');
|
||||
if ($containerName === 'coolify-proxy') {
|
||||
continue;
|
||||
}
|
||||
if (isGeneratedContainerName($containerName)) {
|
||||
continue;
|
||||
}
|
||||
$containerIp = data_get($container, 'IPv4Address');
|
||||
if ($containerName && $containerIp) {
|
||||
$containerIp = str($containerIp)->before('/');
|
||||
$ips->put($containerName, $containerIp->value());
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->addHosts = $ips->map(function ($ip, $name) {
|
||||
return "--add-host $name:$ip";
|
||||
})->implode(' ');
|
||||
$this->addHosts = count($allContainers) > 0 ? $this->addHostFlags(collect($allContainers[0])) : '';
|
||||
}
|
||||
|
||||
if ($this->application->dockerfile_target_build) {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use App\Jobs\ApplicationDeploymentJob;
|
||||
use App\Models\ApplicationDeploymentQueue;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
function addHostFlagsFor(array $containers): string
|
||||
{
|
||||
$job = (new ReflectionClass(ApplicationDeploymentJob::class))->newInstanceWithoutConstructor();
|
||||
|
||||
return (new ReflectionMethod(ApplicationDeploymentJob::class, 'addHostFlags'))->invoke($job, collect($containers));
|
||||
}
|
||||
|
||||
it('keeps build helper containers of other deployments out of --add-host', function () {
|
||||
ApplicationDeploymentQueue::create(['application_id' => '1', 'deployment_uuid' => 'k0s8g4wc4c8gkkso0gk4cgww']);
|
||||
|
||||
$flags = addHostFlagsFor([
|
||||
'a' => ['Name' => 'redis-db', 'IPv4Address' => '10.0.1.5/24'],
|
||||
'b' => ['Name' => 'k0s8g4wc4c8gkkso0gk4cgww', 'IPv4Address' => '10.0.1.9/24'],
|
||||
'c' => ['Name' => 'coolify-proxy', 'IPv4Address' => '10.0.1.2/24'],
|
||||
'd' => ['Name' => 'app-uuid-20260908T141530', 'IPv4Address' => '10.0.1.7/24'],
|
||||
]);
|
||||
|
||||
expect($flags)->toBe('--add-host redis-db:10.0.1.5');
|
||||
});
|
||||
|
||||
it('keeps the --add-host set stable whether or not a build helper is running', function () {
|
||||
ApplicationDeploymentQueue::create(['application_id' => '1', 'deployment_uuid' => 'helper-deployment-uuid']);
|
||||
$database = ['Name' => 'postgres-main', 'IPv4Address' => '10.0.1.3/24'];
|
||||
|
||||
expect(addHostFlagsFor([$database, ['Name' => 'helper-deployment-uuid', 'IPv4Address' => '10.0.1.4/24']]))
|
||||
->toBe(addHostFlagsFor([$database]))
|
||||
->toBe('--add-host postgres-main:10.0.1.3');
|
||||
});
|
||||
Reference in New Issue
Block a user