From bd2e1ad9fe6ff7b8b67c4bec3969ff963eaeb7d3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 25 Sep 2024 10:25:35 +0200 Subject: [PATCH 1/6] refactor: Fix typo in execute-container-command.blade.php --- .../livewire/project/shared/execute-container-command.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/livewire/project/shared/execute-container-command.blade.php b/resources/views/livewire/project/shared/execute-container-command.blade.php index 0a406e152..c98e9ae19 100644 --- a/resources/views/livewire/project/shared/execute-container-command.blade.php +++ b/resources/views/livewire/project/shared/execute-container-command.blade.php @@ -32,7 +32,7 @@ Connect @else -
No containers are not running.
+
No containers are running.
@endif From 59d2c9748a82cc151533be1a34cd03ea57f7f8a3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 25 Sep 2024 10:27:23 +0200 Subject: [PATCH 2/6] fix: make sure to reload window if app status changes --- app/Livewire/Project/Shared/Terminal.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/Livewire/Project/Shared/Terminal.php b/app/Livewire/Project/Shared/Terminal.php index 5fd098e9f..27be46227 100644 --- a/app/Livewire/Project/Shared/Terminal.php +++ b/app/Livewire/Project/Shared/Terminal.php @@ -9,6 +9,20 @@ use Livewire\Component; class Terminal extends Component { + public function getListeners() + { + $teamId = auth()->user()->currentTeam()->id; + + return [ + "echo-private:team.{$teamId},ApplicationStatusChanged" => 'closeTerminal', + ]; + } + + public function closeTerminal() + { + $this->dispatch('reloadWindow'); + } + #[On('send-terminal-command')] public function sendTerminalCommand($isContainer, $identifier, $serverUuid) { From 567bbe9d0b8bcbe1d902b849e1e1242421ec70df Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 25 Sep 2024 10:27:51 +0200 Subject: [PATCH 3/6] chore: Update version numbers to 4.0.0-beta.344 --- config/sentry.php | 2 +- config/version.php | 2 +- other/nightly/versions.json | 4 ++-- versions.json | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/sentry.php b/config/sentry.php index 60e183283..46c4407f2 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.343', + 'release' => '4.0.0-beta.344', // 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 050ea885b..a4ecf5bf6 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Thu, 26 Sep 2024 10:36:59 +0200 Subject: [PATCH 4/6] refactor: Update OS_TYPE for Asahi Linux in install.sh script --- other/nightly/install.sh | 7 ++- scripts/install.sh | 92 ++++++---------------------------------- 2 files changed, 18 insertions(+), 81 deletions(-) diff --git a/other/nightly/install.sh b/other/nightly/install.sh index 020e7d45b..feb97295a 100755 --- a/other/nightly/install.sh +++ b/other/nightly/install.sh @@ -8,7 +8,7 @@ set -o pipefail # Cause a pipeline to return the status of the last command that CDN="https://cdn.coollabs.io/coolify-nightly" DATE=$(date +"%Y%m%d-%H%M%S") -VERSION="1.5" +VERSION="1.6" DOCKER_VERSION="26.0" # TODO: Ask for a user CURRENT_USER=$USER @@ -39,6 +39,11 @@ if [ "$OS_TYPE" = "manjaro" ] || [ "$OS_TYPE" = "manjaro-arm" ]; then OS_TYPE="arch" fi +# Check if the OS is Asahi Linux, if so, change it to fedora +if [ "$OS_TYPE" = "fedora-asahi-remix" ]; then + OS_TYPE="fedora" +fi + # Check if the OS is popOS, if so, change it to ubuntu if [ "$OS_TYPE" = "pop" ]; then OS_TYPE="ubuntu" diff --git a/scripts/install.sh b/scripts/install.sh index 5ca488729..7b1d0c283 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -10,6 +10,8 @@ DATE=$(date +"%Y%m%d-%H%M%S") VERSION="1.6" DOCKER_VERSION="26.0" +# TODO: Ask for a user +CURRENT_USER=$USER mkdir -p /data/coolify/{source,ssh,applications,databases,backups,services,proxy,webhooks-during-maintenance,metrics,logs} mkdir -p /data/coolify/ssh/{keys,mux} @@ -401,88 +403,18 @@ if [ ! -f ~/.ssh/authorized_keys ]; then chmod 600 ~/.ssh/authorized_keys fi -checkSshKeyInAuthorizedKeys() { - grep -qw "root@coolify" ~/.ssh/authorized_keys - return $? -} +set +e +IS_COOLIFY_VOLUME_EXISTS=$(docker volume ls | grep coolify-db | wc -l) +set -e -checkSshKeyInCoolifyData() { - [ -s /data/coolify/ssh/keys/id.root@host.docker.internal ] - return $? -} - -generateAuthorizedKeys() { - sed -i "/root@coolify/d" ~/.ssh/authorized_keys - cat /data/coolify/ssh/keys/id.root@host.docker.internal.pub >> ~/.ssh/authorized_keys - rm -f /data/coolify/ssh/keys/id.root@host.docker.internal.pub -} -generateSshKey() { +if [ "$IS_COOLIFY_VOLUME_EXISTS" -eq 0 ]; then echo " - Generating SSH key." - ssh-keygen -t ed25519 -a 100 -f /data/coolify/ssh/keys/id.root@host.docker.internal -q -N "" -C root@coolify - chown 9999 /data/coolify/ssh/keys/id.root@host.docker.internal - generateAuthorizedKeys -} - -syncSshKeys() { - DB_RUNNING=$(docker inspect coolify-db --format '{{ .State.Status }}' 2>/dev/null) - # Check if SSH key exists in Coolify data but not in authorized_keys - if checkSshKeyInCoolifyData && ! checkSshKeyInAuthorizedKeys; then - # Add the existing Coolify SSH key to authorized_keys - cat /data/coolify/ssh/keys/id.root@host.docker.internal.pub >> ~/.ssh/authorized_keys - # Check if SSH key exists in authorized_keys but not in Coolify data - elif checkSshKeyInAuthorizedKeys && ! checkSshKeyInCoolifyData; then - # Ensure Coolify DB is running before proceeding - if [ "$DB_RUNNING" = "running" ]; then - # Retrieve DB user and SSH key from Coolify database - DB_USER=$(docker inspect coolify-db --format '{{ .Config.Env }}' | grep -oP 'POSTGRES_USER=\K[^ ]+') - DB_SSH_KEY=$(docker exec coolify-db psql -U $DB_USER -d coolify -t -c "SELECT \"private_key\" FROM \"private_keys\" WHERE id = 0 AND team_id = 0 LIMIT 1;" -A -t) - - if [ -z "$DB_SSH_KEY" ]; then - # If no key found in DB, generate a new one - echo " - SSH key not found in database. Generating new key." - generateSshKey - else - # If key found in DB, save it and update authorized_keys - echo " - SSH key found in database. Saving to file." - echo "$DB_SSH_KEY" > /data/coolify/ssh/keys/id.root@host.docker.internal - chmod 600 /data/coolify/ssh/keys/id.root@host.docker.internal - chown 9999 /data/coolify/ssh/keys/id.root@host.docker.internal - - # Generate public key from private key and update authorized_keys - ssh-keygen -y -f /data/coolify/ssh/keys/id.root@host.docker.internal -C root@coolify > /data/coolify/ssh/keys/id.root@host.docker.internal.pub - sed -i "/root@coolify/d" ~/.ssh/authorized_keys - cat /data/coolify/ssh/keys/id.root@host.docker.internal.pub >> ~/.ssh/authorized_keys - rm -f /data/coolify/ssh/keys/id.root@host.docker.internal.pub - chmod 600 ~/.ssh/authorized_keys - fi - fi - # If SSH key doesn't exist in either location - elif ! checkSshKeyInAuthorizedKeys && ! checkSshKeyInCoolifyData; then - # Ensure Coolify DB is running before proceeding - if [ "$DB_RUNNING" = "running" ]; then - # Retrieve DB user and SSH key from Coolify database - DB_USER=$(docker inspect coolify-db --format '{{ .Config.Env }}' | grep -oP 'POSTGRES_USER=\K[^ ]+') - DB_SSH_KEY=$(docker exec coolify-db psql -U $DB_USER -d coolify -t -c "SELECT \"private_key\" FROM \"private_keys\" WHERE id = 0 AND team_id = 0 LIMIT 1;" -A -t) - if [ -z "$DB_SSH_KEY" ]; then - # If no key found in DB, generate a new one - echo " - SSH key not found in database. Generating new key." - generateSshKey - else - # If key found in DB, save it and update authorized_keys - echo " - SSH key found in database. Saving to file." - echo "$DB_SSH_KEY" > /data/coolify/ssh/keys/id.root@host.docker.internal - chmod 600 /data/coolify/ssh/keys/id.root@host.docker.internal - ssh-keygen -y -f /data/coolify/ssh/keys/id.root@host.docker.internal -C root@coolify > /data/coolify/ssh/keys/id.root@host.docker.internal.pub - sed -i "/root@coolify/d" ~/.ssh/authorized_keys - cat /data/coolify/ssh/keys/id.root@host.docker.internal.pub >> ~/.ssh/authorized_keys - fi - else - generateSshKey - fi - fi -} - -syncSshKeys || true + ssh-keygen -t ed25519 -a 100 -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal -q -N "" -C coolify + chown 9999 /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal + sed -i "/coolify/d" ~/.ssh/authorized_keys + cat /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub >> ~/.ssh/authorized_keys + rm -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub +fi chown -R 9999:root /data/coolify chmod -R 700 /data/coolify From d006edc485821fb2f9f00a3d452bb4800102f9f4 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 26 Sep 2024 10:37:02 +0200 Subject: [PATCH 5/6] refactor: Add localhost as Server if it doesn't exist and not in cloud environment --- database/seeders/ProductionSeeder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/seeders/ProductionSeeder.php b/database/seeders/ProductionSeeder.php index 17a85f7b6..fad8f10a9 100644 --- a/database/seeders/ProductionSeeder.php +++ b/database/seeders/ProductionSeeder.php @@ -65,7 +65,7 @@ class ProductionSeeder extends Seeder ]); } // Add Coolify host (localhost) as Server if it doesn't exist - if (Server::find(0) == null) { + if (Server::find(0) == null && ! isCloud()) { $server_details = [ 'id' => 0, 'name' => 'localhost', @@ -89,7 +89,7 @@ class ProductionSeeder extends Seeder $server->settings->is_usable = true; $server->settings->save(); } - if (StandaloneDocker::find(0) == null) { + if (StandaloneDocker::find(0) == null && ! isCloud()) { StandaloneDocker::create([ 'id' => 0, 'name' => 'localhost-coolify', From 0bb1f57ea7463b7a478e5b3b09e0d5b2b4e6d70f Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 26 Sep 2024 12:19:49 +0200 Subject: [PATCH 6/6] fix: deploy key based deployments --- app/Jobs/ApplicationDeploymentJob.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index df166c1cd..24565b389 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -1442,14 +1442,24 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue if ($this->pull_request_id !== 0) { $local_branch = "pull/{$this->pull_request_id}/head"; } - $private_key = $this->application->privateKey?->getKeyLocation(); + $private_key = data_get($this->application, 'private_key.private_key'); if ($private_key) { + $private_key = base64_encode($private_key); $this->execute_remote_command( [ - 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 -i {$private_key}\" git ls-remote {$this->fullRepoUrl} {$local_branch}"), + executeInDocker($this->deployment_uuid, 'mkdir -p /root/.ssh'), + ], + [ + executeInDocker($this->deployment_uuid, "echo '{$private_key}' | base64 -d | tee /root/.ssh/id_rsa > /dev/null"), + ], + [ + executeInDocker($this->deployment_uuid, 'chmod 600 /root/.ssh/id_rsa'), + ], + [ + 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} {$local_branch}"), 'hidden' => true, 'save' => 'git_commit_sha', - ], + ] ); } else { $this->execute_remote_command(