P
P
Pavel Grudinkin2017-06-04 10:43:36
SSH
Pavel Grudinkin, 2017-06-04 10:43:36

Why is there no access to the repository during deployment?

I'm setting up a deployment for a project and ran into a problem: I see an error
when running the script
cap production deploy:check

INFO [16ef9c10] Running /usr/bin/env git ls-remote --heads [email protected]:test/pereezd-test.git as [email protected]
    DEBUG [16ef9c10] Command: ( export GIT_ASKPASS="/bin/echo" GIT_SSH="/tmp/test/git-ssh.sh" ; /usr/bin/env git ls-remote --heads [email protected]:test/pereezd-test.git )
    DEBUG [16ef9c10] 	Permission denied (publickey).
    DEBUG [16ef9c10] 	fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    DEBUG [16ef9c10] 	and the repository exists.

But if you ssh into the server and manually run git clone, everything works fine. Those. the keys are ok.
production.rb
# server-based syntax
    # ======================
    # Defines a single server with a list of roles and multiple properties.
    # You can define all roles on a single server, or split them:
    
    server 'ip', user: 'deployer', roles: %w{app db web}, primary: true
    # server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
    # server 'db.example.com', user: 'deploy', roles: %w{db}
    
    set :ssh_options, {
    forward_agent: false }
    
    # role-based syntax
    # ==================
    
    # Defines a role with one or multiple servers. The primary server in each
    # group is considered to be the first unless any  hosts have the primary
    # property set. Specify the username and a domain or IP for the server.
    # Don't use `:all`, it's a meta role.
    
    role :app, %w{[email protected]}
    role :web, %w{[email protected]}
    role :db,  %w{[email protected]}
    
    set :rails_env, :production

I load the keys using keychain
${HOME}/.bashrc:
keychain ~/.ssh/bitbucket
    . ~/.keychain/`uname -n`-sh

Most likely it is the problem, but I don’t understand how to fix the following behavior in another way:
I go to the server via ssh, start the ssh agent, add the ssh-add key, after the logout everything is new, the key is not saved.
command on server ssh -T [email protected]
authenticated via a deploy key.
    You can use git or hg to connect to Bitbucket. Shell access is disabled.
    This deploy key has read access to the following repositories:
    test/test:  -- [email protected]

My algorithm of actions:
on the server-
- генерирую пару ключей

    - запускаю ssh agent

    - публичный ключ добавляю в битбакет

    - приватный ключ добавляю в агент( ssh-add key) с вводом пароля

    - пытаюсь клонировать репозиторий на сервере, хост добавляю в known_hosts, репозиторий успешно клонируется

locally -
- не закрывая ssh сессию( если закрыть, агент тоже выключится) пробую провести деплой, получаю ошибку доступа к репозиторию, проверку типа версии руби проходит корректно.

It turns out two problems:
1) You need to somehow force the agent not to close after the logout or so that the keys are added automatically (I tried to solve this using keychain)
2) You still need to get access to the repository during deployment.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Radkov, 2017-06-04
@paulradzkov

I once had a situation that the deployment script on GitHub did not see the repository through "remote origin". I had to set separately a new “remote deploy” with an explicitly specified login and password.
The situation is described here paulradzkov.com/2014/deploy_docpad_site_to_github_...
Maybe it will help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question