mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-14 04:15:55 +00:00
Merge remote-tracking branch 'origin/next' into fix/ssh-sporadic-permission-denied
This commit is contained in:
commit
fe1aa94144
34 files changed
+390
-45
No files matched your search
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Models\ApplicationPreview;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('populates fqdn from docker_compose_domains after generate_preview_fqdn_compose', function () {
|
||||
$application = Application::factory()->create([
|
||||
'build_pack' => 'dockercompose',
|
||||
'docker_compose_domains' => json_encode([
|
||||
'web' => ['domain' => 'https://example.com'],
|
||||
]),
|
||||
]);
|
||||
|
||||
$preview = ApplicationPreview::create([
|
||||
'application_id' => $application->id,
|
||||
'pull_request_id' => 42,
|
||||
'docker_compose_domains' => $application->docker_compose_domains,
|
||||
]);
|
||||
|
||||
$preview->generate_preview_fqdn_compose();
|
||||
|
||||
$preview->refresh();
|
||||
|
||||
expect($preview->fqdn)->not->toBeNull();
|
||||
expect($preview->fqdn)->toContain('42');
|
||||
expect($preview->fqdn)->toContain('example.com');
|
||||
});
|
||||
|
||||
it('populates fqdn with multiple domains from multiple services', function () {
|
||||
$application = Application::factory()->create([
|
||||
'build_pack' => 'dockercompose',
|
||||
'docker_compose_domains' => json_encode([
|
||||
'web' => ['domain' => 'https://web.example.com'],
|
||||
'api' => ['domain' => 'https://api.example.com'],
|
||||
]),
|
||||
]);
|
||||
|
||||
$preview = ApplicationPreview::create([
|
||||
'application_id' => $application->id,
|
||||
'pull_request_id' => 7,
|
||||
'docker_compose_domains' => $application->docker_compose_domains,
|
||||
]);
|
||||
|
||||
$preview->generate_preview_fqdn_compose();
|
||||
|
||||
$preview->refresh();
|
||||
|
||||
expect($preview->fqdn)->not->toBeNull();
|
||||
$domains = explode(',', $preview->fqdn);
|
||||
expect($domains)->toHaveCount(2);
|
||||
expect($preview->fqdn)->toContain('web.example.com');
|
||||
expect($preview->fqdn)->toContain('api.example.com');
|
||||
});
|
||||
|
||||
it('sets fqdn to null when no domains are configured', function () {
|
||||
$application = Application::factory()->create([
|
||||
'build_pack' => 'dockercompose',
|
||||
'docker_compose_domains' => json_encode([
|
||||
'web' => ['domain' => ''],
|
||||
]),
|
||||
]);
|
||||
|
||||
$preview = ApplicationPreview::create([
|
||||
'application_id' => $application->id,
|
||||
'pull_request_id' => 99,
|
||||
'docker_compose_domains' => $application->docker_compose_domains,
|
||||
]);
|
||||
|
||||
$preview->generate_preview_fqdn_compose();
|
||||
|
||||
$preview->refresh();
|
||||
|
||||
expect($preview->fqdn)->toBeNull();
|
||||
});
|
||||
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
use App\Livewire\Server\ValidateAndInstall;
|
||||
use App\Models\Server;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
@@ -94,3 +96,24 @@ it('can overwrite server_metadata with new values', function () {
|
||||
expect($this->server->server_metadata['os'])->toBe('Ubuntu 22.04')
|
||||
->and($this->server->server_metadata['cpus'])->toBe(4);
|
||||
});
|
||||
|
||||
it('calls gatherServerMetadata during ValidateAndInstall when docker version is valid', function () {
|
||||
$serverMock = Mockery::mock($this->server)->makePartial();
|
||||
$serverMock->shouldReceive('isSwarm')->andReturn(false);
|
||||
$serverMock->shouldReceive('validateDockerEngineVersion')->once()->andReturn('24.0.0');
|
||||
$serverMock->shouldReceive('gatherServerMetadata')->once();
|
||||
$serverMock->shouldReceive('isBuildServer')->andReturn(false);
|
||||
|
||||
Livewire::test(ValidateAndInstall::class, ['server' => $serverMock])
|
||||
->call('validateDockerVersion');
|
||||
});
|
||||
|
||||
it('does not call gatherServerMetadata when docker version validation fails', function () {
|
||||
$serverMock = Mockery::mock($this->server)->makePartial();
|
||||
$serverMock->shouldReceive('isSwarm')->andReturn(false);
|
||||
$serverMock->shouldReceive('validateDockerEngineVersion')->once()->andReturn(false);
|
||||
$serverMock->shouldNotReceive('gatherServerMetadata');
|
||||
|
||||
Livewire::test(ValidateAndInstall::class, ['server' => $serverMock])
|
||||
->call('validateDockerVersion');
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
use App\Models\InstanceSettings;
|
||||
use App\Models\Project;
|
||||
use App\Models\Server;
|
||||
use App\Models\Service;
|
||||
use App\Models\StandaloneDocker;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
InstanceSettings::create(['id' => 0, 'is_api_enabled' => true]);
|
||||
|
||||
$this->team = Team::factory()->create();
|
||||
$this->user = User::factory()->create();
|
||||
$this->team->members()->attach($this->user->id, ['role' => 'owner']);
|
||||
|
||||
session(['currentTeam' => $this->team]);
|
||||
|
||||
$this->token = $this->user->createToken('test-token', ['*']);
|
||||
$this->bearerToken = $this->token->plainTextToken;
|
||||
|
||||
$this->server = Server::factory()->create(['team_id' => $this->team->id]);
|
||||
$this->destination = StandaloneDocker::where('server_id', $this->server->id)->first();
|
||||
$this->project = Project::factory()->create(['team_id' => $this->team->id]);
|
||||
$this->environment = $this->project->environments()->first();
|
||||
});
|
||||
|
||||
function serviceContainerLabelAuthHeaders($bearerToken): array
|
||||
{
|
||||
return [
|
||||
'Authorization' => 'Bearer '.$bearerToken,
|
||||
'Content-Type' => 'application/json',
|
||||
];
|
||||
}
|
||||
|
||||
describe('PATCH /api/v1/services/{uuid}', function () {
|
||||
test('accepts is_container_label_escape_enabled field', function () {
|
||||
$service = Service::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'destination_id' => $this->destination->id,
|
||||
'destination_type' => $this->destination->getMorphClass(),
|
||||
'environment_id' => $this->environment->id,
|
||||
]);
|
||||
|
||||
$response = $this->withHeaders(serviceContainerLabelAuthHeaders($this->bearerToken))
|
||||
->patchJson("/api/v1/services/{$service->uuid}", [
|
||||
'is_container_label_escape_enabled' => false,
|
||||
]);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$service->refresh();
|
||||
expect($service->is_container_label_escape_enabled)->toBeFalse();
|
||||
});
|
||||
|
||||
test('rejects invalid is_container_label_escape_enabled value', function () {
|
||||
$service = Service::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'destination_id' => $this->destination->id,
|
||||
'destination_type' => $this->destination->getMorphClass(),
|
||||
'environment_id' => $this->environment->id,
|
||||
]);
|
||||
|
||||
$response = $this->withHeaders(serviceContainerLabelAuthHeaders($this->bearerToken))
|
||||
->patchJson("/api/v1/services/{$service->uuid}", [
|
||||
'is_container_label_escape_enabled' => 'not-a-boolean',
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
});
|
||||
});
|
||||
@@ -75,6 +75,55 @@ it('uses host paths for env-file when preserveRepository is true', function () {
|
||||
expect($startCommand)->toContain("-f {$serverWorkdir}{$composeLocation}");
|
||||
});
|
||||
|
||||
it('injects --project-directory with host path when preserveRepository is true', function () {
|
||||
$serverWorkdir = '/data/coolify/applications/app-uuid';
|
||||
$containerWorkdir = '/artifacts/deployment-uuid';
|
||||
$preserveRepository = true;
|
||||
|
||||
$customStartCommand = 'docker compose -f docker-compose.yaml -f docker-compose.prod.yaml up -d';
|
||||
|
||||
// Simulate the --project-directory injection from deploy_docker_compose_buildpack()
|
||||
if (! str($customStartCommand)->contains('--project-directory')) {
|
||||
$projectDir = $preserveRepository ? $serverWorkdir : $containerWorkdir;
|
||||
$customStartCommand = str($customStartCommand)->replaceFirst('compose', 'compose --project-directory '.$projectDir)->value();
|
||||
}
|
||||
|
||||
// When preserveRepository is true, --project-directory must point to host path
|
||||
expect($customStartCommand)->toContain("--project-directory {$serverWorkdir}");
|
||||
expect($customStartCommand)->not->toContain('/artifacts/');
|
||||
});
|
||||
|
||||
it('injects --project-directory with container path when preserveRepository is false', function () {
|
||||
$serverWorkdir = '/data/coolify/applications/app-uuid';
|
||||
$containerWorkdir = '/artifacts/deployment-uuid';
|
||||
$preserveRepository = false;
|
||||
|
||||
$customStartCommand = 'docker compose -f docker-compose.yaml -f docker-compose.prod.yaml up -d';
|
||||
|
||||
// Simulate the --project-directory injection from deploy_docker_compose_buildpack()
|
||||
if (! str($customStartCommand)->contains('--project-directory')) {
|
||||
$projectDir = $preserveRepository ? $serverWorkdir : $containerWorkdir;
|
||||
$customStartCommand = str($customStartCommand)->replaceFirst('compose', 'compose --project-directory '.$projectDir)->value();
|
||||
}
|
||||
|
||||
// When preserveRepository is false, --project-directory must point to container path
|
||||
expect($customStartCommand)->toContain("--project-directory {$containerWorkdir}");
|
||||
expect($customStartCommand)->not->toContain('/data/coolify/applications/');
|
||||
});
|
||||
|
||||
it('does not override explicit --project-directory in custom start command', function () {
|
||||
$customProjectDir = '/custom/path';
|
||||
$customStartCommand = "docker compose --project-directory {$customProjectDir} up -d";
|
||||
|
||||
// Simulate the --project-directory injection — should be skipped
|
||||
if (! str($customStartCommand)->contains('--project-directory')) {
|
||||
$customStartCommand = str($customStartCommand)->replaceFirst('compose', 'compose --project-directory /should-not-appear')->value();
|
||||
}
|
||||
|
||||
expect($customStartCommand)->toContain("--project-directory {$customProjectDir}");
|
||||
expect($customStartCommand)->not->toContain('/should-not-appear');
|
||||
});
|
||||
|
||||
it('uses container paths for env-file when preserveRepository is false', function () {
|
||||
$workdir = '/artifacts/deployment-uuid/backend';
|
||||
$composeLocation = '/compose.yml';
|
||||
|
||||
Reference in new issue
Block a user