From 53e2960ffd35e25fb28c555b275243eda2fa754a Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 2 May 2023 14:30:15 +0200 Subject: [PATCH 001/357] show debug --- .github/workflows/production-build.yml | 2 +- app/Jobs/DeployApplicationJob.php | 2 +- resources/views/server/show.blade.php | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/production-build.yml b/.github/workflows/production-build.yml index 2b71b8573..b9c655f6a 100644 --- a/.github/workflows/production-build.yml +++ b/.github/workflows/production-build.yml @@ -2,7 +2,7 @@ name: Production Build (v4) on: push: - branches: ["v4"] + branches: ["v4", "v4-next"] env: REGISTRY: ghcr.io diff --git a/app/Jobs/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.php index e1780de84..7fdd48190 100644 --- a/app/Jobs/DeployApplicationJob.php +++ b/app/Jobs/DeployApplicationJob.php @@ -123,7 +123,7 @@ class DeployApplicationJob implements ShouldQueue $this->executeNow([ "echo 'Starting deployment of {$this->application->git_repository}:{$this->application->git_branch}...'", "echo -n 'Pulling latest version of the builder image (ghcr.io/coollabsio/coolify-builder)... '", - "docker run --pull=always -d --name {$this->deployment_uuid} --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/coollabsio/coolify-builder >/dev/null 2>&1", + "docker run --pull=always -d --name {$this->deployment_uuid} --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/coollabsio/coolify-builder", "echo 'Done.'", ]); diff --git a/resources/views/server/show.blade.php b/resources/views/server/show.blade.php index bde12916f..1fb710c42 100644 --- a/resources/views/server/show.blade.php +++ b/resources/views/server/show.blade.php @@ -1,8 +1,6 @@

Server

-

Private Key

-

{{ $server->privateKey->private_key }}

Destinations

