Deploy with Capistrano Failing

Capistrano deploy failing on git:check

I'm surprised there isn't a more descriptive error message from Git. However, the git ls-remote command is failing for some reason. In absence of any error message, the best guess is that Git cannot access the remote repository.

This could be because:

  • The Git repository URL you've provided is incorrect (double check there are no typos); or
  • Your SSH agent is not being forwarded; or
  • Your SSH identity is not allowed to access the specified repository

On your local machine (i.e. where you ran the cap command), try manually running the same Git command via SSH and see what happens:

ssh -A -i ~/.ssh/id_rsa.pub deploy@52.206.222.73 git ls-remote --heads git@example.com:username/amharic-web.git

Why does Capistrano deployment fail at assets:precompile without error?

Okay, after days of trying everything I could think of I tried something I'd already tested but with the correct syntax this time, I guess, because it works now.

Here is what I needed to add to Capistrano's config file to ensure Yarn was available when deploying:

# In deploy.rb
# Add or adjust default_env to append .npm-packages to $PATH:
set :default_env, {
PATH: '$HOME/.npm-packages/bin/:$PATH',
NODE_ENVIRONMENT: 'production'
}

Explanation: VPS users are allowed to install binaries like Yarn "globally" (using npm install --global yarn). Under-the-hood the binary is installed in $HOME/.npm-packages/bin, and this folder is added to the $PATH for interactive/login shell sessions. Since Capistrano does its utmost to NOT pick up this, we have to force-feed the updated $PATH in deploy.rb.

Rails 6 Capistrano deploy is failing even though application works fine when it is started manually

So I figured this always failed at precompile assets and the answer here:
https://stackoverflow.com/a/61210930/2358326

helped solve the issue, except I had to add a slightly different value for the path

# add in deploy.rb

set :default_env, {
PATH: '$HOME/.nvm/versions/node/v14.15.1/bin/:$PATH',
NODE_ENVIRONMENT: 'production'
}

this was because running $ which yarn on the VM returned the following:

/home/deploy/.nvm/versions/node/v14.15.1/bin/yarn

Capistrano Deploy Failing on git:check - Permission denied (publickey)

Thanks to everyone who answered, I've managed to find a solution! The main culprit was Git Bash, which, for whatever reason, was not changing the permissions on my ~/.ssh directory to 0700 when I ran chmod 700 ~/.ssh. This prevented SSH agent forwarding from working when Capistrano was deploying but not when I manually SSH'd into my server. I decided to try using Bash on Ubuntu on Windows (BUW) instead of Git Bash, and sure enough, my deploy worked! I copied over the same exact configuration and keys from Git Bash over to BUW. The only difference is that I was able to change the permissions on BUW's ~/.ssh directory to 0700. With that said, here is the solution to my problem:

1. Create a deploy key and add it to GitLab

As @Onur and @grizzthedj, and @Gokul M indicated, I needed to create a deploy key for GitLab and authorize it on my server. Here's how I did that:

  1. Generate a new SSH key on my local machine: ssh-keygen -t rsa -b 4096
  2. Copy the output of the public key: cat ~/.ssh/id_rsa.pub
  3. SSH into my server
  4. Add the public key to the end of ~/.ssh/authorized_keys
  5. Back on my local machine, open up a browser, log into GitLab, go to my repository page, and paste the public key in Settings > Repository > Deploy Keys

2. Use BUW instead of Git Bash

  1. On my local machine, I set up BUW to start the SSH agent on session load using the instructions from this SO answer.
  2. Change the permissions on ~/.ssh: chmod 700 ~/.ssh
  3. Start the SSH agent and add my deploy key to it:

    eval $(ssh-agent -s)
    ssh-add ~/.ssh/id_rsa

I've removed the set :ssh_options line from my deploy.rb file because it works just fine without it.

And that's it! It looks like I'll be deploying using BUW from now on.

Capistrano Deploy Fails To Find Github Repository

By default, capistrano deploys the master branch. But your repository contains only a main branch.

Just configure capistrano to deploy from the main branch.

set :branch, "main"


Related Topics



Leave a reply



Submit