diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 468b37c5d..36def4911 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,10 +1,14 @@ name: Docker Image CI on: + # push: + # branches: [ "main" ] + # pull_request: + # branches: [ "*" ] push: - branches: [ "main" ] + branches: ["this-does-not-exist"] pull_request: - branches: [ "*" ] + branches: ["this-does-not-exist"] jobs: build: diff --git a/.gitignore b/.gitignore index 54068e03b..9d85ddf63 100644 --- a/.gitignore +++ b/.gitignore @@ -21,5 +21,8 @@ yarn-error.log /.bash_history /_volumes +resources/recipes + .lesshst psysh_history +.psql_history diff --git a/app/Actions/RemoteProcess/DispatchRemoteProcess.php b/app/Actions/CoolifyTask/PrepareCoolifyTask.php similarity index 65% rename from app/Actions/RemoteProcess/DispatchRemoteProcess.php rename to app/Actions/CoolifyTask/PrepareCoolifyTask.php index 2d23513ea..c67a8bcb3 100644 --- a/app/Actions/RemoteProcess/DispatchRemoteProcess.php +++ b/app/Actions/CoolifyTask/PrepareCoolifyTask.php @@ -1,16 +1,21 @@ model) { $properties = $remoteProcessArgs->toArray(); @@ -31,7 +36,7 @@ class DispatchRemoteProcess public function __invoke(): Activity { - $job = new ExecuteRemoteProcess($this->activity); + $job = new CoolifyTask($this->activity); dispatch($job); $this->activity->refresh(); return $this->activity; diff --git a/app/Actions/RemoteProcess/RunRemoteProcess.php b/app/Actions/CoolifyTask/RunRemoteProcess.php similarity index 97% rename from app/Actions/RemoteProcess/RunRemoteProcess.php rename to app/Actions/CoolifyTask/RunRemoteProcess.php index 41e86b60d..877e95170 100644 --- a/app/Actions/RemoteProcess/RunRemoteProcess.php +++ b/app/Actions/CoolifyTask/RunRemoteProcess.php @@ -1,6 +1,6 @@ getExtraProperty('type') !== ActivityTypes::REMOTE_PROCESS->value && $activity->getExtraProperty('type') !== ActivityTypes::DEPLOYMENT->value) { + if ($activity->getExtraProperty('type') !== ActivityTypes::INLINE->value && $activity->getExtraProperty('type') !== ActivityTypes::DEPLOYMENT->value) { throw new \RuntimeException('Incompatible Activity to run a remote command.'); } diff --git a/app/Data/CoolifyTaskArgs.php b/app/Data/CoolifyTaskArgs.php new file mode 100644 index 000000000..09ab923ab --- /dev/null +++ b/app/Data/CoolifyTaskArgs.php @@ -0,0 +1,26 @@ +value, + ) { + } +} diff --git a/app/Data/RemoteProcessArgs.php b/app/Data/RemoteProcessArgs.php deleted file mode 100644 index cdf13cac4..000000000 --- a/app/Data/RemoteProcessArgs.php +++ /dev/null @@ -1,24 +0,0 @@ -value, - public string $status = ProcessStatus::HOLDING->value, - public ?Model $model = null, - ) { - } -} diff --git a/app/Enums/ActivityTypes.php b/app/Enums/ActivityTypes.php index 5bcab7cd7..47fec9424 100644 --- a/app/Enums/ActivityTypes.php +++ b/app/Enums/ActivityTypes.php @@ -4,6 +4,6 @@ namespace App\Enums; enum ActivityTypes: string { - case REMOTE_PROCESS = 'remote_process'; + case INLINE = 'inline'; case DEPLOYMENT = 'deployment'; } diff --git a/app/Http/Controllers/ApplicationController.php b/app/Http/Controllers/ApplicationController.php index 3cc33c203..f477549db 100644 --- a/app/Http/Controllers/ApplicationController.php +++ b/app/Http/Controllers/ApplicationController.php @@ -56,8 +56,14 @@ class ApplicationController extends Controller if (!$application) { return redirect()->route('dashboard'); } - $activity = Activity::where('properties->deployment_uuid', '=', $deployment_uuid)->first(); - + $activity = Activity::where('properties->type_uuid', '=', $deployment_uuid)->first(); + if (!$activity) { + return redirect()->route('project.application.deployments', [ + 'project_uuid' => $project->uuid, + 'environment_name' => $environment->name, + 'application_uuid' => $application->uuid, + ]); + } return view('project.application.deployment', [ 'application' => $application, 'activity' => $activity, diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 1f234cdab..3bb4c2b23 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -93,7 +93,10 @@ class ProjectController extends Controller if (!$application) { return redirect()->route('dashboard'); } - $activity = Activity::where('properties->deployment_uuid', '=', $deployment_uuid)->first(); + $activity = Activity::query() + ->where('properties->type', '=', 'deployment') + ->where('properties->uuid', '=', $deployment_uuid) + ->first(); return view('project.application.deployment', [ 'application' => $application, diff --git a/app/Http/Livewire/Destination/New/StandaloneDocker.php b/app/Http/Livewire/Destination/New/StandaloneDocker.php index 1d22e65fb..5abf19a90 100644 --- a/app/Http/Livewire/Destination/New/StandaloneDocker.php +++ b/app/Http/Livewire/Destination/New/StandaloneDocker.php @@ -45,7 +45,7 @@ class StandaloneDocker extends Component $server = Server::find($this->server_id); - runRemoteCommandSync($server, ['docker network create --attachable ' . $this->network], throwError: false); + instantRemoteProcess($server, ['docker network create --attachable ' . $this->network], throwError: false); return redirect()->route('destination.show', $docker->uuid); } } diff --git a/app/Http/Livewire/ForceUpgrade.php b/app/Http/Livewire/ForceUpgrade.php index ad6dd2ba4..bec3ee0f8 100644 --- a/app/Http/Livewire/ForceUpgrade.php +++ b/app/Http/Livewire/ForceUpgrade.php @@ -2,25 +2,26 @@ namespace App\Http\Livewire; +use App\Enums\ActivityTypes; use App\Models\Server; -use Illuminate\Support\Facades\Http; use Livewire\Component; class ForceUpgrade extends Component { public function upgrade() { - if (env('APP_ENV') === 'local') { + //if (env('APP_ENV') === 'local') { + if (config('app.env') === 'local') { $server = Server::where('ip', 'coolify-testing-host')->first(); if (!$server) { return; } - runRemoteCommandSync($server, [ + instantRemoteProcess($server, [ "sleep 2" ]); remoteProcess([ "sleep 10" - ], $server); + ], $server, ActivityTypes::INLINE->value); $this->emit('updateInitiated'); } else { $latestVersion = getLatestVersionOfCoolify(); @@ -31,19 +32,19 @@ class ForceUpgrade extends Component return; } - runRemoteCommandSync($server, [ + instantRemoteProcess($server, [ "curl -fsSL $cdn/docker-compose.yml -o /data/coolify/source/docker-compose.yml", "curl -fsSL $cdn/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml", "curl -fsSL $cdn/.env.production -o /data/coolify/source/.env.production", "curl -fsSL $cdn/upgrade.sh -o /data/coolify/source/upgrade.sh", ]); - runRemoteCommandSync($server, [ + instantRemoteProcess($server, [ "docker compose -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml pull", ]); remoteProcess([ "bash /data/coolify/source/upgrade.sh $latestVersion" - ], $server); + ], $server, ActivityTypes::INLINE->value); $this->emit('updateInitiated'); } diff --git a/app/Http/Livewire/Project/Application/Deploy.php b/app/Http/Livewire/Project/Application/Deploy.php index a4ac4ab2d..ba31e4fbf 100644 --- a/app/Http/Livewire/Project/Application/Deploy.php +++ b/app/Http/Livewire/Project/Application/Deploy.php @@ -73,7 +73,7 @@ class Deploy extends Component } public function stop() { - runRemoteCommandSync($this->destination->server, ["docker rm -f {$this->application->uuid}"]); + instantRemoteProcess($this->destination->server, ["docker rm -f {$this->application->uuid}"]); if ($this->application->status != 'exited') { $this->application->status = 'exited'; $this->application->save(); diff --git a/app/Http/Livewire/Project/Application/GetDeployments.php b/app/Http/Livewire/Project/Application/GetDeployments.php index 1037eb727..2df15d0c4 100644 --- a/app/Http/Livewire/Project/Application/GetDeployments.php +++ b/app/Http/Livewire/Project/Application/GetDeployments.php @@ -12,7 +12,7 @@ class GetDeployments extends Component public string $status; public function polling() { - $activity = Activity::where('properties->deployment_uuid', '=', $this->deployment_uuid)->first(); + $activity = Activity::where('properties->type_uuid', '=', $this->deployment_uuid)->first(); $this->created_at = $activity->created_at; $this->status = data_get($activity, 'properties.status'); } diff --git a/app/Http/Livewire/Project/Application/PollDeployment.php b/app/Http/Livewire/Project/Application/PollDeployment.php index 148cadf27..c09106afb 100644 --- a/app/Http/Livewire/Project/Application/PollDeployment.php +++ b/app/Http/Livewire/Project/Application/PollDeployment.php @@ -2,6 +2,7 @@ namespace App\Http\Livewire\Project\Application; +use App\Enums\ActivityTypes; use Livewire\Component; use Spatie\Activitylog\Models\Activity; @@ -14,7 +15,9 @@ class PollDeployment extends Component public function polling() { if ( is_null($this->activity) && isset($this->deployment_uuid)) { - $this->activity = Activity::where('properties->deployment_uuid', '=', $this->deployment_uuid) + $this->activity = Activity::query() + ->where('properties->type', '=', ActivityTypes::DEPLOYMENT->value) + ->where('properties->type_uuid', '=', $this->deployment_uuid) ->first(); } else { $this->activity?->refresh(); diff --git a/app/Http/Livewire/Project/New/PublicGitRepository.php b/app/Http/Livewire/Project/New/PublicGitRepository.php index 736d85c69..b676b463c 100644 --- a/app/Http/Livewire/Project/New/PublicGitRepository.php +++ b/app/Http/Livewire/Project/New/PublicGitRepository.php @@ -38,7 +38,7 @@ class PublicGitRepository extends Component ]; public function mount() { - if (env('APP_ENV') === 'local') { + if (config('app.env') === 'local') { $this->public_repository_url = 'https://github.com/coollabsio/coolify-examples/tree/nodejs-fastify'; $this->port = 3000; } diff --git a/app/Http/Livewire/RunCommand.php b/app/Http/Livewire/RunCommand.php index 9eaa2bbd1..41002ca17 100755 --- a/app/Http/Livewire/RunCommand.php +++ b/app/Http/Livewire/RunCommand.php @@ -2,6 +2,7 @@ namespace App\Http\Livewire; +use App\Enums\ActivityTypes; use App\Models\Server; use Livewire\Component; @@ -31,19 +32,19 @@ class RunCommand extends Component public function runCommand() { $this->isKeepAliveOn = true; - $this->activity = remoteProcess([$this->command], Server::where('uuid', $this->server)->first()); + $this->activity = remoteProcess([$this->command], Server::where('uuid', $this->server)->first(), ActivityTypes::INLINE->value); } public function runSleepingBeauty() { $this->isKeepAliveOn = true; - $this->activity = remoteProcess(['x=1; while [ $x -le 40 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done'], Server::where('uuid', $this->server)->first()); + $this->activity = remoteProcess(['x=1; while [ $x -le 40 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done'], Server::where('uuid', $this->server)->first(), ActivityTypes::INLINE->value); } public function runDummyProjectBuild() { $this->isKeepAliveOn = true; - $this->activity = remoteProcess([' cd projects/dummy-project', 'docker-compose build --no-cache'], Server::where('uuid', $this->server)->first()); + $this->activity = remoteProcess([' cd projects/dummy-project', 'docker-compose build --no-cache'], Server::where('uuid', $this->server)->first(), ActivityTypes::INLINE->value); } public function polling() diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php index e4d9916fd..08d2d7cf9 100644 --- a/app/Http/Livewire/Server/Form.php +++ b/app/Http/Livewire/Server/Form.php @@ -28,15 +28,15 @@ class Form extends Component public function installDocker() { $config = base64_encode('{ "live-restore": true }'); - runRemoteCommandSync($this->server, [ + instantRemoteProcess($this->server, [ "curl https://releases.rancher.com/install-docker/23.0.sh | sh" ]); } public function checkServer() { - $this->uptime = runRemoteCommandSync($this->server, ['uptime']); - $this->dockerVersion = runRemoteCommandSync($this->server, ['docker version|head -2|grep -i version'], false); - $this->dockerComposeVersion = runRemoteCommandSync($this->server, ['docker compose version|head -2|grep -i version'], false); + $this->uptime = instantRemoteProcess($this->server, ['uptime']); + $this->dockerVersion = instantRemoteProcess($this->server, ['docker version|head -2|grep -i version'], false); + $this->dockerComposeVersion = instantRemoteProcess($this->server, ['docker compose version|head -2|grep -i version'], false); } public function submit() { diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index a55954df3..5924cae3a 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -38,7 +38,7 @@ class ContainerStatusJob implements ShouldQueue $not_found_applications = $applications; $containers = collect(); foreach ($servers as $server) { - $output = runRemoteCommandSync($server, ['docker ps -a -q --format \'{{json .}}\'']); + $output = instantRemoteProcess($server, ['docker ps -a -q --format \'{{json .}}\'']); $containers = $containers->concat(formatDockerCmdOutputToJson($output)); } foreach ($containers as $container) { @@ -67,7 +67,7 @@ class ContainerStatusJob implements ShouldQueue return; } if ($application->destination->server) { - $container = runRemoteCommandSync($application->destination->server, ["docker inspect --format '{{json .State}}' {$this->container_id}"]); + $container = instantRemoteProcess($application->destination->server, ["docker inspect --format '{{json .State}}' {$this->container_id}"]); $container = formatDockerCmdOutputToJson($container); $application->status = $container[0]['Status']; $application->save(); diff --git a/app/Jobs/ExecuteRemoteProcess.php b/app/Jobs/CoolifyTask.php similarity index 89% rename from app/Jobs/ExecuteRemoteProcess.php rename to app/Jobs/CoolifyTask.php index 3915c2d55..d96095cc4 100755 --- a/app/Jobs/ExecuteRemoteProcess.php +++ b/app/Jobs/CoolifyTask.php @@ -2,7 +2,7 @@ namespace App\Jobs; -use App\Actions\RemoteProcess\RunRemoteProcess; +use App\Actions\CoolifyTask\RunRemoteProcess; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -10,7 +10,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Spatie\Activitylog\Models\Activity; -class ExecuteRemoteProcess implements ShouldQueue +class CoolifyTask implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; diff --git a/app/Jobs/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.php index 9a4393f7c..501f45039 100644 --- a/app/Jobs/DeployApplicationJob.php +++ b/app/Jobs/DeployApplicationJob.php @@ -2,8 +2,8 @@ namespace App\Jobs; -use App\Actions\RemoteProcess\RunRemoteProcess; -use App\Data\RemoteProcessArgs; +use App\Actions\CoolifyTask\RunRemoteProcess; +use App\Data\CoolifyTaskArgs; use App\Enums\ActivityTypes; use App\Models\Application; use App\Models\InstanceSettings; @@ -55,14 +55,14 @@ class DeployApplicationJob implements ShouldQueue $private_key_location = savePrivateKeyForServer($server); - $remoteProcessArgs = new RemoteProcessArgs( + $remoteProcessArgs = new CoolifyTaskArgs( server_ip: $server->ip, private_key_location: $private_key_location, - deployment_uuid: $this->deployment_uuid, command: 'overwritten-later', port: $server->port, user: $server->user, type: ActivityTypes::DEPLOYMENT->value, + type_uuid: $this->deployment_uuid, ); $this->activity = activity() diff --git a/app/Jobs/DockerCleanupDanglingImagesJob.php b/app/Jobs/DockerCleanupDanglingImagesJob.php index d5798ba54..0938b6bb8 100644 --- a/app/Jobs/DockerCleanupDanglingImagesJob.php +++ b/app/Jobs/DockerCleanupDanglingImagesJob.php @@ -31,7 +31,7 @@ class DockerCleanupDanglingImagesJob implements ShouldQueue try { $servers = Server::all(); foreach ($servers as $server) { - runRemoteCommandSync($server, ['docker image prune -f']); + instantRemoteProcess($server, ['docker image prune -f']); } } catch (\Exception $e) { Log::error($e->getMessage()); diff --git a/app/Models/Application.php b/app/Models/Application.php index 48234efe0..b79ca182d 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -94,13 +94,12 @@ class Application extends BaseModel return $this->morphMany(LocalPersistentVolume::class, 'resource'); } - public function deployments() { - return Activity::where('subject_id', $this->id)->where('properties->deployment_uuid', '!=', null)->orderBy('created_at', 'desc')->get(); + return Activity::where('subject_id', $this->id)->where('properties->type', '=', 'deployment')->orderBy('created_at', 'desc')->get(); } public function get_deployment(string $deployment_uuid) { - return Activity::where('subject_id', $this->id)->where('properties->deployment_uuid', '=', $deployment_uuid)->first(); + return Activity::where('subject_id', $this->id)->where('properties->type_uuid', '=', $deployment_uuid)->first(); } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 5813a6235..9945221c8 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,6 +2,7 @@ namespace App\Providers; +use App\Jobs\CoolifyTask; use Illuminate\Queue\Events\JobProcessed; use Illuminate\Support\Facades\Process; use Illuminate\Support\Facades\Queue; @@ -31,7 +32,7 @@ class AppServiceProvider extends ServiceProvider { Queue::after(function (JobProcessed $event) { // @TODO: Remove `coolify-builder` container after the remoteProcess job is finishged and remoteProcess->type == `deployment`. - if ($event->job->resolveName() === 'App\Jobs\ExecuteRemoteProcess') { + if ($event->job->resolveName() === CoolifyTask::class) { } }); diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 36ee4cdac..49569d1a4 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -1,8 +1,7 @@ new RemoteProcessArgs( + return resolve(PrepareCoolifyTask::class, [ + 'remoteProcessArgs' => new CoolifyTaskArgs( server_ip: $server->ip, private_key_location: $private_key_location, - deployment_uuid: $deployment_uuid, command: <<port, user: $server->user, - type: $deployment_uuid ? ActivityTypes::DEPLOYMENT->value : ActivityTypes::REMOTE_PROCESS->value, + type: $type, + type_uuid: $type_uuid, model: $model, ), ])(); @@ -119,8 +119,8 @@ if (!function_exists('formatDockerLabelsToJson')) { })[0]; } } -if (!function_exists('runRemoteCommandSync')) { - function runRemoteCommandSync(Server $server, array $command, $throwError = true) +if (!function_exists('instantRemoteProcess')) { + function instantRemoteProcess(Server $server, array $command, $throwError = true) { $command_string = implode("\n", $command); $private_key_location = savePrivateKeyForServer($server); diff --git a/resources/views/livewire/project/application/deploy.blade.php b/resources/views/livewire/project/application/deploy.blade.php index 06e71bf55..8237c0ce7 100644 --- a/resources/views/livewire/project/application/deploy.blade.php +++ b/resources/views/livewire/project/application/deploy.blade.php @@ -18,7 +18,7 @@ @if (data_get($application, 'ports_mappings_array')) @foreach ($application->ports_mappings_array as $port) - @if (env('APP_ENV') === 'local') + @if (config('app.env') === 'local') Open {{ explode(':', $port)[0] }} @else diff --git a/resources/views/livewire/project/application/poll-deployment.blade.php b/resources/views/livewire/project/application/poll-deployment.blade.php index c48f1e440..53a5987d6 100644 --- a/resources/views/livewire/project/application/poll-deployment.blade.php +++ b/resources/views/livewire/project/application/poll-deployment.blade.php @@ -1,3 +1,6 @@
-
{{ \App\Actions\RemoteProcess\RunRemoteProcess::decodeOutput($activity) }}
+
{{ \App\Actions\CoolifyTask\RunRemoteProcess::decodeOutput($activity) }}
diff --git a/resources/views/livewire/run-command.blade.php b/resources/views/livewire/run-command.blade.php index 085bc9bb7..3953f2fa4 100755 --- a/resources/views/livewire/run-command.blade.php +++ b/resources/views/livewire/run-command.blade.php @@ -1,7 +1,7 @@