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.

Add coolify-builder image, initials of deployments

Andras Bacsai8e0c1027bbea
diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php
new file mode 100644
index 0000000000..b479a6d193
--- /dev/null
+++ b/app/Http/Controllers/ProjectController.php
@@ -0,0 +1,109 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+class ProjectController extends Controller
+{
+ public function environments()
+ {
+ $project_uuid = request()->route('project_uuid');
+ $project = session('currentTeam')->projects->where('uuid', $project_uuid)->first();
+ if (!$project) {
+ return redirect()->route('home');
+ }
+ return view('project.environments', ['project' => $project]);
+ }
+ public function resources()
+ {
+ $project_uuid = request()->route('project_uuid');
+ $project = session('currentTeam')->projects->where('uuid', $project_uuid)->first();
+ if (!$project) {
+ return redirect()->route('home');
+ }
+ return view('project.resources', ['project' => $project]);
+ }
+ public function application()
+ {
+ $project_uuid = request()->route('project_uuid');
+ $environment_name = request()->route('environment_name');
+ $application_uuid = request()->route('application_uuid');
+ $project = session('currentTeam')->projects->where('uuid', $project_uuid)->first();
+ if (!$project) {
+ return redirect()->route('home');
+ }
+ $environment = $project->environments->where('name', $environment_name)->first();
+ if (!$environment) {
+ return redirect()->route('home');
+ }
+ $application = $environment->applications->where('uuid', $application_uuid)->first();
+ if (!$application) {
+ return redirect()->route('home');
+ }
+ return view('project.application', ['project' => $project, 'application' => $application]);
+ }
+ public function database()
+ {
+ $project_uuid = request()->route('project_uuid');
+ $environment_name = request()->route('environment_name');
+ $database_uuid = request()->route('database_uuid');
+ $project = session('currentTeam')->projects->where('uuid', $project_uuid)->first();
+ if (!$project) {
+ return redirect()->route('home');
+ }
+ $environment = $project->environments->where('name', $environment_name)->first();
+ if (!$environment) {
+ return redirect()->route('home');
+ }
+ $database = $environment->databases->where('uuid', $database_uuid)->first();
+ if (!$database) {
+ return redirect()->route('home');
+ }
+
+ return view('project.database', ['project' => $project, 'database' => $database]);
+ }
+ public function service()
+ {
+ $project_uuid = request()->route('project_uuid');
+ $environment_name = request()->route('environment_name');
+ $service_uuid = request()->route('service_uuid');
+
+ $project = session('currentTeam')->projects->where('uuid', $project_uuid)->first();
+ if (!$project) {
+ return redirect()->route('home');
+ }
+ $environment = $project->environments->where('name', $environment_name)->first();
+ if (!$environment) {
+ return redirect()->route('home');
+ }
+ $service = $environment->services->where('uuid', $service_uuid)->first();
+ if (!$service) {
+ return redirect()->route('home');
+ }
+
+ return view('project.service', ['project' => $project, 'service' => $service]);
+ }
+ public function deployment()
+ {
+ $project_uuid = request()->route('project_uuid');
+ $environment_name = request()->route('environment_name');
+ $application_uuid = request()->route('application_uuid');
+ $deployment_uuid = request()->route('deployment_uuid');
+
+ $project = session('currentTeam')->projects->where('uuid', $project_uuid)->first();
+ if (!$project) {
+ return redirect()->route('home');
+ }
+ $environment = $project->environments->where('name', $environment_name)->first();
+ if (!$environment) {
+ return redirect()->route('home');
+ }
+ $application = $environment->applications->where('uuid', $application_uuid)->first();
+ if (!$application) {
+ return redirect()->route('home');
+ }
+ $deployment = $application->deployments->where('uuid', $deployment_uuid)->first();
+ return view('project.deployment', ['project' => $project, 'deployment' => $deployment]);
+ }
+}
diff --git a/app/Http/Livewire/DemoDeployApplication.php b/app/Http/Livewire/DemoDeployApplication.php
deleted file mode 100644
index f038a72cb3..0000000000
--- a/app/Http/Livewire/DemoDeployApplication.php
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-
-namespace App\Http\Livewire;
-
-use App\Models\Application;
-use App\Models\CoolifyInstanceSettings;
-use App\Models\Deployment;
-use App\Traits\Shared;
-use Livewire\Component;
-use Visus\Cuid2\Cuid2;
-
-class DemoDeployApplication extends Component
-{
- use Shared;
-
- public $activity;
- public $isKeepAliveOn = false;
- public $application_uuid;
-
- public Application $application;
- public $destination;
- public string $deployment_id;
- public string $workdir;
-
-
- public CoolifyInstanceSettings $coolify_instance_settings;
- public $wildcard_domain;
-
- protected $command;
-
- private function dockerPreCommand($command)
- {
- return $this->command[] = "docker exec {$this->deployment_id} sh -c '{$command}'";
- }
- public function deploy()
- {
- $this->isKeepAliveOn = true;
-
- $this->coolify_instance_settings = CoolifyInstanceSettings::find(1);
- $this->application = Application::where('uuid', $this->application_uuid)->first();
- $this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
- $project_wildcard_domain = data_get($this->application, 'environment.project.settings.wildcard_domain');
- $global_wildcard_domain = data_get($this->coolify_instance_settings, 'wildcard_domain');
- $this->wildcard_domain = $project_wildcard_domain ?? $global_wildcard_domain ?? null;
-
- $source = $this->application->source->getMorphClass()::where('id', $this->application->source->id)->first();
- $this->deployment_id = new Cuid2(10);
-
- $this->workdir = "/tmp/{$this->deployment_id}";
-
- $this->command[] = "echo 'Starting deployment of {$this->application->name} ({$this->application->uuid})'";
- $this->command[] = "docker run -d --name {$this->deployment_id} --rm -v /var/run/docker.sock:/var/run/docker.sock coolify-builder >/dev/null";
-
- $this->dockerPreCommand('hostname');
- $this->dockerPreCommand("mkdir -p {$this->workdir}");
- $this->dockerPreCommand("ls -ld {$this->workdir}");
- $this->dockerPreCommand("git clone -b {$this->application->git_branch} {$source->html_url}/{$this->application->git_repository}.git {$this->workdir}");
- $this->dockerPreCommand("ls -l {$this->workdir}");
- $this->command[] = "docker stop -t 0 {$this->deployment_id} >/dev/null";
-
- $this->activity = remoteProcess(implode("\n", $this->command), $this->destination->server->name);
-
- Deployment::create([
- 'uuid' => $this->deployment_id,
- 'type_id' => $this->application->id,
- 'type_type' => Application::class,
- 'activity_log_id' => $this->activity->id,
- ]);
- }
- public function polling()
- {
- $this->activity?->refresh();
- if (data_get($this->activity, 'properties.exitCode') !== null) {
- $this->isKeepAliveOn = false;
- }
- }
- public function render()
- {
- return view('livewire.demo-deploy-application');
- }
-}
diff --git a/app/Http/Livewire/DeployApplication.php b/app/Http/Livewire/DeployApplication.php
new file mode 100644
index 0000000000..367b2d3e7c
--- /dev/null
+++ b/app/Http/Livewire/DeployApplication.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace App\Http\Livewire;
+
+use App\Models\Application;
+use App\Models\CoolifyInstanceSettings;
+use App\Models\Deployment;
+use Livewire\Component;
+use Visus\Cuid2\Cuid2;
+
+class DeployApplication extends Component
+{
+ public string $application_uuid;
+ public $activity;
+ protected string $deployment_uuid;
+ protected array $command = [];
+
+ private function execute_in_builder(string $command)
+ {
+ return $this->command[] = "docker exec {$this->deployment_uuid} sh -c '{$command}'";
+ }
+ private function start_builder_container()
+ {
+ // @TODO: Add --pull=always if the container is published to ghcr.io
+ $this->command[] = "docker run -d --name {$this->deployment_uuid} --rm -v /var/run/docker.sock:/var/run/docker.sock coolify-builder >/dev/null";
+ }
+ public function deploy()
+ {
+ $coolify_instance_settings = CoolifyInstanceSettings::find(1);
+ $application = Application::where('uuid', $this->application_uuid)->first();
+ $destination = $application->destination->getMorphClass()::where('id', $application->destination->id)->first();
+ $source = $application->source->getMorphClass()::where('id', $application->source->id)->first();
+
+ // Get Wildcard Domain
+ $project_wildcard_domain = data_get($application, 'environment.project.settings.wildcard_domain');
+ $global_wildcard_domain = data_get($coolify_instance_settings, 'wildcard_domain');
+ $wildcard_domain = $project_wildcard_domain ?? $global_wildcard_domain ?? null;
+
+ // Create Deployment ID
+ $this->deployment_uuid = new Cuid2(10);
+ $workdir = "/artifacts/{$this->deployment_uuid}";
+
+ // Start build process
+ $this->command[] = "echo 'Starting deployment of {$application->name} ({$application->uuid})'";
+ $this->start_builder_container();
+ $this->execute_in_builder('hostname');
+ $this->execute_in_builder("git clone -b {$application->git_branch} {$source->html_url}/{$application->git_repository}.git {$workdir}");
+ $this->execute_in_builder("ls -l {$workdir}");
+ $this->command[] = "docker stop -t 0 {$this->deployment_uuid} >/dev/null";
+
+ $this->activity = remoteProcess(implode("\n", $this->command), $destination->server->name);
+
+ // Create Deployment
+ Deployment::create([
+ 'uuid' => $this->deployment_uuid,
+ 'type_id' => $application->id,
+ 'type_type' => Application::class,
+ 'activity_log_id' => $this->activity->id,
+ ]);
+ // Redirect to deployment page
+ return redirect()->route('project.deployment', [
+ "deployment_uuid" => $this->deployment_uuid,
+ "project_uuid" => $application->environment->project->uuid,
+ "environment_name" => $application->environment->name,
+ "application_uuid" => $application->uuid
+ ]);
+ }
+ public function render()
+ {
+ return view('livewire.deploy-application');
+ }
+}
diff --git a/app/Http/Livewire/PollActivity.php b/app/Http/Livewire/PollActivity.php
new file mode 100644
index 0000000000..c754cca005
--- /dev/null
+++ b/app/Http/Livewire/PollActivity.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Http\Livewire;
+
+use Livewire\Component;
+use Spatie\Activitylog\Models\Activity;
+
+class PollActivity extends Component
+{
+ public $activity;
+ public $activity_log_id;
+ public $isKeepAliveOn = true;
+ public function mount() {
+ $this->activity = Activity::find($this->activity_log_id);
+ }
+ public function polling()
+ {
+ $this->activity?->refresh();
+ if (data_get($this->activity, 'properties.exitCode') !== null) {
+ $this->isKeepAliveOn = false;
+ }
+ }
+ public function render()
+ {
+ return view('livewire.poll-activity');
+ }
+}
diff --git a/app/Traits/Shared.php b/app/Traits/Shared.php
deleted file mode 100644
index c6884a7a00..0000000000
--- a/app/Traits/Shared.php
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-
-namespace App\Traits;
-
-use Illuminate\Support\Facades\Process;
-
-trait Shared
-{
- public function get_workdir(string $type, string $resource_id, string $deployment_id)
- {
- $workdir = "/tmp/coolify/$type/{$resource_id}/{$deployment_id}/";
- return $workdir;
- }
-}
diff --git a/database/seeders/ServiceSeeder.php b/database/seeders/ServiceSeeder.php
index e3e1ea3d88..f79b72144d 100644
--- a/database/seeders/ServiceSeeder.php
+++ b/database/seeders/ServiceSeeder.php
@@ -18,7 +18,7 @@ class ServiceSeeder extends Seeder
$standalone_docker_1 = StandaloneDocker::find(1);
Service::create([
'id' => 1,
- 'name'=> "My first database",
+ 'name'=> "My first service",
'environment_id' => $environment_1->id,
'destination_id' => $standalone_docker_1->id,
'destination_type' => StandaloneDocker::class,
diff --git a/docker/builder/Dockerfile b/docker/builder/Dockerfile
index 16aa2a9656..32099603b7 100644
--- a/docker/builder/Dockerfile
+++ b/docker/builder/Dockerfile
@@ -12,6 +12,7 @@ ARG PACK_VERSION=0.27.0
ARG NIXPACKS_VERSION=1.6.0
USER root
+WORKDIR /artifacts
RUN apk add --no-cache bash curl git git-lfs openssh-client tar tini
RUN mkdir -p ~/.docker/cli-plugins
RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/docker-$DOCKER_VERSION -o /usr/bin/docker
diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php
index 030b2379b7..d0477bc9e3 100644
--- a/resources/views/home.blade.php
+++ b/resources/views/home.blade.php
@@ -1,46 +1,8 @@
<x-layout>
- <h1>
- Coolify v4 🎉
- </h1>
<h1>Projects</h1>
- <ul>
- @forelse ($projects as $project)
- <h2>{{ $project->name }}</h2>
- <p>Project Settings:{{ $project->settings }}</p>
- <h2>Environments</h2>
- @forelse ($project->environments as $environment)
- <h1>Environment: {{ $environment->name }}</h1>
- <h2>Applications</h2>
- @forelse ($environment->applications as $application)
- <h3>{{ $application->name }}</h3>
- <p>Application: {{ $application->settings }}</p>
- <p>Destination Class: {{ $application->destination->getMorphClass() }}</p>
- <p>Source Class: {{ $application->source->getMorphClass() }}</p>
- <livewire:demo-deploy-application :application_uuid="$application->uuid" />
- @empty
- <li>No application found</li>
- @endforelse
- <h2>Databases</h2>
- @forelse ($environment->databases as $database)
- <h3>{{ $database->name }}</h3>
- <p>Database: {{ $database }}</p>
- <p>Destination Class: {{ $database->destination->getMorphClass() }}</p>
- @empty
- <li>No database found</li>
- @endforelse
- <h2>Services</h2>
- @forelse ($environment->services as $service)
- <h3>{{ $service->name }}</h3>
- <p>Service: {{ $service }}</p>
- <p>Destination Class: {{ $service->destination->getMorphClass() }}</p>
- @empty
- <li>No service found</li>
- @endforelse
- @empty
- <p>No environments found</p>
- @endforelse
- @empty
- <li>No projects found</li>
- @endforelse
- </ul>
+ @forelse ($projects as $project)
+ <a href="{{ route('project.environments', [$project->uuid]) }}">{{ data_get($project, 'name') }}</a>
+ @empty
+ <p>No projects found.</p>
+ @endforelse
</x-layout>
diff --git a/resources/views/livewire/deploy-application.blade.php b/resources/views/livewire/deploy-application.blade.php
new file mode 100644
index 0000000000..14d29bd9c5
--- /dev/null
+++ b/resources/views/livewire/deploy-application.blade.php
@@ -0,0 +1,3 @@
+<div>
+ <button wire:click='deploy'>Deploy</button>
+</div>
diff --git a/resources/views/livewire/poll-activity.blade.php b/resources/views/livewire/poll-activity.blade.php
new file mode 100644
index 0000000000..64e8a843d3
--- /dev/null
+++ b/resources/views/livewire/poll-activity.blade.php
@@ -0,0 +1,8 @@
+<div>
+ @isset($activity?->id)
+ <div>
+ Activity: <span>{{ $activity?->id ?? 'waiting' }}</span>
+ </div>
+ <pre style="width: 100%;overflow-y: scroll;" @if ($isKeepAliveOn) wire:poll.750ms="polling" @endif>{{ data_get($activity, 'description') }}</pre>
+ @endisset
+</div>
diff --git a/resources/views/project/application.blade.php b/resources/views/project/application.blade.php
new file mode 100644
index 0000000000..36ab571462
--- /dev/null
+++ b/resources/views/project/application.blade.php
@@ -0,0 +1,6 @@
+<x-layout>
+ <h1>Application</h1>
+ <p>Name: {{ $project->name }}</p>
+ <p>UUID: {{ $project->uuid }}</p>
+ <livewire:deploy-application :application_uuid="$application->uuid" />
+</x-layout>
diff --git a/resources/views/project/database.blade.php b/resources/views/project/database.blade.php
new file mode 100644
index 0000000000..f256fecb94
--- /dev/null
+++ b/resources/views/project/database.blade.php
@@ -0,0 +1,5 @@
+<x-layout>
+ <h1>Database</h1>
+
+
+</x-layout>
diff --git a/resources/views/project/deployment.blade.php b/resources/views/project/deployment.blade.php
new file mode 100644
index 0000000000..5ca6091fa4
--- /dev/null
+++ b/resources/views/project/deployment.blade.php
@@ -0,0 +1,8 @@
+<x-layout>
+ <h1>Deployment</h1>
+ <p>Name: {{ $project->name }}</p>
+ <p>UUID: {{ $project->uuid }}</p>
+
+ <p>Deployment UUID: {{ $deployment->uuid }}</p>
+ <livewire:poll-activity :activity_log_id="$deployment->activity_log_id" />
+</x-layout>
diff --git a/resources/views/project/environments.blade.php b/resources/views/project/environments.blade.php
new file mode 100644
index 0000000000..bf9efb655a
--- /dev/null
+++ b/resources/views/project/environments.blade.php
@@ -0,0 +1,11 @@
+<x-layout>
+ <h1>Environments</h1>
+
+ @foreach ($project->environments as $environment)
+ <div>
+ <a href="{{ route('project.resources', [$project->uuid, $environment->name]) }}">
+ {{ $environment->name }}
+ </a>
+ </div>
+ @endforeach
+</x-layout>
diff --git a/resources/views/project/resources.blade.php b/resources/views/project/resources.blade.php
new file mode 100644
index 0000000000..ec5976d25e
--- /dev/null
+++ b/resources/views/project/resources.blade.php
@@ -0,0 +1,29 @@
+<x-layout>
+ <h1>Resources</h1>
+
+ @foreach ($project->environments as $environment)
+ <div>
+ @foreach ($environment->applications as $application)
+ <p>
+ <a href="{{ route('project.application', [$project->uuid, $environment->name, $application->uuid]) }}">
+ {{ $application->name }}
+ </a>
+ </p>
+ @endforeach
+ @foreach ($environment->databases as $database)
+ <p>
+ <a href="{{ route('project.database', [$project->uuid, $environment->name, $database->uuid]) }}">
+ {{ $database->name }}
+ </a>
+ </p>
+ @endforeach
+ @foreach ($environment->services as $service)
+ <p>
+ <a href="{{ route('project.service', [$project->uuid, $environment->name, $service->uuid]) }}">
+ {{ $service->name }}
+ </a>
+ </p>
+ @endforeach
+ </div>
+ @endforeach
+</x-layout>
diff --git a/resources/views/project/service.blade.php b/resources/views/project/service.blade.php
new file mode 100644
index 0000000000..04cbcd4df2
--- /dev/null
+++ b/resources/views/project/service.blade.php
@@ -0,0 +1,5 @@
+<x-layout>
+ <h1>Service</h1>
+
+
+</x-layout>
diff --git a/routes/web.php b/routes/web.php
index 18cde30a78..875a117c87 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -1,6 +1,7 @@
<?php
use App\Http\Controllers\HomeController;
+use App\Http\Controllers\ProjectController;
use Illuminate\Support\Facades\Route;
/*
@@ -17,7 +18,14 @@ use Illuminate\Support\Facades\Route;
Route::middleware(['auth'])->group(function () {
- Route::get('/', [HomeController::class, 'show']);
+ Route::get('/', [HomeController::class, 'show'])->name('home');
+ Route::get('/project/{project_uuid}', [ProjectController::class, 'environments'])->name('project.environments');
+ Route::get('/project/{project_uuid}/{environment_name}', [ProjectController::class, 'resources'])->name('project.resources');
+ Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}', [ProjectController::class, 'application'])->name('project.application');
+ Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}/deployment/{deployment_uuid}', [ProjectController::class, 'deployment'])->name('project.deployment');
+ Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}', [ProjectController::class, 'database'])->name('project.database');
+ Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}', [ProjectController::class, 'service'])->name('project.service');
+
Route::get('/profile', function () {
return view('profile');
});