From 0bb1f57ea7463b7a478e5b3b09e0d5b2b4e6d70f Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 26 Sep 2024 12:19:49 +0200 Subject: [PATCH] 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(