mirror of
https://github.com/tiennm99/coolify.git
synced 2026-08-20 04:23:34 +00:00
Merge remote-tracking branch 'origin/next' into v5-parallel-inertia-react
This commit is contained in:
@@ -20,14 +20,33 @@ class DevelopmentRailpackExamplesSeeder extends Seeder
|
||||
{
|
||||
public const PROJECT_UUID = 'railpack-examples';
|
||||
|
||||
public const ENVIRONMENT_UUID = 'railpack-examples-production';
|
||||
|
||||
public const GIT_REPOSITORY = 'coollabsio/coolify-examples';
|
||||
|
||||
public const GIT_BRANCH = 'next';
|
||||
|
||||
public const REPOSITORY_PROJECT_ID = 603035348;
|
||||
|
||||
public const LIMA_SERVERS = [
|
||||
[
|
||||
'server_uuid' => 'lima-ubuntu-2404',
|
||||
'server_name' => 'lima-ubuntu-2404',
|
||||
'port' => 2222,
|
||||
'environment_name' => 'ubuntu24',
|
||||
'environment_uuid' => 'railpack-examples-ubuntu24',
|
||||
'uuid_prefix' => 'ubuntu24-',
|
||||
],
|
||||
[
|
||||
'server_uuid' => 'lima-ubuntu-2604',
|
||||
'server_name' => 'lima-ubuntu-2604',
|
||||
'port' => 2223,
|
||||
'environment_name' => 'ubuntu26',
|
||||
'environment_uuid' => 'railpack-examples-ubuntu26',
|
||||
'uuid_prefix' => 'ubuntu26-',
|
||||
],
|
||||
];
|
||||
|
||||
private const LIMA_SENTINEL_URL = 'http://host.lima.internal:8000';
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
if (! $this->isDevelopmentEnvironment()) {
|
||||
@@ -37,16 +56,22 @@ class DevelopmentRailpackExamplesSeeder extends Seeder
|
||||
}
|
||||
|
||||
$this->ensureDevelopmentPrerequisitesExist();
|
||||
$destination = StandaloneDocker::query()->find(0);
|
||||
|
||||
if (! $destination) {
|
||||
if (! StandaloneDocker::query()->find(0)) {
|
||||
throw new RuntimeException('StandaloneDocker with id=0 is required before running DevelopmentRailpackExamplesSeeder.');
|
||||
}
|
||||
|
||||
$environment = $this->prepareEnvironment();
|
||||
$this->cleanupLegacyLimaProjects();
|
||||
$this->cleanupLegacyProductionExamples();
|
||||
|
||||
foreach (self::examples() as $example) {
|
||||
$this->upsertApplication($environment, $destination, $example);
|
||||
foreach (self::LIMA_SERVERS as $limaServer) {
|
||||
$this->seedEnvironment(
|
||||
environmentUuid: $limaServer['environment_uuid'],
|
||||
environmentName: $limaServer['environment_name'],
|
||||
destination: $this->limaDestination($limaServer['server_uuid']),
|
||||
uuidPrefix: $limaServer['uuid_prefix'],
|
||||
nameSuffix: " ({$limaServer['environment_name']})",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,6 +465,37 @@ KEY,
|
||||
],
|
||||
);
|
||||
|
||||
foreach (self::LIMA_SERVERS as $limaServer) {
|
||||
$server = Server::query()->firstOrCreate(
|
||||
['uuid' => $limaServer['server_uuid']],
|
||||
[
|
||||
'name' => $limaServer['server_name'],
|
||||
'description' => 'This is a Lima VM for local development testing',
|
||||
'ip' => 'host.docker.internal',
|
||||
'port' => $limaServer['port'],
|
||||
'team_id' => 0,
|
||||
'private_key_id' => 1,
|
||||
'proxy' => [
|
||||
'type' => ProxyTypes::TRAEFIK->value,
|
||||
'status' => ProxyStatus::EXITED->value,
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
$server->settings->forceFill([
|
||||
'sentinel_custom_url' => self::LIMA_SENTINEL_URL,
|
||||
])->saveQuietly();
|
||||
|
||||
StandaloneDocker::query()->firstOrCreate(
|
||||
['server_id' => $server->id],
|
||||
[
|
||||
'uuid' => "{$limaServer['server_uuid']}-docker",
|
||||
'name' => "{$limaServer['server_name']} Docker",
|
||||
'network' => 'coolify',
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
StandaloneDocker::query()->firstOrCreate(
|
||||
['id' => 0],
|
||||
[
|
||||
@@ -489,7 +545,71 @@ KEY,
|
||||
return in_array(config('app.env'), ['local', 'development', 'dev'], true);
|
||||
}
|
||||
|
||||
private function prepareEnvironment(): Environment
|
||||
private function limaDestination(string $serverUuid): StandaloneDocker
|
||||
{
|
||||
$limaDestination = Server::query()
|
||||
->where('uuid', $serverUuid)
|
||||
->first()
|
||||
?->standaloneDockers()
|
||||
->first();
|
||||
|
||||
if (! $limaDestination) {
|
||||
throw new RuntimeException("Lima StandaloneDocker destination is required for {$serverUuid} before running DevelopmentRailpackExamplesSeeder.");
|
||||
}
|
||||
|
||||
return $limaDestination;
|
||||
}
|
||||
|
||||
private function cleanupLegacyLimaProjects(): void
|
||||
{
|
||||
Project::query()
|
||||
->whereIn('uuid', [
|
||||
'railpack-examples-lima-ubuntu-2404',
|
||||
'railpack-examples-lima-ubuntu-2604',
|
||||
])
|
||||
->get()
|
||||
->each(function (Project $project): void {
|
||||
Application::withTrashed()
|
||||
->whereIn('environment_id', $project->environments()->pluck('id'))
|
||||
->get()
|
||||
->each
|
||||
->forceDelete();
|
||||
|
||||
$project->delete();
|
||||
});
|
||||
}
|
||||
|
||||
private function cleanupLegacyProductionExamples(): void
|
||||
{
|
||||
$project = Project::query()->where('uuid', self::PROJECT_UUID)->first();
|
||||
|
||||
if (! $project) {
|
||||
return;
|
||||
}
|
||||
|
||||
Application::withTrashed()
|
||||
->whereIn('environment_id', $project->environments()->pluck('id'))
|
||||
->whereIn('uuid', collect(self::examples())->pluck('uuid'))
|
||||
->get()
|
||||
->each
|
||||
->forceDelete();
|
||||
}
|
||||
|
||||
private function seedEnvironment(
|
||||
string $environmentUuid,
|
||||
string $environmentName,
|
||||
StandaloneDocker $destination,
|
||||
string $uuidPrefix = '',
|
||||
string $nameSuffix = '',
|
||||
): void {
|
||||
$environment = $this->prepareEnvironment($environmentUuid, $environmentName);
|
||||
|
||||
foreach (self::examples() as $example) {
|
||||
$this->upsertApplication($environment, $destination, $example, $uuidPrefix, $nameSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareEnvironment(string $environmentUuid, string $environmentName): Environment
|
||||
{
|
||||
$project = Project::query()->firstOrNew(['uuid' => self::PROJECT_UUID]);
|
||||
$project->fill([
|
||||
@@ -499,17 +619,29 @@ KEY,
|
||||
]);
|
||||
$project->save();
|
||||
|
||||
$environment = $project->environments()->first();
|
||||
$environment = $project->environments()
|
||||
->where(function ($query) use ($environmentName, $environmentUuid): void {
|
||||
$query
|
||||
->where('name', $environmentName)
|
||||
->orWhere('uuid', $environmentUuid);
|
||||
})
|
||||
->first();
|
||||
|
||||
$existingEnvironment = $project->environments()->first();
|
||||
|
||||
if (! $environment && $project->environments()->count() === 1 && $existingEnvironment?->name === 'production') {
|
||||
$environment = $existingEnvironment;
|
||||
}
|
||||
|
||||
if (! $environment) {
|
||||
$environment = $project->environments()->create([
|
||||
'name' => 'production',
|
||||
'uuid' => self::ENVIRONMENT_UUID,
|
||||
'name' => $environmentName,
|
||||
'uuid' => $environmentUuid,
|
||||
]);
|
||||
} else {
|
||||
$environment->update([
|
||||
'name' => 'production',
|
||||
'uuid' => self::ENVIRONMENT_UUID,
|
||||
'name' => $environmentName,
|
||||
'uuid' => $environmentUuid,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -519,13 +651,15 @@ KEY,
|
||||
/**
|
||||
* @param array<string, mixed> $example
|
||||
*/
|
||||
private function upsertApplication(Environment $environment, StandaloneDocker $destination, array $example): void
|
||||
private function upsertApplication(Environment $environment, StandaloneDocker $destination, array $example, string $uuidPrefix = '', string $nameSuffix = ''): void
|
||||
{
|
||||
$application = Application::withTrashed()->firstOrNew(['uuid' => $example['uuid']]);
|
||||
$uuid = $uuidPrefix.$example['uuid'];
|
||||
$name = $example['name'].$nameSuffix;
|
||||
$application = Application::withTrashed()->firstOrNew(['uuid' => $uuid]);
|
||||
$application->fill([
|
||||
'name' => $example['name'],
|
||||
'description' => $example['name'],
|
||||
'fqdn' => "http://{$example['uuid']}.127.0.0.1.sslip.io",
|
||||
'name' => $name,
|
||||
'description' => $name,
|
||||
'fqdn' => "http://{$uuid}.127.0.0.1.sslip.io",
|
||||
'repository_project_id' => $example['repository_project_id'] ?? self::REPOSITORY_PROJECT_ID,
|
||||
'git_repository' => $example['git_repository'] ?? self::GIT_REPOSITORY,
|
||||
'git_branch' => $example['git_branch'] ?? self::GIT_BRANCH,
|
||||
|
||||
@@ -7,6 +7,11 @@ use Illuminate\Database\Seeder;
|
||||
|
||||
class ProjectSeeder extends Seeder
|
||||
{
|
||||
private const LIMA_ENVIRONMENTS = [
|
||||
['name' => 'ubuntu24', 'uuid' => 'ubuntu24'],
|
||||
['name' => 'ubuntu26', 'uuid' => 'ubuntu26'],
|
||||
];
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$project = Project::create([
|
||||
@@ -16,7 +21,14 @@ class ProjectSeeder extends Seeder
|
||||
'team_id' => 0,
|
||||
]);
|
||||
|
||||
// Update the auto-created environment with a deterministic UUID
|
||||
$project->environments()->first()->update(['uuid' => 'production']);
|
||||
foreach (self::LIMA_ENVIRONMENTS as $index => $environment) {
|
||||
if ($index === 0) {
|
||||
$project->environments()->first()->update($environment);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$project->environments()->create($environment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,13 @@ use Illuminate\Database\Seeder;
|
||||
|
||||
class ServerSeeder extends Seeder
|
||||
{
|
||||
private const LIMA_SENTINEL_URL = 'http://host.lima.internal:8000';
|
||||
|
||||
private const LIMA_SERVERS = [
|
||||
['uuid' => 'lima-ubuntu-2404', 'name' => 'lima-ubuntu-2404', 'port' => 2222],
|
||||
['uuid' => 'lima-ubuntu-2604', 'name' => 'lima-ubuntu-2604', 'port' => 2223],
|
||||
];
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
Server::create([
|
||||
@@ -24,5 +31,25 @@ class ServerSeeder extends Seeder
|
||||
'status' => ProxyStatus::EXITED->value,
|
||||
],
|
||||
]);
|
||||
|
||||
foreach (self::LIMA_SERVERS as $limaServer) {
|
||||
$server = Server::create([
|
||||
'uuid' => $limaServer['uuid'],
|
||||
'name' => $limaServer['name'],
|
||||
'description' => 'This is a Lima VM for local development testing',
|
||||
'ip' => 'host.docker.internal',
|
||||
'port' => $limaServer['port'],
|
||||
'team_id' => 0,
|
||||
'private_key_id' => 1,
|
||||
'proxy' => [
|
||||
'type' => ProxyTypes::TRAEFIK->value,
|
||||
'status' => ProxyStatus::EXITED->value,
|
||||
],
|
||||
]);
|
||||
|
||||
$server->settings->forceFill([
|
||||
'sentinel_custom_url' => self::LIMA_SENTINEL_URL,
|
||||
])->saveQuietly();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user