Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

2.8 KB
Raw Blame
<?php

use App\Models\Environment;
use App\Models\Project;
use App\Models\Server;
use App\Models\Service;
use App\Models\ServiceApplication;
use App\Models\StandaloneDocker;
use App\Models\Team;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;

uses(RefreshDatabase::class);

it('selects the private service network for Traefik routed compose services', function () {
    Bus::fake();

    $team = Team::factory()->create();
    $server = Server::factory()->create(['team_id' => $team->id]);
    $destination = StandaloneDocker::where('server_id', $server->id)->firstOrFail();
    $project = Project::factory()->create(['team_id' => $team->id]);
    $environment = Environment::factory()->create(['project_id' => $project->id]);
    $service = Service::factory()->create([
        'environment_id' => $environment->id,
        'server_id' => $server->id,
        'destination_id' => $destination->id,
        'destination_type' => $destination->getMorphClass(),
        'docker_compose_raw' => <<<'YAML'
services:
  app:
    image: nginx:latest
    networks:
      - custom-network
networks:
  custom-network: {}
YAML,
    ]);

    ServiceApplication::create([
        'name' => 'app',
        'service_id' => $service->id,
        'fqdn' => 'https://example.com',
    ]);

    $parsedCompose = serviceParser($service);
    $labels = collect(data_get($parsedCompose, 'services.app.labels'));

    expect($labels->values()->all())->toContain("traefik.docker.network={$service->uuid}");
});

it('labels an existing service application from its stored type after its image changes', function () {
    Bus::fake();

    $team = Team::factory()->create();
    $server = Server::factory()->create(['team_id' => $team->id]);
    $destination = StandaloneDocker::where('server_id', $server->id)->firstOrFail();
    $project = Project::factory()->create(['team_id' => $team->id]);
    $environment = Environment::factory()->create(['project_id' => $project->id]);
    $service = Service::factory()->create([
        'environment_id' => $environment->id,
        'server_id' => $server->id,
        'destination_id' => $destination->id,
        'destination_type' => $destination->getMorphClass(),
        'docker_compose_raw' => <<<'YAML'
services:
  app:
    image: postgres:17
YAML,
    ]);

    $serviceApplication = ServiceApplication::create([
        'name' => 'app',
        'service_id' => $service->id,
        'image' => 'nginx:latest',
    ]);

    $parsedCompose = serviceParser($service);
    $labels = collect(data_get($parsedCompose, 'services.app.labels'));

    expect($serviceApplication->fresh()->image)->toBe('postgres:17')
        ->and($labels->values()->all())
        ->toContain('coolify.service.subType=application')
        ->not->toContain('coolify.service.subType=database');
});