From 2ad7c2b1ce3a61b7bc69a6b6acfaf6ae9453cce6 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 18 Oct 2023 15:33:07 +0200 Subject: [PATCH] fix: remove custom port from git repo url --- app/Jobs/ApplicationDeploymentJob.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 258651035..3091bc339 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -75,6 +75,8 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted private string $serverUserHomeDir = '/root'; private string $dockerConfigFileExists = 'NOK'; + private int $customPort = 22; + public $tries = 1; public function __construct(int $application_deployment_queue_id) { @@ -167,6 +169,15 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted // Get user home directory $this->serverUserHomeDir = instant_remote_process(["echo \$HOME"], $this->server); $this->dockerConfigFileExists = instant_remote_process(["test -f {$this->serverUserHomeDir}/.docker/config.json && echo 'OK' || echo 'NOK'"], $this->server); + + // Check custom port + preg_match('/(?<=:)\d+(?=\/)/', $this->application->git_repository, $matches); + if (count($matches) === 1) { + $this->customPort = $matches[0]; + $gitHost = str($this->application->git_repository)->before(':'); + $gitRepo = str($this->application->git_repository)->after('/'); + $this->application->git_repository = "$gitHost:$gitRepo"; + } try { if ($this->application->dockerfile) { $this->deploy_simple_dockerfile(); @@ -549,13 +560,8 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted } } if ($this->application->deploymentType() === 'deploy_key') { - $port = 22; - preg_match('/(?<=:)\d+(?=\/)/', $this->application->git_repository, $matches); - if (count($matches) === 1) { - $port = $matches[0]; - } $private_key = base64_encode($this->application->private_key->private_key); - $git_clone_command = "GIT_SSH_COMMAND=\"ssh -o ConnectTimeout=30 -p $port -o Port=$port -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /root/.ssh/id_rsa\" {$git_clone_command} {$this->application->git_repository} {$this->basedir}"; + $git_clone_command = "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 /root/.ssh/id_rsa\" {$git_clone_command} {$this->application->git_repository} {$this->basedir}"; $git_clone_command = $this->set_git_import_settings($git_clone_command); $commands = collect([ executeInDocker($this->deployment_uuid, "mkdir -p /root/.ssh"),