From f9c469497e4e9fdeeb95d4b084302ed9882eb050 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 26 Oct 2023 11:15:37 +0200 Subject: [PATCH 1/8] version++ --- config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/sentry.php b/config/sentry.php index 9041a7606..826794a5a 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.104', + 'release' => '4.0.0-beta.105', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 62ca33fbb..5bcfd4f1b 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Thu, 26 Oct 2023 11:38:37 +0200 Subject: [PATCH 2/8] fix: custom labels only should have non-coolify labels fix: pull helper image every 10 minutes instead of every deployment --- app/Console/Kernel.php | 16 ++++++++++ app/Jobs/ApplicationDeploymentJob.php | 13 ++++---- app/Jobs/PullHelperImageJob.php | 45 +++++++++++++++++++++++++++ bootstrap/helpers/docker.php | 2 -- 4 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 app/Jobs/PullHelperImageJob.php diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 8bbab0081..4aa0fc339 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -8,6 +8,7 @@ use App\Jobs\DatabaseBackupJob; use App\Jobs\DockerCleanupJob; use App\Jobs\InstanceAutoUpdateJob; use App\Jobs\ContainerStatusJob; +use App\Jobs\PullHelperImageJob; use App\Models\InstanceSettings; use App\Models\ScheduledDatabaseBackup; use App\Models\Server; @@ -19,20 +20,35 @@ class Kernel extends ConsoleKernel protected function schedule(Schedule $schedule): void { if (isDev()) { + // Instance Jobs $schedule->command('horizon:snapshot')->everyMinute(); $schedule->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer(); + + // Server Jobs $this->check_scheduled_backups($schedule); $this->check_resources($schedule); $this->cleanup_servers($schedule); $this->check_scheduled_backups($schedule); + $this->pull_helper_image($schedule); } else { + // Instance Jobs $schedule->command('horizon:snapshot')->everyFiveMinutes(); $schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer(); $schedule->job(new CheckResaleLicenseJob)->hourly()->onOneServer(); + + // Server Jobs $this->instance_auto_update($schedule); $this->check_scheduled_backups($schedule); $this->check_resources($schedule); $this->cleanup_servers($schedule); + $this->pull_helper_image($schedule); + } + } + private function pull_helper_image($schedule) + { + $servers = Server::all()->where('settings.is_usable', true)->where('settings.is_reachable', true); + foreach ($servers as $server) { + $schedule->job(new PullHelperImageJob($server))->everyTenMinutes()->onOneServer(); } } private function cleanup_servers($schedule) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 6017f1f1d..962ea362b 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -484,17 +484,16 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted private function prepare_builder_image() { - $pull = "--pull=always"; $helperImage = config('coolify.helper_image'); if ($this->dockerConfigFileExists === 'OK') { - $runCommand = "docker run {$pull} -d --network {$this->destination->network} -v /:/host --name {$this->deployment_uuid} --rm -v {$this->serverUserHomeDir}/.docker/config.json:/root/.docker/config.json:ro -v /var/run/docker.sock:/var/run/docker.sock {$helperImage}"; + $runCommand = "docker run -d --network {$this->destination->network} -v /:/host --name {$this->deployment_uuid} --rm -v {$this->serverUserHomeDir}/.docker/config.json:/root/.docker/config.json:ro -v /var/run/docker.sock:/var/run/docker.sock {$helperImage}"; } else { - $runCommand = "docker run {$pull} -d --network {$this->destination->network} -v /:/host --name {$this->deployment_uuid} --rm -v /var/run/docker.sock:/var/run/docker.sock {$helperImage}"; + $runCommand = "docker run -d --network {$this->destination->network} -v /:/host --name {$this->deployment_uuid} --rm -v /var/run/docker.sock:/var/run/docker.sock {$helperImage}"; } $this->execute_remote_command( [ - "echo -n 'Pulling helper image from $helperImage.'", + "echo -n 'Preparing container with helper image: $helperImage.'", ], [ $runCommand, @@ -676,10 +675,12 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted $volume_names = $this->generate_local_persistent_volumes_only_volume_names(); $environment_variables = $this->generate_environment_variables($ports); - $labels = generateLabelsApplication($this->application, $this->preview); if (data_get($this->application, 'custom_labels')) { - $labels = str($this->application->custom_labels)->explode(',')->toArray(); + $labels = collect(str($this->application->custom_labels)->explode(',')->toArray()); + } else { + $labels = collect(generateLabelsApplication($this->application, $this->preview)); } + $labels = $labels->merge(defaultLabels($this->application->id, $this->application->uuid, $this->pull_request_id))->toArray(); $docker_compose = [ 'version' => '3.8', 'services' => [ diff --git a/app/Jobs/PullHelperImageJob.php b/app/Jobs/PullHelperImageJob.php new file mode 100644 index 000000000..b61a0f295 --- /dev/null +++ b/app/Jobs/PullHelperImageJob.php @@ -0,0 +1,45 @@ +server->uuid))->dontRelease()]; + } + + public function uniqueId(): string + { + return $this->server->uuid; + } + public function __construct(public Server $server) + { + } + public function handle(): void + { + try { + $helperImage = config('coolify.helper_image'); + ray("Pulling {$helperImage}"); + instant_remote_process(["docker pull -q {$helperImage}"], $this->server); + ray('PullHelperImageJob done'); + } catch (\Throwable $e) { + send_internal_notification('PullHelperImageJob failed with: ' . $e->getMessage()); + ray($e->getMessage()); + throw $e; + } + } +} diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php index 179abecb9..a61bb177c 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -212,13 +212,11 @@ function generateLabelsApplication(Application $application, ?ApplicationPreview $onlyPort = $ports[0]; } $pull_request_id = data_get($preview, 'pull_request_id', 0); - // $container_name = generateApplicationContainerName($application, $pull_request_id); $appId = $application->id; if ($pull_request_id !== 0 && $pull_request_id !== null) { $appId = $appId . '-pr-' . $pull_request_id; } $labels = collect([]); - $labels = $labels->merge(defaultLabels($appId, $application->uuid, $pull_request_id)); if ($application->fqdn) { if ($pull_request_id !== 0) { $domains = Str::of(data_get($preview, 'fqdn'))->explode(','); From 756c7f81ca95b3ca517c2a7aefb80409d48e22b8 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 26 Oct 2023 13:00:40 +0200 Subject: [PATCH 3/8] fix: if user is invited, that means its email is verified --- app/Http/Controllers/Controller.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index a2978e2ee..7c1d186ff 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -39,6 +39,10 @@ class Controller extends BaseController } else { $team = $user->teams()->first(); } + if (is_null(data_get($user, 'email_verified_at'))){ + $user->email_verified_at = now(); + $user->save(); + } Auth::login($user); session(['currentTeam' => $team]); return redirect()->route('dashboard'); From 06d7c69487e01d2c304d884167873a58da8527f1 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 26 Oct 2023 13:32:23 +0200 Subject: [PATCH 4/8] add nocodb --- templates/compose/nocodb.yaml | 16 ++++++++++++++++ templates/service-templates.json | 14 ++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 templates/compose/nocodb.yaml diff --git a/templates/compose/nocodb.yaml b/templates/compose/nocodb.yaml new file mode 100644 index 000000000..4e772b3db --- /dev/null +++ b/templates/compose/nocodb.yaml @@ -0,0 +1,16 @@ +# documentation: https://docs.nocodb.com/ +# slogan: NocoDB is an open source Airtable alternative. Turns any MySQL, PostgreSQL, SQL Server, SQLite & MariaDB into a smart-spreadsheet. +# tags: nocodb,airtable,mysql,postgresql,sqlserver,sqlite,mariadb + +services: + nocodb: + image: nocodb/nocodb + environment: + - SERVICE_FQDN_NOCODB + volumes: + - nocodb-data:/usr/app/data/ + healthcheck: + test: ["CMD", "wget", "-q", "--spider", "http://localhost:8080"] + interval: 5s + timeout: 20s + retries: 10 diff --git a/templates/service-templates.json b/templates/service-templates.json index f028ee20c..466824574 100644 --- a/templates/service-templates.json +++ b/templates/service-templates.json @@ -207,6 +207,20 @@ "code" ] }, + "nocodb": { + "documentation": "https:\/\/docs.nocodb.com\/", + "slogan": "NocoDB is an open source Airtable alternative. Turns any MySQL, PostgreSQL, SQL Server, SQLite & MariaDB into a smart-spreadsheet.", + "compose": "c2VydmljZXM6CiAgbm9jb2RiOgogICAgaW1hZ2U6IG5vY29kYi9ub2NvZGIKICAgIGVudmlyb25tZW50OgogICAgICAtIFNFUlZJQ0VfRlFETl9OT0NPREIKICAgIHZvbHVtZXM6CiAgICAgIC0gJ25vY29kYi1kYXRhOi91c3IvYXBwL2RhdGEvJwogICAgaGVhbHRoY2hlY2s6CiAgICAgIHRlc3Q6CiAgICAgICAgLSBDTUQKICAgICAgICAtIHdnZXQKICAgICAgICAtICctcScKICAgICAgICAtICctLXNwaWRlcicKICAgICAgICAtICdodHRwOi8vbG9jYWxob3N0OjgwODAnCiAgICAgIGludGVydmFsOiA1cwogICAgICB0aW1lb3V0OiAyMHMKICAgICAgcmV0cmllczogMTAK", + "tags": [ + "nocodb", + "airtable", + "mysql", + "postgresql", + "sqlserver", + "sqlite", + "mariadb" + ] + }, "openblocks": { "documentation": "https:\/\/docs.openblocks.dev\/self-hosting", "slogan": "OpenBlocks is a self-hosted, open-source, low-code platform for building internal tools.", From 52d6fb51d59902a73247df7a9216b0b65e917a8b Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 26 Oct 2023 15:53:42 +0200 Subject: [PATCH 5/8] pocketbase --- templates/compose/pocketbase.yaml | 11 +++++++++++ templates/service-templates.json | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 templates/compose/pocketbase.yaml diff --git a/templates/compose/pocketbase.yaml b/templates/compose/pocketbase.yaml new file mode 100644 index 000000000..3f77bf83f --- /dev/null +++ b/templates/compose/pocketbase.yaml @@ -0,0 +1,11 @@ +# documentation: https://pocketbase.io/docs/ +# slogan: Open Source backend for your next SaaS and Mobile app in 1 file +# tags: pocketbase,backend,saas,mobile,api + +services: + pocketbase: + image: ghcr.io/coollabsio/pocketbase:latest + environment: + - SERVICE_FQDN_POCKETBASE + volumes: + - pocketbase-data:/app/pb_data diff --git a/templates/service-templates.json b/templates/service-templates.json index 466824574..883fbfe5a 100644 --- a/templates/service-templates.json +++ b/templates/service-templates.json @@ -247,6 +247,18 @@ "teamwork" ] }, + "pocketbase": { + "documentation": "https:\/\/pocketbase.io\/docs\/", + "slogan": "Open Source backend for your next SaaS and Mobile app in 1 file", + "compose": "c2VydmljZXM6CiAgcG9ja2V0YmFzZToKICAgIGltYWdlOiAnZ2hjci5pby9jb29sbGFic2lvL3BvY2tldGJhc2U6bGF0ZXN0JwogICAgZW52aXJvbm1lbnQ6CiAgICAgIC0gU0VSVklDRV9GUUROX1BPQ0tFVEJBU0UKICAgIHZvbHVtZXM6CiAgICAgIC0gJ3BvY2tldGJhc2UtZGF0YTovYXBwL3BiX2RhdGEnCg==", + "tags": [ + "pocketbase", + "backend", + "saas", + "mobile", + "api" + ] + }, "snapdrop": { "documentation": "https:\/\/github.com\/RobinLinus\/snapdrop", "slogan": "A self-hosted file-sharing service for secure and convenient file transfers, whether on a local network or the internet.", From 928345c8ea90f0d58d5c580146137e6f43ffb968 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 26 Oct 2023 20:45:38 +0200 Subject: [PATCH 6/8] fix: force password reset on invited accounts --- app/Http/Middleware/DecideWhatToDoWithUser.php | 2 +- bootstrap/helpers/subscriptions.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Middleware/DecideWhatToDoWithUser.php b/app/Http/Middleware/DecideWhatToDoWithUser.php index 3fb9dfea7..19a09125a 100644 --- a/app/Http/Middleware/DecideWhatToDoWithUser.php +++ b/app/Http/Middleware/DecideWhatToDoWithUser.php @@ -12,7 +12,7 @@ class DecideWhatToDoWithUser public function handle(Request $request, Closure $next): Response { if (!auth()->user() || !isCloud() || isInstanceAdmin()) { - if (!isCloud() && showBoarding() && !in_array($request->path(), allowedPathsForBoardingAccounts())) { + if (!isCloud() && showBoarding() && !in_array($request->path(), allowedPathsForBoardingAccounts())) { return redirect('boarding'); } return $next($request); diff --git a/bootstrap/helpers/subscriptions.php b/bootstrap/helpers/subscriptions.php index 130654db5..6707f8937 100644 --- a/bootstrap/helpers/subscriptions.php +++ b/bootstrap/helpers/subscriptions.php @@ -148,6 +148,8 @@ function allowedPathsForInvalidAccounts() { return [ 'logout', 'verify', + 'force-password-reset', + 'livewire/message/force-password-reset', 'livewire/message/verify-email', 'livewire/message/help' ]; From d8151ddb2e905da1eb79cacc4ac51cf98dccf906 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 27 Oct 2023 09:25:15 +0200 Subject: [PATCH 7/8] fix: add ssh options to git ls-remote --- app/Jobs/ApplicationDeploymentJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 962ea362b..59d2a1e30 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -518,7 +518,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted $this->generate_git_import_commands(); $this->execute_remote_command( [ - executeInDocker($this->deployment_uuid, "git ls-remote {$this->fullRepoUrl} {$this->branch}"), + executeInDocker($this->deployment_uuid, "GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p {$this->customPort} -o Port={$this->customPort} -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git ls-remote {$this->fullRepoUrl} {$this->branch}"), "hidden" => true, "save" => "git_commit_sha" ], From eda8b34297df980fb7ae18a3f2578278c7faeace Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 27 Oct 2023 09:28:43 +0200 Subject: [PATCH 8/8] fix --- app/Jobs/PullHelperImageJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/PullHelperImageJob.php b/app/Jobs/PullHelperImageJob.php index b61a0f295..f06e9524d 100644 --- a/app/Jobs/PullHelperImageJob.php +++ b/app/Jobs/PullHelperImageJob.php @@ -34,7 +34,7 @@ class PullHelperImageJob implements ShouldQueue, ShouldBeEncrypted try { $helperImage = config('coolify.helper_image'); ray("Pulling {$helperImage}"); - instant_remote_process(["docker pull -q {$helperImage}"], $this->server); + instant_remote_process(["docker pull -q {$helperImage}"], $this->server, false); ray('PullHelperImageJob done'); } catch (\Throwable $e) { send_internal_notification('PullHelperImageJob failed with: ' . $e->getMessage());