mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-14 10:18:20 +00:00
Merge remote-tracking branch 'origin/next' into v5-parallel-inertia-react
This commit is contained in:
commit
a2fc08a7b3
36 files changed
+305
-966
No files matched your search
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
use App\Jobs\ApplicationDeploymentJob;
|
||||
use App\Models\Application;
|
||||
use App\Models\ApplicationDeploymentQueue;
|
||||
use App\Models\Environment;
|
||||
use App\Models\InstanceSettings;
|
||||
use App\Models\Project;
|
||||
use App\Models\Server;
|
||||
use App\Models\StandaloneDocker;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Testing\Fluent\AssertableJson;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
Bus::fake([ApplicationDeploymentJob::class]);
|
||||
|
||||
InstanceSettings::unguarded(fn () => InstanceSettings::query()->updateOrCreate(
|
||||
['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('deployment-actions-test', ['deploy'])->plainTextToken;
|
||||
|
||||
$this->server = Server::factory()->create(['team_id' => $this->team->id]);
|
||||
$this->destination = StandaloneDocker::query()->where('server_id', $this->server->id)->firstOrFail();
|
||||
$this->project = Project::factory()->create(['team_id' => $this->team->id]);
|
||||
$this->environment = Environment::factory()->create(['project_id' => $this->project->id]);
|
||||
});
|
||||
|
||||
function deploymentActionHeaders(string $token): array
|
||||
{
|
||||
return [
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
'Content-Type' => 'application/json',
|
||||
];
|
||||
}
|
||||
|
||||
function makeDeploymentActionApplication(Environment $environment, StandaloneDocker $destination): Application
|
||||
{
|
||||
return Application::factory()->create([
|
||||
'environment_id' => $environment->id,
|
||||
'destination_id' => $destination->id,
|
||||
'destination_type' => $destination->getMorphClass(),
|
||||
'git_repository' => 'https://github.com/coollabsio/coolify',
|
||||
'git_branch' => 'main',
|
||||
'git_commit_sha' => 'HEAD',
|
||||
]);
|
||||
}
|
||||
|
||||
test('application start API returns queued deployment uuid as a string', function () {
|
||||
$application = makeDeploymentActionApplication($this->environment, $this->destination);
|
||||
|
||||
$response = $this->withHeaders(deploymentActionHeaders($this->token))
|
||||
->postJson("/api/v1/applications/{$application->uuid}/start");
|
||||
|
||||
$response->assertSuccessful()
|
||||
->assertJson(fn (AssertableJson $json) => $json
|
||||
->where('message', 'Deployment request queued.')
|
||||
->whereType('deployment_uuid', 'string')
|
||||
);
|
||||
|
||||
expect(ApplicationDeploymentQueue::query()->where('deployment_uuid', $response->json('deployment_uuid'))->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
test('application restart API returns queued deployment uuid as a string', function () {
|
||||
$application = makeDeploymentActionApplication($this->environment, $this->destination);
|
||||
|
||||
$response = $this->withHeaders(deploymentActionHeaders($this->token))
|
||||
->postJson("/api/v1/applications/{$application->uuid}/restart");
|
||||
|
||||
$response->assertSuccessful()
|
||||
->assertJson(fn (AssertableJson $json) => $json
|
||||
->where('message', 'Restart request queued.')
|
||||
->whereType('deployment_uuid', 'string')
|
||||
);
|
||||
|
||||
$deployment = ApplicationDeploymentQueue::query()
|
||||
->where('deployment_uuid', $response->json('deployment_uuid'))
|
||||
->first();
|
||||
|
||||
expect($deployment)->not->toBeNull()
|
||||
->and($deployment->restart_only)->toBeTruthy();
|
||||
});
|
||||
|
||||
test('deployment uuid strings are not converted as objects in API and webhook controllers', function () {
|
||||
$files = [
|
||||
app_path('Http/Controllers/Api/DeployController.php'),
|
||||
app_path('Http/Controllers/Webhook/Bitbucket.php'),
|
||||
app_path('Http/Controllers/Webhook/Gitea.php'),
|
||||
app_path('Http/Controllers/Webhook/Gitlab.php'),
|
||||
];
|
||||
|
||||
foreach ($files as $file) {
|
||||
expect(file_get_contents($file))
|
||||
->not->toContain('$deployment_uuid->toString()')
|
||||
->not->toContain('$deployment_uuid?->toString()');
|
||||
}
|
||||
});
|
||||
@@ -180,7 +180,7 @@ test('convertContainerEnvsToArray', function () {
|
||||
"OpenStdin": false,
|
||||
"StdinOnce": false,
|
||||
"Env": [
|
||||
"RAY_ENABLED=true=123",
|
||||
"FEATURE_FLAG_WITH_EQUALS=true=123",
|
||||
"REGISTRY_URL=docker.io",
|
||||
"SUBSCRIPTION_PROVIDER=stripe",
|
||||
"TELESCOPE_ENABLED=false",
|
||||
@@ -295,5 +295,5 @@ test('convertContainerEnvsToArray', function () {
|
||||
}
|
||||
]';
|
||||
$envs = format_docker_envs_to_json($data);
|
||||
$this->assertEquals('true=123', $envs->get('RAY_ENABLED'));
|
||||
$this->assertEquals('true=123', $envs->get('FEATURE_FLAG_WITH_EQUALS'));
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Models\EnvironmentVariable;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('stores null environment variable values as database null', function () {
|
||||
$env = EnvironmentVariable::create([
|
||||
'key' => 'NULL_VALUE',
|
||||
'value' => null,
|
||||
'resourceable_type' => Application::class,
|
||||
'resourceable_id' => 1,
|
||||
]);
|
||||
|
||||
$rawValue = DB::table('environment_variables')
|
||||
->where('id', $env->id)
|
||||
->value('value');
|
||||
|
||||
expect($rawValue)->toBeNull();
|
||||
|
||||
$env->refresh();
|
||||
expect($env->value)->toBeNull();
|
||||
});
|
||||
|
||||
it('preserves intentional empty string environment variable values', function () {
|
||||
$env = EnvironmentVariable::create([
|
||||
'key' => 'EMPTY_STRING_VALUE',
|
||||
'value' => '',
|
||||
'resourceable_type' => Application::class,
|
||||
'resourceable_id' => 1,
|
||||
]);
|
||||
|
||||
$rawValue = DB::table('environment_variables')
|
||||
->where('id', $env->id)
|
||||
->value('value');
|
||||
|
||||
expect($rawValue)->not->toBeNull()
|
||||
->and(decrypt($rawValue))->toBe('');
|
||||
|
||||
$env->refresh();
|
||||
expect($env->value)->toBe('');
|
||||
});
|
||||
@@ -218,7 +218,7 @@ describe('security UI audit logging', function () {
|
||||
|
||||
test('cloud provider token form does not contain debug ray calls', function () {
|
||||
expect(file_get_contents(app_path('Livewire/Security/CloudProviderTokenForm.php')))
|
||||
->not->toContain('ray(');
|
||||
->not->toContain('ray'.'(');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -95,6 +95,6 @@ it('ensures docker_compose_raw update is wrapped in try-catch for error handling
|
||||
->toContain('// This keeps the original user input clean while preventing content reapplication')
|
||||
->toContain('try {')
|
||||
->toContain('$originalYaml = Yaml::parse($originalCompose);')
|
||||
->toContain('} catch (\Exception $e) {')
|
||||
->toContain("ray('Failed to update docker_compose_raw");
|
||||
->toContain('} catch (Exception) {')
|
||||
->toContain('// If parsing fails, keep the original docker_compose_raw unchanged');
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
function rayRemovalFiles(string $directory): array
|
||||
{
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
|
||||
$files = [];
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
if ($file->isFile() && $file->getExtension() === 'php') {
|
||||
$files[] = $file->getPathname();
|
||||
}
|
||||
}
|
||||
|
||||
sort($files);
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
function rayRemovalBasePath(string $path = ''): string
|
||||
{
|
||||
return dirname(__DIR__, 2).($path === '' ? '' : DIRECTORY_SEPARATOR.$path);
|
||||
}
|
||||
|
||||
it('does not include Ray as a dependency', function () {
|
||||
$composer = json_decode(file_get_contents(rayRemovalBasePath('composer.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$lock = json_decode(file_get_contents(rayRemovalBasePath('composer.lock')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$lockedPackageNames = collect([
|
||||
...($lock['packages'] ?? []),
|
||||
...($lock['packages-dev'] ?? []),
|
||||
])->pluck('name');
|
||||
|
||||
expect($composer['require'] ?? [])->not->toHaveKey('spatie/laravel-ray')
|
||||
->and($composer['require-dev'] ?? [])->not->toHaveKey('spatie/laravel-ray')
|
||||
->and($lockedPackageNames)->not->toContain('spatie/laravel-ray', 'spatie/ray');
|
||||
});
|
||||
|
||||
it('does not ship Ray configuration', function () {
|
||||
expect(file_exists(rayRemovalBasePath('config/ray.php')))->toBeFalse();
|
||||
});
|
||||
|
||||
it('does not call ray from application code', function () {
|
||||
$files = [
|
||||
...rayRemovalFiles(rayRemovalBasePath('app')),
|
||||
...rayRemovalFiles(rayRemovalBasePath('bootstrap/helpers')),
|
||||
];
|
||||
|
||||
$rayCalls = collect($files)
|
||||
->filter(fn (string $file): bool => preg_match('/\bray\s*\(/', file_get_contents($file)) === 1)
|
||||
->map(fn (string $file): string => str_replace(rayRemovalBasePath().'/', '', $file))
|
||||
->values();
|
||||
|
||||
expect($rayCalls)->toBeEmpty();
|
||||
});
|
||||
Reference in new issue
Block a user