deployphp / deployer

The PHP deployment tool with support for popular frameworks out of the box
https://deployer.org
MIT License
10.61k stars 1.48k forks source link

Deploy to server via Gitlab CI #1951

Closed GlennM closed 4 years ago

GlennM commented 4 years ago

Hi,

I'm trying to implement deployer for the deployment stage of GitLab CI. Unfortunately, I've been unable to get it fully working.

Setup

Issue

I've been seeing various error messages (e.g. TTY error, hopefully solved by disabling git_tty option).

The error I am unable to solve is:

In Client.php line 103:

The command "cd [PATH] && (git clone   --recursive  [REPO CLONE URL (SSH)] [PATH]/releases/1 2>&1)" failed.

Exit Code: 128 (Invalid exit argument)

Host Name: [HOSTNAME]
================
Cloning into '[PATH]/releases/1'...
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

(I've replaced some specific info with general info, see the []).

I did several attempts, e.g.

Question

Is there someone who could point me to the right direction to get my setup with GitLab and push to server working?

antonmedv commented 4 years ago

Just use deploy keys. This is most easy to go solution and should work 100% in implemented correctly. Don't rely on agent forwarding, just allow your server to pull changes from git.

GlennM commented 4 years ago

Thanks for your quick reply @antonmedv ! Unfortunately, I think there's still some confusion about the deployment keys. I've tried several combinations, but have been unable to get it working.

To be specific:

antonmedv commented 4 years ago

I've tried to follow the GitLab instructions.

šŸ‘šŸ»

When generating the SSH key pair, I am not quite sure what email address to use. Or doesn't that matter?

Any email. Keys are just files.

Should I run ssh-keygen on my local machine or on the server I'm trying to push the code to?

Doesn't matter. Make sure git using them on machine which trying to access git server.

Will it cause any issues if I have a different name for the keypair (e.g. id_rsa_gitlab) or do I need to adjust something in that case?

No. As long as your git is using them.

I added the private key as a private variable to GitLab project

Okay. But why?

I added the public key as a deployment key to GitLab project

Okay. But why?

I added the before_script part from the GitLab docs to my .gitlab-ci.yml (job-specific, not global before_script).

This is releated only for gitlab, can help here.

GlennM commented 4 years ago

Thanks, but I still don't get it working.

Result

However, when I'm trying to deploy, I get an error, which I think has to do with permissions for GitLab, as the error occurs specifically when trying to perform deploy:update_code.

Error:

Cloning into '[PATH]/releases/1'...                             
  Host key verification failed.                                                
  fatal: Could not read from remote repository.                                

  Please make sure you have the correct access rights                          
  and the repository exists.
antonmedv commented 4 years ago

Make sure what user which connect from gitlab to your server uses same keys.

GlennM commented 4 years ago

Thanks for your help @antonmedv, I got it working now. Probably it was a combination of multiple factors, but the root cause seems to be that dep init put a wrong repository url in the deploy.php file (config related, not a bug in deployer package).