Why capistrano is executing the task locally - capistrano

I am using Capistrano to deploy a ruby on rails project. I am attempting to login to remote server as user 'deploy' and deploy this application.
When I ssh into box as deploy and git clone the project it works
ssh deploy#remote_box
git clone git#github.com:lumdum/demo.git
However when I run using Capistrano it says that permission denied to account dorelal. dorelal is my account on GitHub. So I thought Capistrano is executing the task locally on my mac and not on my remote server which is on Redhat.
And that is true that Capistrano is running locally the command. when I execute
cap staging deploy -vvvv
this is the error message I am getting
executing locally: "git ls-remote git#github.com:lumdum/demo.git master"
Notice it says 'executing locally'. Why is capistrano running it locally and not on my remote box.
here is my deploy.rb
set :stages, %w(staging)
require 'capistrano/ext/multistage'
set :repository, "git#github.com:lumdum/demo.git"
set :scm, :git
set :user, 'deploy'
set :use_sudo, false
set :keep_releases, 2
role :web, "serv1"
role :app, "serv1"
role :db, "db1", :primary => true
set :application, "demo_staging"
set :branch, "master"
set :deploy_via, :remote_cache
set :deploy_to, "/var/www/rails/demo"
set :scm_user, 'dorelal_lumdum'
set :user, 'deploy'
set :rails_env, "staging"
set :keep_releases, 1

Capistrano runs that locally to determine the HEAD on the repository, which is then used in the subsequent step to check-out (or, clone in Git terminology) the precise revision that was seen from your workstation.
I'll admit this is a little unexpected!

Related

Auto deploy with gitlab continuous integration

I want to setup auto deployment from a gitlab branch to a digitalocean droplet. I created a runner and exec git clone in droplet. But now I can't configure my gitlab-ci.yml for autodeploy from branch "dev" to droplet.
My gitlab-ci.yml:
image: python:3.5
staging:
type: deploy
only:
- dev
script:
# there must be some kind of connection to the droplet to further code executed already on server
- git pull
# - server restart
How do I connect to the server in gitlab-ci.yml to make "git pull" command?
Ok, I solved the problem. First, we need to add the GitLab CI runner to the server. You can see in the documentation how to do it. Then all commands from gitlab-ci.yml will execute on the server. So "git pull" command also will be executed on the server where the runner was started.

How to enable minion to connect to git repository using saltstack and capistrano

I am trying to create run my rails application on ec2 using saltstack and capistrano.
Here's what I have successfully completed so far.
Using salt cloud and salt master I am able to create a new minion instance and setup everything required for the application to run i.e. ruby, rails, unicorn, mysql etc.
I have done proper configuration for capistrano. when I try to deploy I see the following error.
DEBUG [ed84c6ab] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/pathto/git-ssh.sh /usr/bin/env git ls-remote -h git#github.com:somehost/somerepo.git )
DEBUG [ed84c6ab] Warning: Permanently added 'github.com,ip' (RSA) to the list of known hosts.
DEBUG [ed84c6ab] Permission denied (publickey).
DEBUG [ed84c6ab] fatal: Could not read from remote repository.
DEBUG [ed84c6ab]
DEBUG [ed84c6ab] Please make sure you have the correct access rights
DEBUG [ed84c6ab] and the repository exists.
DEBUG [ed84c6ab] Finished in 12.600 seconds with exit status 128 (failed).
So this means that from my local capistrano is able to connect to the minion but when it tries to checkout git repo it fails.
I know this is happening because the ssh public key of the minion is not added to the github.
so the goal is.
run salt cloud to create instance
run salt highstate to install everything required for app
run capistrano deploy to start the application
I would like to automate github authorization process too. I mean once the minion is created the minion should be able to clone git repo without any manual intervention.
I am confused as to this can be done through capistrano or saltstack.
I used github ssh forwarding to achieve this.
Here's the changes I made.
Steps to enable ssh forwarding for github
Then in capistrano deploy.rb file configure ssh forwarding by adding forward_agent: true
set :ssh_options, {
user: 'user',
auth_methods: %w(publickey),
port: <some port>,
forward_agent: true
}

mina setup/deploy help needed

I´m new to mina and only have a hosting package with an ssh access but with no root privileges.
My prob is that I get an "Permission denied, please try again" if I run mina setup.
By extending the deploy.rb wit the following line:
set :term_mode, :nil
I can run mina deploy but I received this error:
-----> Using git branch 'master'
$ git clone "development/www.mydomain.com/scm" . --recursive --branch "master"
fatal: destination path '.' already exists and is not an empty directory.
! ERROR: Deploy failed.
I know that the www.mydomain.com isn´t an empty folder cause mina creates with the setup the "shared" and "releases" folders.
So I don´t know what I have to do to make the deploy happend.
Any hint?
You need to check settings in your deploy.rb file. Looks like mina is attempting to clone into your user home directory. Also the repository path looks incorrect. It should be using a full path for both the repository path and the target path.
For example you should see something like:
-----> Cloning the Git repository
$ git clone "http://github.com/username/project.git" "/home/username/deploy_path/scm" --bare
Cloning into bare repository '/home/username/deploy_path/scm'...
This error is most likely caused by not having a deploy block in your deploy task. Your deploy task should look like this:
task :deploy => :environment do
deploy do
invoke :'git:clone'
# Other deploy tasks ...
to :launch do
# Run some commands when launching the appplication
end
end
end
Soluction deploy mina
set :repository, 'git#bitbucket.org:my_user/my_repo.git'
set :branch, 'master'

cap deploy:setup creates the release folder with root as owner

I am using capistrano to deplay my rails application on a Ubuntu server.
I already logged into the server and created a folder /webapps/myapp, but no sub folders from here.
Then I run
cap deploy:setup
No errors so far, so i run
cap deploy:setup
Now I get this message
You do not have permissions to write to /webapps/myapp/releases
I can get around this by logging in to the server and change the owner of releases, I just wonder why it is not created with the user I use for deploying? Is this how it work or am I missing something?
In your deploy.rb file you should specify the deployment user and if he has sudo privilege.
set :user, "william"
set :use_sudo, false
Giving sudo privilege isn't recommended, but this option exists.
The directory to which you deploy should be already owned by the deployment user "william"

Capistrano doesn't use sudo despite :use_sudo, true

I'm brand new to Capistrano, working with an existing server that was previously using chef to run deployments.
I have set :use_sudo, true in my deploy.rb, and yet "cap deploy:check" claims "You do not have permissions to write to '/srv/app/'"
My deployment user is correctly configured to sudo without a password prompt. If I manually run "sudo test -w /srv/app" on the server, it succeeds.
Why isn't Capistrano using sudo?
The command fails because the directory does not exist. You should first run cap deploy:setup After that cap deploy:check succeeds.