@if ($server->standaloneDockers) @foreach ($server->standaloneDockers as $docker) From 23cea9a130649c8955c0433e5c5b49c752c63a70 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 2 May 2023 15:20:45 +0200 Subject: [PATCH 002/357] wip --- app/Http/Livewire/Server/Form.php | 6 +++++ app/Jobs/DeployApplicationJob.php | 7 ++++-- bootstrap/helpers.php | 2 +- docker/builder/Dockerfile | 23 ++++++++++++------- .../views/livewire/server/form.blade.php | 1 + 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php index 2d9a6cf60..7b512f066 100644 --- a/app/Http/Livewire/Server/Form.php +++ b/app/Http/Livewire/Server/Form.php @@ -23,6 +23,12 @@ class Form extends Component { $this->server = Server::find($this->server_id); } + public function installDocker() + { + $config = base64_encode('{ "live-restore": true }'); + runRemoteCommandSync($this->server, ["mkdir -p /etc/docker/", "touch /etc/docker/daemon.json", "echo '{$config}' | base64 -d > /etc/docker/daemon.json"]); + runRemoteCommandSync($this->server, ['sh -c "$(curl --silent -fsSL https://get.docker.com)"']); + } public function checkConnection() { $this->uptime = runRemoteCommandSync($this->server, ['uptime']); diff --git a/app/Jobs/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.php index 7fdd48190..9a4393f7c 100644 --- a/app/Jobs/DeployApplicationJob.php +++ b/app/Jobs/DeployApplicationJob.php @@ -123,12 +123,15 @@ class DeployApplicationJob implements ShouldQueue $this->executeNow([ "echo 'Starting deployment of {$this->application->git_repository}:{$this->application->git_branch}...'", "echo -n 'Pulling latest version of the builder image (ghcr.io/coollabsio/coolify-builder)... '", - "docker run --pull=always -d --name {$this->deployment_uuid} --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/coollabsio/coolify-builder", - "echo 'Done.'", ]); + $this->executeNow([ + "docker run --pull=always -d --name {$this->deployment_uuid} --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/coollabsio/coolify-builder", + ], isDebuggable: true); + // Import git repository $this->executeNow([ + "echo 'Done.'", "echo -n 'Importing {$this->application->git_repository}:{$this->application->git_branch} to {$this->workdir}... '" ]); diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 830df31c5..7e86b016c 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -131,7 +131,7 @@ if (!function_exists('runRemoteCommandSync')) { if (!$throwError) { return false; } - Log::error($output); + Log::error($process->errorOutput()); throw new \RuntimeException('There was an error running the command.'); } return $output; diff --git a/docker/builder/Dockerfile b/docker/builder/Dockerfile index aa7e9de1e..868c48cd3 100644 --- a/docker/builder/Dockerfile +++ b/docker/builder/Dockerfile @@ -4,11 +4,11 @@ ARG TARGETPLATFORM # https://download.docker.com/linux/static/stable/ ARG DOCKER_VERSION=23.0.5 # https://github.com/docker/compose/releases -# Reverted to 2.6.1 because of this https://github.com/docker/compose/issues/9704. 2.9.0 still has a bug. -# Using the latest now ARG DOCKER_COMPOSE_VERSION=2.17.3 +# https://github.com/docker/buildx/releases +ARG DOCKER_BUILDX_VERSION=0.10.4 # https://github.com/buildpacks/pack/releases -ARG PACK_VERSION=0.27.0 +ARG PACK_VERSION=0.29.0 # https://github.com/railwayapp/nixpacks/releases ARG NIXPACKS_VERSION=1.6.1 @@ -16,11 +16,18 @@ 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 -RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/docker-compose-linux-$DOCKER_COMPOSE_VERSION -o ~/.docker/cli-plugins/docker-compose -RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/pack-$PACK_VERSION -o /usr/local/bin/pack -RUN curl -sSL https://nixpacks.com/install.sh | bash -RUN chmod +x ~/.docker/cli-plugins/docker-compose /usr/bin/docker /usr/local/bin/pack +RUN if [[ ${TARGETPLATFORM} == 'linux/amd64' ]]; then \ + curl -SL https://github.com/docker/buildx/releases/download/v${DOCKER_BUILDX_VERSION}/buildx-v0.10.4.linux-amd64 -o ~/.docker/cli-plugins/docker-buildx && \ + curl -SL https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}}/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose && \ + (curl -sSL "https://github.com/buildpacks/pack/releases/download/v${PACK_VERSION}/pack-v${PACK_VERSION}-linux.tgz" | sudo tar -C /usr/local/bin/ --no-same-owner -xzv pack) && \ + curl -sSL https://nixpacks.com/install.sh | bash && \ + chmod +x ~/.docker/cli-plugins/docker-compose /usr/bin/docker /usr/local/bin/pack; \ + fi +# RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/docker-$DOCKER_VERSION -o /usr/bin/docker +# RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/docker-compose-linux-$DOCKER_COMPOSE_VERSION -o ~/.docker/cli-plugins/docker-compose +# RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/pack-$PACK_VERSION -o /usr/local/bin/pack +# RUN curl -sSL https://nixpacks.com/install.sh | bash +# RUN chmod +x ~/.docker/cli-plugins/docker-compose /usr/bin/docker /usr/local/bin/pack ENTRYPOINT ["/sbin/tini", "--"] CMD ["sh", "-c", "while true; do sleep 3600; done"] diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php index 1226bf3f8..15ead9a79 100644 --- a/resources/views/livewire/server/form.blade.php +++ b/resources/views/livewire/server/form.blade.php @@ -22,6 +22,7 @@ Submit + @isset($uptime) From 7fd93ab556dc3b244c915439dd866da242955fad Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 2 May 2023 17:53:06 +0200 Subject: [PATCH 003/357] new builder image --- .github/workflows/coolify-builder.yml | 4 ++-- docker/{builder => coolify-builder}/Dockerfile | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) rename docker/{builder => coolify-builder}/Dockerfile (68%) diff --git a/.github/workflows/coolify-builder.yml b/.github/workflows/coolify-builder.yml index 24f1c91a9..e044ed5a3 100644 --- a/.github/workflows/coolify-builder.yml +++ b/.github/workflows/coolify-builder.yml @@ -2,7 +2,7 @@ name: Coolify Builder (v4) on: push: - branches: ["this-does-not-exist"] + branches: ["v4", "v4-next"] env: REGISTRY: ghcr.io @@ -24,7 +24,7 @@ jobs: with: no-cache: true context: . - file: docker/builder/Dockerfile + file: docker/coolify-builder/Dockerfile platforms: linux/amd64 push: true tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest diff --git a/docker/builder/Dockerfile b/docker/coolify-builder/Dockerfile similarity index 68% rename from docker/builder/Dockerfile rename to docker/coolify-builder/Dockerfile index 868c48cd3..806cf2169 100644 --- a/docker/builder/Dockerfile +++ b/docker/coolify-builder/Dockerfile @@ -17,12 +17,14 @@ WORKDIR /artifacts RUN apk add --no-cache bash curl git git-lfs openssh-client tar tini RUN mkdir -p ~/.docker/cli-plugins RUN if [[ ${TARGETPLATFORM} == 'linux/amd64' ]]; then \ - curl -SL https://github.com/docker/buildx/releases/download/v${DOCKER_BUILDX_VERSION}/buildx-v0.10.4.linux-amd64 -o ~/.docker/cli-plugins/docker-buildx && \ - curl -SL https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}}/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose && \ - (curl -sSL "https://github.com/buildpacks/pack/releases/download/v${PACK_VERSION}/pack-v${PACK_VERSION}-linux.tgz" | sudo tar -C /usr/local/bin/ --no-same-owner -xzv pack) && \ + curl -SL https://github.com/docker/buildx/releases/download/v${DOCKER_BUILDX_VERSION}/buildx-v${DOCKER_BUILDX_VERSION}.linux-amd64 -o ~/.docker/cli-plugins/docker-buildx && \ + curl -SL https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose && \ + (curl -sSL https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz | tar -C /usr/bin/ --no-same-owner -xzv --strip-components=1 docker/docker) && \ + (curl -sSL https://github.com/buildpacks/pack/releases/download/v${PACK_VERSION}/pack-v${PACK_VERSION}-linux.tgz | tar -C /usr/local/bin/ --no-same-owner -xzv pack) && \ curl -sSL https://nixpacks.com/install.sh | bash && \ - chmod +x ~/.docker/cli-plugins/docker-compose /usr/bin/docker /usr/local/bin/pack; \ - fi + chmod +x ~/.docker/cli-plugins/docker-compose /usr/bin/docker /usr/local/bin/pack /root/.docker/cli-plugins/docker-buildx \ + ;fi +RUN # RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/docker-$DOCKER_VERSION -o /usr/bin/docker # RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/docker-compose-linux-$DOCKER_COMPOSE_VERSION -o ~/.docker/cli-plugins/docker-compose # RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/pack-$PACK_VERSION -o /usr/local/bin/pack From 58d51dd12850ea015607456e81bb5c56f453dac7 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 2 May 2023 17:58:38 +0200 Subject: [PATCH 004/357] revert --- .github/workflows/coolify-builder.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coolify-builder.yml b/.github/workflows/coolify-builder.yml index e044ed5a3..6fa1a82a5 100644 --- a/.github/workflows/coolify-builder.yml +++ b/.github/workflows/coolify-builder.yml @@ -2,7 +2,7 @@ name: Coolify Builder (v4) on: push: - branches: ["v4", "v4-next"] + branches: ["this-does-not-exist"] env: REGISTRY: ghcr.io From 910e8279a00bac0649fc394122927c6c2dbee9ba Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 2 May 2023 19:15:17 +0200 Subject: [PATCH 005/357] ssh timeout + docker install --- app/Http/Livewire/Server/Form.php | 5 +++-- bootstrap/helpers.php | 1 + scripts/run | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php index 7b512f066..d1d90d21c 100644 --- a/app/Http/Livewire/Server/Form.php +++ b/app/Http/Livewire/Server/Form.php @@ -26,8 +26,9 @@ class Form extends Component public function installDocker() { $config = base64_encode('{ "live-restore": true }'); - runRemoteCommandSync($this->server, ["mkdir -p /etc/docker/", "touch /etc/docker/daemon.json", "echo '{$config}' | base64 -d > /etc/docker/daemon.json"]); - runRemoteCommandSync($this->server, ['sh -c "$(curl --silent -fsSL https://get.docker.com)"']); + runRemoteCommandSync($this->server, [ + "curl https://releases.rancher.com/install-docker/23.0.sh | sh" + ]); } public function checkConnection() { diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 7e86b016c..36ee4cdac 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -78,6 +78,7 @@ if (!function_exists('generateSshCommand')) { $ssh_command .= "-i {$private_key_location} " . '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ' . '-o PasswordAuthentication=no ' + . '-o ConnectTimeout=3600 ' . '-o RequestTTY=no ' . '-o LogLevel=ERROR ' . "-p {$port} " diff --git a/scripts/run b/scripts/run index fca172e01..f7e56234e 100755 --- a/scripts/run +++ b/scripts/run @@ -45,7 +45,9 @@ function coolify-root { function vite { bash vendor/bin/spin exec vite bash } - +function build-builder { + act -W .github/workflows/coolify-builder.yml --secret-file .env.secrets +} function default { help } From f723b504a1c59a07c9dc09e860afc9db09dfe500 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 2 May 2023 19:25:47 +0200 Subject: [PATCH 006/357] wip --- app/Http/Livewire/Server/Form.php | 6 +++++- resources/views/livewire/server/form.blade.php | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php index d1d90d21c..e4d9916fd 100644 --- a/app/Http/Livewire/Server/Form.php +++ b/app/Http/Livewire/Server/Form.php @@ -11,6 +11,8 @@ class Form extends Component public $server_id; public Server $server; public $uptime; + public $dockerVersion; + public $dockerComposeVersion; protected $rules = [ 'server.name' => 'required|min:6', @@ -30,9 +32,11 @@ class Form extends Component "curl https://releases.rancher.com/install-docker/23.0.sh | sh" ]); } - public function checkConnection() + 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); } public function submit() { diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php index 15ead9a79..94689a045 100644 --- a/resources/views/livewire/server/form.blade.php +++ b/resources/views/livewire/server/form.blade.php @@ -21,12 +21,15 @@ - + @isset($uptime)

Connection OK

Uptime: {{ $uptime }}

+

{{ $dockerVersion }}

+

{{ $dockerComposeVersion }}

@endisset + From e7763f3b7361c14acd454a04d46f465d01e55319 Mon Sep 17 00:00:00 2001 From: Joao Patricio Date: Wed, 3 May 2023 06:15:45 +0100 Subject: [PATCH 007/357] Refactor for CoolifyTask. --- .gitignore | 1 + .../PrepareCoolifyTask.php} | 12 ++++----- .../RunRemoteProcess.php | 2 +- app/Data/CoolifyTaskArgs.php | 23 +++++++++++++++++ app/Data/RemoteProcessArgs.php | 24 ------------------ app/Http/Controllers/ProjectController.php | 5 +++- app/Http/Livewire/DeployApplication.php | 4 +-- app/Http/Livewire/PollActivity.php | 5 +++- app/Jobs/ContainerStatusJob.php | 4 +-- app/Jobs/DeployApplicationJob.php | 8 +++--- ...ocess.php => HandleCoolifyTaskInQueue.php} | 4 +-- app/Providers/AppServiceProvider.php | 3 ++- bootstrap/helpers.php | 25 +++++++++---------- .../views/livewire/poll-activity.blade.php | 5 +++- .../views/livewire/run-command.blade.php | 7 ++++-- tests/Feature/DockerCommandsTest.php | 4 +-- tests/Feature/RemoteProcessTest.php | 2 +- 17 files changed, 75 insertions(+), 63 deletions(-) rename app/Actions/{RemoteProcess/DispatchRemoteProcess.php => CoolifyTask/PrepareCoolifyTask.php} (75%) rename app/Actions/{RemoteProcess => CoolifyTask}/RunRemoteProcess.php (99%) create mode 100644 app/Data/CoolifyTaskArgs.php delete mode 100644 app/Data/RemoteProcessArgs.php rename app/Jobs/{ExecuteRemoteProcess.php => HandleCoolifyTaskInQueue.php} (89%) diff --git a/.gitignore b/.gitignore index 67c5e7aa9..084a8d2f2 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ yarn-error.log .lesshst psysh_history +.psql_history diff --git a/app/Actions/RemoteProcess/DispatchRemoteProcess.php b/app/Actions/CoolifyTask/PrepareCoolifyTask.php similarity index 75% rename from app/Actions/RemoteProcess/DispatchRemoteProcess.php rename to app/Actions/CoolifyTask/PrepareCoolifyTask.php index 2d23513ea..d9a3ece2b 100644 --- a/app/Actions/RemoteProcess/DispatchRemoteProcess.php +++ b/app/Actions/CoolifyTask/PrepareCoolifyTask.php @@ -1,16 +1,16 @@ model) { $properties = $remoteProcessArgs->toArray(); @@ -31,7 +31,7 @@ class DispatchRemoteProcess public function __invoke(): Activity { - $job = new ExecuteRemoteProcess($this->activity); + $job = new HandleCoolifyTaskInQueue($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 99% rename from app/Actions/RemoteProcess/RunRemoteProcess.php rename to app/Actions/CoolifyTask/RunRemoteProcess.php index 41e86b60d..a8c49a7c7 100644 --- a/app/Actions/RemoteProcess/RunRemoteProcess.php +++ b/app/Actions/CoolifyTask/RunRemoteProcess.php @@ -1,6 +1,6 @@ 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/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 1bcb848f7..b1c65ec61 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -62,7 +62,10 @@ class ProjectController extends Controller if (!$application) { return redirect()->route('home'); } - $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.deployment', [ 'activity' => $activity, diff --git a/app/Http/Livewire/DeployApplication.php b/app/Http/Livewire/DeployApplication.php index 8531ed7db..321e11563 100644 --- a/app/Http/Livewire/DeployApplication.php +++ b/app/Http/Livewire/DeployApplication.php @@ -48,13 +48,13 @@ class DeployApplication extends Component public function stop() { - runRemoteCommandSync($this->destination->server, ["docker stop -t 0 {$this->application->uuid} >/dev/null 2>&1"]); + instantRemoteProcess($this->destination->server, ["docker stop -t 0 {$this->application->uuid} >/dev/null 2>&1"]); $this->application->status = 'stopped'; $this->application->save(); } public function kill() { - 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/PollActivity.php b/app/Http/Livewire/PollActivity.php index da8ed5252..f29a5b01f 100644 --- a/app/Http/Livewire/PollActivity.php +++ b/app/Http/Livewire/PollActivity.php @@ -2,6 +2,7 @@ namespace App\Http\Livewire; +use App\Enums\ActivityTypes; use Livewire\Component; use Spatie\Activitylog\Models\Activity; @@ -14,7 +15,9 @@ class PollActivity 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/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index b66d9fd78..bf9cb8eec 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -35,7 +35,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) { @@ -68,7 +68,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/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.php index f9a6e1a07..055f67283 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\CoolifyInstanceSettings; @@ -53,14 +53,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/ExecuteRemoteProcess.php b/app/Jobs/HandleCoolifyTaskInQueue.php similarity index 89% rename from app/Jobs/ExecuteRemoteProcess.php rename to app/Jobs/HandleCoolifyTaskInQueue.php index 3915c2d55..d2236027e 100755 --- a/app/Jobs/ExecuteRemoteProcess.php +++ b/app/Jobs/HandleCoolifyTaskInQueue.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 HandleCoolifyTaskInQueue implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 5813a6235..1256de2cb 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,6 +2,7 @@ namespace App\Providers; +use App\Jobs\HandleCoolifyTaskInQueue; 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() === HandleCoolifyTaskInQueue::class) { } }); diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 46028e545..9e81da07c 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_uuid, + type_uuid: $type_uuid, model: $model, ), ])(); @@ -117,8 +116,8 @@ if (!function_exists('formatDockerLabelsToJson')) { })[0]; } } -if (!function_exists('runRemoteCommandSync')) { - function runRemoteCommandSync($server, array $command) +if (!function_exists('instantRemoteProcess')) { + function instantRemoteProcess($server, array $command) { $command_string = implode("\n", $command); $private_key_location = savePrivateKeyForServer($server); diff --git a/resources/views/livewire/poll-activity.blade.php b/resources/views/livewire/poll-activity.blade.php index c48f1e440..53a5987d6 100644 --- a/resources/views/livewire/poll-activity.blade.php +++ b/resources/views/livewire/poll-activity.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 @@
diff --git a/resources/views/server/show.blade.php b/resources/views/server/show.blade.php new file mode 100644 index 000000000..9491ce149 --- /dev/null +++ b/resources/views/server/show.blade.php @@ -0,0 +1,5 @@ + +

{{ $server->name }}

+ + +
diff --git a/routes/web.php b/routes/web.php index 6aa837d2d..198a0bab5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use App\Http\Controllers\HomeController; use App\Http\Controllers\ProjectController; +use App\Http\Controllers\ServerController; use Illuminate\Support\Facades\Route; /* @@ -26,6 +27,8 @@ Route::middleware(['auth'])->group(function () { 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('/server/{server:uuid}', [ServerController::class, 'show'])->name('server.show'); + // Route::get('/database/{database_uuid}', [ProjectController::class, 'database'])->name('project.database'); // Route::get('//service/{service_uuid}', [ProjectController::class, 'service'])->name('project.service'); From ce9fb38055532457663c17a4516cc9318178bb4c Mon Sep 17 00:00:00 2001 From: Joao Patricio Date: Wed, 3 May 2023 07:21:52 +0100 Subject: [PATCH 009/357] Retrofit for helpers --- app/Jobs/{HandleCoolifyTaskInQueue.php => CoolifyTask.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/Jobs/{HandleCoolifyTaskInQueue.php => CoolifyTask.php} (100%) diff --git a/app/Jobs/HandleCoolifyTaskInQueue.php b/app/Jobs/CoolifyTask.php similarity index 100% rename from app/Jobs/HandleCoolifyTaskInQueue.php rename to app/Jobs/CoolifyTask.php From 79a850f3b90419744dc687109059d6a4c8169239 Mon Sep 17 00:00:00 2001 From: Joao Patricio Date: Wed, 3 May 2023 07:24:34 +0100 Subject: [PATCH 010/357] wip --- app/Actions/CoolifyTask/PrepareCoolifyTask.php | 9 +++++++-- app/Actions/CoolifyTask/RunRemoteProcess.php | 2 +- app/Data/CoolifyTaskArgs.php | 3 +++ app/Enums/ActivityTypes.php | 2 +- .../Livewire/Destination/New/StandaloneDocker.php | 2 +- app/Http/Livewire/ForceUpgrade.php | 15 ++++++++------- app/Http/Livewire/Project/Application/Deploy.php | 2 +- app/Http/Livewire/RunCommand.php | 7 ++++--- app/Http/Livewire/Server/Form.php | 8 ++++---- app/Jobs/CoolifyTask.php | 2 +- app/Jobs/DockerCleanupDanglingImagesJob.php | 2 +- app/Providers/AppServiceProvider.php | 4 ++-- bootstrap/helpers.php | 3 ++- 13 files changed, 36 insertions(+), 25 deletions(-) diff --git a/app/Actions/CoolifyTask/PrepareCoolifyTask.php b/app/Actions/CoolifyTask/PrepareCoolifyTask.php index d9a3ece2b..c67a8bcb3 100644 --- a/app/Actions/CoolifyTask/PrepareCoolifyTask.php +++ b/app/Actions/CoolifyTask/PrepareCoolifyTask.php @@ -3,9 +3,14 @@ namespace App\Actions\CoolifyTask; use App\Data\CoolifyTaskArgs; -use App\Jobs\HandleCoolifyTaskInQueue; +use App\Jobs\CoolifyTask; use Spatie\Activitylog\Models\Activity; +/** + * The initial step to run a `CoolifyTask`: a remote SSH process + * with monitoring/tracking/trace feature. Such thing is made + * possible using an Activity model and some attributes. + */ class PrepareCoolifyTask { protected Activity $activity; @@ -31,7 +36,7 @@ class PrepareCoolifyTask public function __invoke(): Activity { - $job = new HandleCoolifyTaskInQueue($this->activity); + $job = new CoolifyTask($this->activity); dispatch($job); $this->activity->refresh(); return $this->activity; diff --git a/app/Actions/CoolifyTask/RunRemoteProcess.php b/app/Actions/CoolifyTask/RunRemoteProcess.php index a8c49a7c7..979144b01 100644 --- a/app/Actions/CoolifyTask/RunRemoteProcess.php +++ b/app/Actions/CoolifyTask/RunRemoteProcess.php @@ -36,7 +36,7 @@ class RunRemoteProcess public function __construct(Activity $activity, bool $hideFromOutput = false, bool $isFinished = false, bool $ignoreErrors = false) { - if ($activity->getExtraProperty('type') !== ActivityTypes::REMOTE_PROCESS->value && $activity->getExtraProperty('type') !== ActivityTypes::DEPLOYMENT->value) { + if ($activity->getExtraProperty('type') !== ActivityTypes::INSTANT->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 index 803143a9a..09ab923ab 100644 --- a/app/Data/CoolifyTaskArgs.php +++ b/app/Data/CoolifyTaskArgs.php @@ -6,6 +6,9 @@ use App\Enums\ProcessStatus; use Illuminate\Database\Eloquent\Model; use Spatie\LaravelData\Data; +/** + * The parameters to execute a CoolifyTask, organized in a DTO. + */ class CoolifyTaskArgs extends Data { public function __construct( diff --git a/app/Enums/ActivityTypes.php b/app/Enums/ActivityTypes.php index 5bcab7cd7..fac79267d 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 INSTANT = 'instant'; case DEPLOYMENT = 'deployment'; } 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..706417014 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::INSTANT->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::INSTANT->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/RunCommand.php b/app/Http/Livewire/RunCommand.php index 9eaa2bbd1..1e3f78f15 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::INSTANT->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::INSTANT->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::INSTANT->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/CoolifyTask.php b/app/Jobs/CoolifyTask.php index d2236027e..d96095cc4 100755 --- a/app/Jobs/CoolifyTask.php +++ b/app/Jobs/CoolifyTask.php @@ -10,7 +10,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Spatie\Activitylog\Models\Activity; -class HandleCoolifyTaskInQueue implements ShouldQueue +class CoolifyTask implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; 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/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 1256de2cb..9945221c8 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,7 +2,7 @@ namespace App\Providers; -use App\Jobs\HandleCoolifyTaskInQueue; +use App\Jobs\CoolifyTask; use Illuminate\Queue\Events\JobProcessed; use Illuminate\Support\Facades\Process; use Illuminate\Support\Facades\Queue; @@ -32,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() === HandleCoolifyTaskInQueue::class) { + if ($event->job->resolveName() === CoolifyTask::class) { } }); diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 2ff739570..49569d1a4 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -20,6 +20,7 @@ if (!function_exists('remoteProcess')) { function remoteProcess( array $command, Server $server, + string $type, ?string $type_uuid = null, ?Model $model = null, ): Activity { @@ -40,7 +41,7 @@ if (!function_exists('remoteProcess')) { EOT, port: $server->port, user: $server->user, - type: $type_uuid, + type: $type, type_uuid: $type_uuid, model: $model, ), From 7c884797d101cc6e0bb06c31d24d07dc396dcc8c Mon Sep 17 00:00:00 2001 From: Joao Patricio Date: Wed, 3 May 2023 07:25:50 +0100 Subject: [PATCH 011/357] wip --- app/Actions/CoolifyTask/RunRemoteProcess.php | 2 +- app/Enums/ActivityTypes.php | 2 +- app/Http/Livewire/ForceUpgrade.php | 4 ++-- app/Http/Livewire/RunCommand.php | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Actions/CoolifyTask/RunRemoteProcess.php b/app/Actions/CoolifyTask/RunRemoteProcess.php index 979144b01..877e95170 100644 --- a/app/Actions/CoolifyTask/RunRemoteProcess.php +++ b/app/Actions/CoolifyTask/RunRemoteProcess.php @@ -36,7 +36,7 @@ class RunRemoteProcess public function __construct(Activity $activity, bool $hideFromOutput = false, bool $isFinished = false, bool $ignoreErrors = false) { - if ($activity->getExtraProperty('type') !== ActivityTypes::INSTANT->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/Enums/ActivityTypes.php b/app/Enums/ActivityTypes.php index fac79267d..47fec9424 100644 --- a/app/Enums/ActivityTypes.php +++ b/app/Enums/ActivityTypes.php @@ -4,6 +4,6 @@ namespace App\Enums; enum ActivityTypes: string { - case INSTANT = 'instant'; + case INLINE = 'inline'; case DEPLOYMENT = 'deployment'; } diff --git a/app/Http/Livewire/ForceUpgrade.php b/app/Http/Livewire/ForceUpgrade.php index 706417014..bec3ee0f8 100644 --- a/app/Http/Livewire/ForceUpgrade.php +++ b/app/Http/Livewire/ForceUpgrade.php @@ -21,7 +21,7 @@ class ForceUpgrade extends Component ]); remoteProcess([ "sleep 10" - ], $server, ActivityTypes::INSTANT->value); + ], $server, ActivityTypes::INLINE->value); $this->emit('updateInitiated'); } else { $latestVersion = getLatestVersionOfCoolify(); @@ -44,7 +44,7 @@ class ForceUpgrade extends Component remoteProcess([ "bash /data/coolify/source/upgrade.sh $latestVersion" - ], $server, ActivityTypes::INSTANT->value); + ], $server, ActivityTypes::INLINE->value); $this->emit('updateInitiated'); } diff --git a/app/Http/Livewire/RunCommand.php b/app/Http/Livewire/RunCommand.php index 1e3f78f15..41002ca17 100755 --- a/app/Http/Livewire/RunCommand.php +++ b/app/Http/Livewire/RunCommand.php @@ -32,19 +32,19 @@ class RunCommand extends Component public function runCommand() { $this->isKeepAliveOn = true; - $this->activity = remoteProcess([$this->command], Server::where('uuid', $this->server)->first(), ActivityTypes::INSTANT->value); + $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(), ActivityTypes::INSTANT->value); + $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(), ActivityTypes::INSTANT->value); + $this->activity = remoteProcess([' cd projects/dummy-project', 'docker-compose build --no-cache'], Server::where('uuid', $this->server)->first(), ActivityTypes::INLINE->value); } public function polling() From aab29f9077b557da878e9a41fa1e86eb58872dbf Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 08:31:50 +0200 Subject: [PATCH 012/357] force migrate in nightly --- docker/coolify-builder/Dockerfile | 11 +++-------- .../prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up | 9 ++++++++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/docker/coolify-builder/Dockerfile b/docker/coolify-builder/Dockerfile index 806cf2169..2b310a5e9 100644 --- a/docker/coolify-builder/Dockerfile +++ b/docker/coolify-builder/Dockerfile @@ -17,20 +17,15 @@ WORKDIR /artifacts RUN apk add --no-cache bash curl git git-lfs openssh-client tar tini RUN mkdir -p ~/.docker/cli-plugins RUN if [[ ${TARGETPLATFORM} == 'linux/amd64' ]]; then \ - curl -SL https://github.com/docker/buildx/releases/download/v${DOCKER_BUILDX_VERSION}/buildx-v${DOCKER_BUILDX_VERSION}.linux-amd64 -o ~/.docker/cli-plugins/docker-buildx && \ - curl -SL https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose && \ + curl -sSL https://github.com/docker/buildx/releases/download/v${DOCKER_BUILDX_VERSION}/buildx-v${DOCKER_BUILDX_VERSION}.linux-amd64 -o ~/.docker/cli-plugins/docker-buildx && \ + curl -sSL https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose && \ (curl -sSL https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz | tar -C /usr/bin/ --no-same-owner -xzv --strip-components=1 docker/docker) && \ (curl -sSL https://github.com/buildpacks/pack/releases/download/v${PACK_VERSION}/pack-v${PACK_VERSION}-linux.tgz | tar -C /usr/local/bin/ --no-same-owner -xzv pack) && \ curl -sSL https://nixpacks.com/install.sh | bash && \ chmod +x ~/.docker/cli-plugins/docker-compose /usr/bin/docker /usr/local/bin/pack /root/.docker/cli-plugins/docker-buildx \ ;fi RUN -# RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/docker-$DOCKER_VERSION -o /usr/bin/docker -# RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/docker-compose-linux-$DOCKER_COMPOSE_VERSION -o ~/.docker/cli-plugins/docker-compose -# RUN curl -SL https://cdn.coollabs.io/bin/$TARGETPLATFORM/pack-$PACK_VERSION -o /usr/local/bin/pack -# RUN curl -sSL https://nixpacks.com/install.sh | bash -# RUN chmod +x ~/.docker/cli-plugins/docker-compose /usr/bin/docker /usr/local/bin/pack ENTRYPOINT ["/sbin/tini", "--"] -CMD ["sh", "-c", "while true; do sleep 3600; done"] +CMD ["sh", "-c", "while true; do sleep 3600 && exit 0; done"] diff --git a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up index 250d5d8b1..8618a7e8c 100644 --- a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up +++ b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up @@ -1,2 +1,9 @@ #!/command/execlineb -P -php /var/www/html/artisan migrate --force --isolated +VERSION=$(php bootstrap/getVersion.php) + +if echo "$VERSION" | grep -q "nightly"; then + php /var/www/html/artisan migrate:fresh --force + php /var/www/html/artisan db:seed --class ProductionSeeder --force +else + php /var/www/html/artisan migrate --force --isolated +fi From 83392dd8dc5ad61be99110561d7c72c37d11f6cc Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 08:36:23 +0200 Subject: [PATCH 013/357] disabling docker image ci for now --- .github/workflows/docker-image.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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: From f6c7343b70861b0b91b50c3dd0f1013505940c2e Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 08:51:03 +0200 Subject: [PATCH 014/357] fix: deployment_uuid -> type_uuid --- app/Http/Controllers/ApplicationController.php | 2 +- app/Http/Livewire/Project/Application/GetDeployments.php | 2 +- app/Models/Application.php | 5 ++--- resources/views/project/application/deployments.blade.php | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/ApplicationController.php b/app/Http/Controllers/ApplicationController.php index 3cc33c203..877ca3254 100644 --- a/app/Http/Controllers/ApplicationController.php +++ b/app/Http/Controllers/ApplicationController.php @@ -56,7 +56,7 @@ 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(); return view('project.application.deployment', [ 'application' => $application, 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/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/resources/views/project/application/deployments.blade.php b/resources/views/project/application/deployments.blade.php index dd159d173..3d3e76d5b 100644 --- a/resources/views/project/application/deployments.blade.php +++ b/resources/views/project/application/deployments.blade.php @@ -3,7 +3,7 @@
@forelse ($deployments as $deployment) - + @empty

No deployments found.

@endforelse From ac0c88f486aa26e751050a64252c227a5bdfcf39 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 08:51:11 +0200 Subject: [PATCH 015/357] add new run commands --- scripts/run | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/run b/scripts/run index f7e56234e..9aad129ac 100755 --- a/scripts/run +++ b/scripts/run @@ -48,6 +48,12 @@ function vite { function build-builder { act -W .github/workflows/coolify-builder.yml --secret-file .env.secrets } +function tinker { + bash vendor/bin/spin exec -u webuser coolify php artisan tinker +} +function db { + bash vendor/bin/spin exec -u webuser coolify php artisan db +} function default { help } From 22028e23e3d724b7d07f11b41cacd9284687fde9 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 08:53:00 +0200 Subject: [PATCH 016/357] redirect if no deployment found --- app/Http/Controllers/ApplicationController.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ApplicationController.php b/app/Http/Controllers/ApplicationController.php index 877ca3254..f477549db 100644 --- a/app/Http/Controllers/ApplicationController.php +++ b/app/Http/Controllers/ApplicationController.php @@ -57,7 +57,13 @@ class ApplicationController extends Controller return redirect()->route('dashboard'); } $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, From fd02219c833a47e4a3bbcfbabf62481ae86a246f Mon Sep 17 00:00:00 2001 From: Joao Patricio Date: Wed, 3 May 2023 07:53:50 +0100 Subject: [PATCH 017/357] wip --- app/Http/Livewire/Server/Proxy.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Livewire/Server/Proxy.php b/app/Http/Livewire/Server/Proxy.php index b01db728c..fe3ed74f3 100644 --- a/app/Http/Livewire/Server/Proxy.php +++ b/app/Http/Livewire/Server/Proxy.php @@ -2,6 +2,7 @@ namespace App\Http\Livewire\Server; +use App\Enums\ActivityTypes; use App\Models\Server; use Livewire\Component; @@ -18,7 +19,7 @@ class Proxy extends Component public function runInstallProxy() { - $activity = remoteProcess(['ls -alh'], $this->server); + $activity = remoteProcess(['ls -alh'], $this->server, ActivityTypes::INLINE->value); $this->emit('newMonitorActivity', $activity->id); } From e20cdd83f887772adb45cdbcbc18d3f761bea668 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 08:55:03 +0200 Subject: [PATCH 018/357] fix: read env from config, bc of cache --- app/Http/Livewire/Project/New/PublicGitRepository.php | 2 +- resources/views/livewire/project/application/deploy.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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 From a3517d28fac34f894cbf57c7c5a2c73d55e8b90c Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 09:00:57 +0200 Subject: [PATCH 019/357] fix --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index d34bc6182..48ec5414f 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -11,7 +11,7 @@ OS_TYPE=$(cat /etc/os-release | grep -w "ID" | cut -d "=" -f 2 | tr -d '"') OS_VERSION=$(cat /etc/os-release | grep -w "VERSION_ID" | cut -d "=" -f 2 | tr -d '"') LATEST_VERSION=$(curl --silent https://get.coollabs.io/versions.json | grep -i version | sed -n '2p' | xargs | awk '{print $2}' | tr -d ',') -if [ "$EUID" -ne 0 ]; then +if [ $EUID -ne 0 ]; then echo "Please run as root" exit fi From 218e5ecb359e78e01f0db508b1b42f5ff45123e2 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 09:01:58 +0200 Subject: [PATCH 020/357] fix --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index 48ec5414f..4d512120a 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -11,7 +11,7 @@ OS_TYPE=$(cat /etc/os-release | grep -w "ID" | cut -d "=" -f 2 | tr -d '"') OS_VERSION=$(cat /etc/os-release | grep -w "VERSION_ID" | cut -d "=" -f 2 | tr -d '"') LATEST_VERSION=$(curl --silent https://get.coollabs.io/versions.json | grep -i version | sed -n '2p' | xargs | awk '{print $2}' | tr -d ',') -if [ $EUID -ne 0 ]; then +if [ $EUID != 0 ]; then echo "Please run as root" exit fi From c3cb5c7356b32ba318e4c97fad05e46c6123b9c2 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 09:02:20 +0200 Subject: [PATCH 021/357] fix db-migration --- docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up index 8618a7e8c..36ca6da39 100644 --- a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up +++ b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up @@ -1,7 +1,7 @@ #!/command/execlineb -P VERSION=$(php bootstrap/getVersion.php) -if echo "$VERSION" | grep -q "nightly"; then +if [ echo "$VERSION" | grep -q "nightly" ]; then php /var/www/html/artisan migrate:fresh --force php /var/www/html/artisan db:seed --class ProductionSeeder --force else From 6f3f31b8722fec5fecc2932a36cd6a5f782c1bde Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 09:06:33 +0200 Subject: [PATCH 022/357] test --- .../etc/s6-overlay/s6-rc.d/db-migration/up | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up index 36ca6da39..d49e2b59a 100644 --- a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up +++ b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up @@ -1,9 +1,9 @@ #!/command/execlineb -P VERSION=$(php bootstrap/getVersion.php) - -if [ echo "$VERSION" | grep -q "nightly" ]; then - php /var/www/html/artisan migrate:fresh --force - php /var/www/html/artisan db:seed --class ProductionSeeder --force -else - php /var/www/html/artisan migrate --force --isolated -fi +echo "$VERSION" +# if [ echo "$VERSION" | grep -q "nightly" ]; then +# php /var/www/html/artisan migrate:fresh --force +# php /var/www/html/artisan db:seed --class ProductionSeeder --force +# else +php /var/www/html/artisan migrate --force --isolated +# fi From 124e5d94eddd2ec30140a9d06c35d43178c1a01c Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 09:09:43 +0200 Subject: [PATCH 023/357] revert migration --- docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up index d49e2b59a..250d5d8b1 100644 --- a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up +++ b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up @@ -1,9 +1,2 @@ #!/command/execlineb -P -VERSION=$(php bootstrap/getVersion.php) -echo "$VERSION" -# if [ echo "$VERSION" | grep -q "nightly" ]; then -# php /var/www/html/artisan migrate:fresh --force -# php /var/www/html/artisan db:seed --class ProductionSeeder --force -# else php /var/www/html/artisan migrate --force --isolated -# fi From 476abd30f40435997f14e8a2e0a27b28782a2c39 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 09:24:40 +0200 Subject: [PATCH 024/357] check with sh --- .../prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up index 250d5d8b1..42594c737 100644 --- a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up +++ b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up @@ -1,2 +1,9 @@ -#!/command/execlineb -P -php /var/www/html/artisan migrate --force --isolated +#!/bin/sh +VERSION=$(php bootstrap/getVersion.php) + +if echo "$VERSION" | grep -q "nightly"; then + php /var/www/html/artisan migrate:fresh --force + php /var/www/html/artisan db:seed --class ProductionSeeder --force +else + php /var/www/html/artisan migrate --force --isolated +fi From 3e475d87eb2cafa51cab5c37defd2c2f7b7cd3d1 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 09:27:00 +0200 Subject: [PATCH 025/357] ok it is not working --- .../prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up index 42594c737..250d5d8b1 100644 --- a/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up +++ b/docker/prod-ssu/etc/s6-overlay/s6-rc.d/db-migration/up @@ -1,9 +1,2 @@ -#!/bin/sh -VERSION=$(php bootstrap/getVersion.php) - -if echo "$VERSION" | grep -q "nightly"; then - php /var/www/html/artisan migrate:fresh --force - php /var/www/html/artisan db:seed --class ProductionSeeder --force -else - php /var/www/html/artisan migrate --force --isolated -fi +#!/command/execlineb -P +php /var/www/html/artisan migrate --force --isolated From ad671cfcf117037fd1b3af9caa6918992a47f0e0 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 09:38:53 +0200 Subject: [PATCH 026/357] use same args for remoteProcess and instantRemoteProcess --- .../Destination/New/StandaloneDocker.php | 2 +- app/Http/Livewire/ForceUpgrade.php | 13 ++++++------ .../Livewire/Project/Application/Deploy.php | 2 +- app/Http/Livewire/Server/Form.php | 20 +++++++++++++------ app/Jobs/ContainerStatusJob.php | 4 ++-- app/Jobs/DockerCleanupDanglingImagesJob.php | 2 +- bootstrap/helpers.php | 2 +- 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/app/Http/Livewire/Destination/New/StandaloneDocker.php b/app/Http/Livewire/Destination/New/StandaloneDocker.php index 5abf19a90..7b1c1089b 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); - instantRemoteProcess($server, ['docker network create --attachable ' . $this->network], throwError: false); + instantRemoteProcess(['docker network create --attachable ' . $this->network], $server, throwError: false); return redirect()->route('destination.show', $docker->uuid); } } diff --git a/app/Http/Livewire/ForceUpgrade.php b/app/Http/Livewire/ForceUpgrade.php index bec3ee0f8..f73bf9cee 100644 --- a/app/Http/Livewire/ForceUpgrade.php +++ b/app/Http/Livewire/ForceUpgrade.php @@ -16,9 +16,9 @@ class ForceUpgrade extends Component if (!$server) { return; } - instantRemoteProcess($server, [ + instantRemoteProcess([ "sleep 2" - ]); + ], $server); remoteProcess([ "sleep 10" ], $server, ActivityTypes::INLINE->value); @@ -32,15 +32,16 @@ class ForceUpgrade extends Component return; } - instantRemoteProcess($server, [ + instantRemoteProcess([ "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", - ]); - instantRemoteProcess($server, [ + ], $server); + + instantRemoteProcess([ "docker compose -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml pull", - ]); + ], $server); remoteProcess([ "bash /data/coolify/source/upgrade.sh $latestVersion" diff --git a/app/Http/Livewire/Project/Application/Deploy.php b/app/Http/Livewire/Project/Application/Deploy.php index ba31e4fbf..23d6bdbee 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() { - instantRemoteProcess($this->destination->server, ["docker rm -f {$this->application->uuid}"]); + instantRemoteProcess(["docker rm -f {$this->application->uuid}"], $this->destination->server); if ($this->application->status != 'exited') { $this->application->status = 'exited'; $this->application->save(); diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php index 08d2d7cf9..136d37b98 100644 --- a/app/Http/Livewire/Server/Form.php +++ b/app/Http/Livewire/Server/Form.php @@ -2,6 +2,7 @@ namespace App\Http\Livewire\Server; +use App\Enums\ActivityTypes; use App\Models\Server; use Illuminate\Support\Facades\Validator; use Livewire\Component; @@ -28,15 +29,22 @@ class Form extends Component public function installDocker() { $config = base64_encode('{ "live-restore": true }'); - instantRemoteProcess($this->server, [ - "curl https://releases.rancher.com/install-docker/23.0.sh | sh" - ]); + remoteProcess([ + "curl https://releases.rancher.com/install-docker/23.0.sh | sh", + "echo '{$config}' | base64 -d > /etc/docker/daemon.json", + "systemctl restart docker" + ], $this->server, ActivityTypes::INLINE->value); } public function checkServer() { - $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); + try { + + $this->uptime = instantRemoteProcess(['uptime'], $this->server); + $this->dockerVersion = instantRemoteProcess(['docker version|head -2|grep -i version'], $this->server, false); + $this->dockerComposeVersion = instantRemoteProcess(['docker compose version|head -2|grep -i version'], $this->server, false); + } catch (\Exception $e) { + $this->addError('server.ip', $e->getMessage()); + } } public function submit() { diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index 5924cae3a..bc05d6e0b 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 = instantRemoteProcess($server, ['docker ps -a -q --format \'{{json .}}\'']); + $output = instantRemoteProcess(['docker ps -a -q --format \'{{json .}}\''], $server); $containers = $containers->concat(formatDockerCmdOutputToJson($output)); } foreach ($containers as $container) { @@ -67,7 +67,7 @@ class ContainerStatusJob implements ShouldQueue return; } if ($application->destination->server) { - $container = instantRemoteProcess($application->destination->server, ["docker inspect --format '{{json .State}}' {$this->container_id}"]); + $container = instantRemoteProcess(["docker inspect --format '{{json .State}}' {$this->container_id}"], $application->destination->server); $container = formatDockerCmdOutputToJson($container); $application->status = $container[0]['Status']; $application->save(); diff --git a/app/Jobs/DockerCleanupDanglingImagesJob.php b/app/Jobs/DockerCleanupDanglingImagesJob.php index 0938b6bb8..256016330 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) { - instantRemoteProcess($server, ['docker image prune -f']); + instantRemoteProcess(['docker image prune -f'], $server); } } catch (\Exception $e) { Log::error($e->getMessage()); diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 49569d1a4..51aff79a7 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -120,7 +120,7 @@ if (!function_exists('formatDockerLabelsToJson')) { } } if (!function_exists('instantRemoteProcess')) { - function instantRemoteProcess(Server $server, array $command, $throwError = true) + function instantRemoteProcess(array $command, Server $server, $throwError = true) { $command_string = implode("\n", $command); $private_key_location = savePrivateKeyForServer($server); From 581930d8c65c9f0f3fe7df4777833a3637bf042b Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 09:43:01 +0200 Subject: [PATCH 027/357] update server check --- app/Http/Livewire/Server/Form.php | 14 +++++++++++--- resources/views/livewire/server/form.blade.php | 11 +++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php index 136d37b98..8c75f887e 100644 --- a/app/Http/Livewire/Server/Form.php +++ b/app/Http/Livewire/Server/Form.php @@ -38,12 +38,20 @@ class Form extends Component public function checkServer() { try { - - $this->uptime = instantRemoteProcess(['uptime'], $this->server); + $this->uptime = instantRemoteProcess(['uptime'], $this->server, false); + if (!$this->uptime) { + $this->uptime = 'Server not reachable.'; + throw new \Exception('Server not reachable.'); + } $this->dockerVersion = instantRemoteProcess(['docker version|head -2|grep -i version'], $this->server, false); + if (!$this->dockerVersion) { + $this->dockerVersion = 'Not installed.'; + } $this->dockerComposeVersion = instantRemoteProcess(['docker compose version|head -2|grep -i version'], $this->server, false); + if (!$this->dockerComposeVersion) { + $this->dockerComposeVersion = 'Not installed.'; + } } catch (\Exception $e) { - $this->addError('server.ip', $e->getMessage()); } } public function submit() diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php index 94689a045..77af63b9a 100644 --- a/resources/views/livewire/server/form.blade.php +++ b/resources/views/livewire/server/form.blade.php @@ -22,14 +22,17 @@ Submit - + {{-- --}}
@isset($uptime) -

Connection OK

Uptime: {{ $uptime }}

-

{{ $dockerVersion }}

-

{{ $dockerComposeVersion }}

+ @endisset + @isset($dockerVersion) +

Docker Engine: {{ $dockerVersion }}

+ @endisset + @isset($dockerComposeVersion) +

Docker Compose: {{ $dockerComposeVersion }}

@endisset
From 97572f158c66d20ffde2ccca2f1de972c403e411 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 09:45:18 +0200 Subject: [PATCH 028/357] add docker install script --- scripts/install-docker.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 scripts/install-docker.sh diff --git a/scripts/install-docker.sh b/scripts/install-docker.sh new file mode 100644 index 000000000..292995fa1 --- /dev/null +++ b/scripts/install-docker.sh @@ -0,0 +1,5 @@ +#!/bin/bash +curl https://releases.rancher.com/install-docker/23.0.sh | sh +echo "Docker installed successfully" +echo '{ "live-restore": true }' >/etc/docker/daemon.json +systemctl restart docker From 8bfdcdbf440a09f15a9b62ef7e6f04bc2f87ab81 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 09:57:06 +0200 Subject: [PATCH 029/357] update scripts --- app/Console/Commands/SyncBunny.php | 10 +++++++--- scripts/install.sh | 8 ++++---- scripts/run | 3 +-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/Console/Commands/SyncBunny.php b/app/Console/Commands/SyncBunny.php index 7757a7e6c..27d4a8b79 100644 --- a/app/Console/Commands/SyncBunny.php +++ b/app/Console/Commands/SyncBunny.php @@ -37,6 +37,7 @@ class SyncBunny extends Command $compose_file = "docker-compose.yml"; $compose_file_prod = "docker-compose.prod.yml"; $upgrade_script = "upgrade.sh"; + $docker_install_script = "install-docker.sh"; $production_env = ".env.production"; PendingRequest::macro('storage', function ($file) { @@ -53,8 +54,9 @@ class SyncBunny extends Command Http::pool(fn (Pool $pool) => [ $pool->storage(file: "$parent_dir/$compose_file")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$compose_file"), $pool->storage(file: "$parent_dir/$compose_file_prod")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$compose_file_prod"), - $pool->storage(file: "$parent_dir/scripts/$upgrade_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$upgrade_script"), $pool->storage(file: "$parent_dir/$production_env")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$production_env"), + $pool->storage(file: "$parent_dir/scripts/$upgrade_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$upgrade_script"), + $pool->storage(file: "$parent_dir/scripts/$docker_install_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$docker_install_script"), ]); $res = Http::withHeaders([ @@ -64,13 +66,15 @@ class SyncBunny extends Command "url" => "$bunny_cdn/$bunny_cdn_path/$compose_file", "url" => "$bunny_cdn/$bunny_cdn_path/$compose_file_prod", "url" => "$bunny_cdn/$bunny_cdn_path/$upgrade_script", - "url" => "$bunny_cdn/$bunny_cdn_path/$production_env" + "url" => "$bunny_cdn/$bunny_cdn_path/$production_env", + "url" => "$bunny_cdn/$bunny_cdn_path/$docker_install_script" ]); if ($res->ok()) { echo "All files uploaded & purged...\n"; + return; } + throw new \Exception("Something went wrong."); } catch (\Exception $e) { - echo "Something went wrong.\n"; echo $e->getMessage(); } } diff --git a/scripts/install.sh b/scripts/install.sh index 4d512120a..8aa22b17e 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -2,10 +2,12 @@ ## Do not modify this file. You will lost the ability to installation and autoupdate! ########### -## Always run "php artisan app:sync-to-bunny-cdn --env=secrets" if you update this file. +## Always run "php artisan app:sync-to-bunny-cdn --env=secrets" or "scripts/run sync-bunny" if you update this file. ########### VERSION="1.0.0" +DOCKER_VERSION="23.0" + CDN="https://coolify-cdn.b-cdn.net/files" OS_TYPE=$(cat /etc/os-release | grep -w "ID" | cut -d "=" -f 2 | tr -d '"') OS_VERSION=$(cat /etc/os-release | grep -w "VERSION_ID" | cut -d "=" -f 2 | tr -d '"') @@ -18,9 +20,7 @@ fi if ! [ -x "$(command -v docker)" ]; then echo "Docker is not installed. Installing Docker..." - curl -fsSL https://get.docker.com -o get-docker.sh - sh get-docker.sh - rm get-docker.sh + curl https://releases.rancher.com/install-docker/${DOCKER_VERSION}.sh | sh echo "Docker installed successfully" fi diff --git a/scripts/run b/scripts/run index 9aad129ac..6c4cdcb5d 100755 --- a/scripts/run +++ b/scripts/run @@ -21,8 +21,7 @@ function help { compgen -A function | cat -n } function sync-bunny { - bash vendor/bin/spin exec -u webuser coolify php artisan sync:bunny --env=secret || - php artisan sync:bunny --env=secrets + php artisan sync:bunny --env=secrets } function queue { bash vendor/bin/spin exec -u webuser coolify php artisan queue:listen From 1ad7d885b3f22f307af2ae59d04e528d8217ce3a Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 10:06:15 +0200 Subject: [PATCH 030/357] migrate on appservice boot --- app/Http/Livewire/ForceUpgrade.php | 1 - app/Providers/AppServiceProvider.php | 15 +++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/app/Http/Livewire/ForceUpgrade.php b/app/Http/Livewire/ForceUpgrade.php index f73bf9cee..52c9a28ad 100644 --- a/app/Http/Livewire/ForceUpgrade.php +++ b/app/Http/Livewire/ForceUpgrade.php @@ -10,7 +10,6 @@ class ForceUpgrade extends Component { public function upgrade() { - //if (env('APP_ENV') === 'local') { if (config('app.env') === 'local') { $server = Server::where('ip', 'coolify-testing-host')->first(); if (!$server) { diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 9945221c8..ab8ad04c4 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -7,6 +7,7 @@ use Illuminate\Queue\Events\JobProcessed; use Illuminate\Support\Facades\Process; use Illuminate\Support\Facades\Queue; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; class AppServiceProvider extends ServiceProvider { @@ -15,14 +16,9 @@ class AppServiceProvider extends ServiceProvider */ public function register(): void { - // @TODO: Is this the best place to run the seeder? - // if (env('APP_ENV') === 'production') { - // dump('Seed default data.'); - // Process::run('php artisan db:seed --class=ProductionSeeder --force'); - // } else { - // dump('Not in production environment.'); - // } - // + if (config('app.env') === 'production' && Str::contains(config('coolify.version'), ['nightly'])) { + Process::run('php artisan migrate:fresh --force --seed --seeder=ProductionSeeder'); + } } /** @@ -31,9 +27,8 @@ class AppServiceProvider extends ServiceProvider public function boot(): void { Queue::after(function (JobProcessed $event) { - // @TODO: Remove `coolify-builder` container after the remoteProcess job is finishged and remoteProcess->type == `deployment`. + // @TODO: Remove `coolify-builder` container after the remoteProcess job is finishged and remoteProcess->type == `deployment`. if ($event->job->resolveName() === CoolifyTask::class) { - } }); } From e174e2f68ff23bf48ebeaa912db576b4591663a8 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 10:24:13 +0200 Subject: [PATCH 031/357] revert appserviceprovider --- app/Providers/AppServiceProvider.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ab8ad04c4..65fccab1b 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -16,9 +16,9 @@ class AppServiceProvider extends ServiceProvider */ public function register(): void { - if (config('app.env') === 'production' && Str::contains(config('coolify.version'), ['nightly'])) { - Process::run('php artisan migrate:fresh --force --seed --seeder=ProductionSeeder'); - } + // if (config('app.env') === 'production' && Str::contains(config('coolify.version'), ['nightly'])) { + // Process::run('php artisan migrate:fresh --force --seed --seeder=ProductionSeeder'); + // } } /** From b69410697d6385b3a7840754c31cc968a6de91db Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 3 May 2023 10:25:44 +0200 Subject: [PATCH 032/357] delete server --- app/Http/Livewire/Server/Form.php | 5 +++ app/Http/Livewire/Server/New/ByIp.php | 4 +++ app/View/Components/FormInput.php | 1 + .../views/livewire/server/form.blade.php | 3 ++ .../views/livewire/server/new/by-ip.blade.php | 35 +++++++++++-------- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php index 8c75f887e..1c01345bb 100644 --- a/app/Http/Livewire/Server/Form.php +++ b/app/Http/Livewire/Server/Form.php @@ -54,6 +54,11 @@ class Form extends Component } catch (\Exception $e) { } } + public function delete() + { + $this->server->delete(); + redirect()->route('dashboard'); + } public function submit() { $this->validate(); diff --git a/app/Http/Livewire/Server/New/ByIp.php b/app/Http/Livewire/Server/New/ByIp.php index f003beb5f..e5fdafa98 100644 --- a/app/Http/Livewire/Server/New/ByIp.php +++ b/app/Http/Livewire/Server/New/ByIp.php @@ -45,6 +45,10 @@ class ByIp extends Component } public function submit() { + if (!$this->private_key_id) { + $this->addError('private_key_id', 'The private key field is required.'); + return; + } $server = Server::create([ 'name' => $this->name, 'description' => $this->description, diff --git a/app/View/Components/FormInput.php b/app/View/Components/FormInput.php index a96dc3b6c..efe511b6a 100644 --- a/app/View/Components/FormInput.php +++ b/app/View/Components/FormInput.php @@ -19,6 +19,7 @@ class FormInput extends Component public string|null $type = 'text', public bool $instantSave = false, public bool $disabled = false, + public bool $hidden = false ) { } diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php index 77af63b9a..cd593ebd5 100644 --- a/resources/views/livewire/server/form.blade.php +++ b/resources/views/livewire/server/form.blade.php @@ -22,6 +22,9 @@ Submit + {{-- --}} diff --git a/resources/views/livewire/server/new/by-ip.blade.php b/resources/views/livewire/server/new/by-ip.blade.php index a12ad1523..6f16bece7 100644 --- a/resources/views/livewire/server/new/by-ip.blade.php +++ b/resources/views/livewire/server/new/by-ip.blade.php @@ -5,22 +5,29 @@ +