Deployer: Deploying From bitbucket

Created on 28 May 2015  Â·  14Comments  Â·  Source: deployphp/deployer

How do I provide the credentails for a GIT repo that's on Bitbucket? This is what my deploy.php looks like.

<?php
// All Deployer recipes are based on `recipe/common.php`.
require 'recipe/laravel.php';

// Define a server for deployment.
// Let's name it "prod" and use port 22.
server('dev-server-1', 'dev', 22)
    ->user('root')
    ->forwardAgent()
    ->stage('dev')
    ->env('deploy_path', '/var/www/my-deploy-dir'); // Define the base path to deploy your project to.

// Specify the repository from which to download your project's code.
// The server needs to have git installed for this to work.
// If you're not using a forward agent, then the server has to be able clone
// your project from this repository.
set('repository', '[email protected]:someuser/somerepo.git');

?>

Whe I run dep deploy dev -v, I get the following trace:

➤ E➤ecuting task deploy:prepare
⤷ on [dev-server-1]
⤶ done on [dev-server-1]
✔ Ok
➤ E➤ecuting task deploy:release
⤷ on [dev-server-1]
⤶ done on [dev-server-1]
✔ Ok
➤ E➤ecuting task deploy:update_code
⤷ on [dev-server-1]



  [RuntimeException]                          
  Host key verification failed.               
  fatal: The remote end hung up unexpectedly  



Exception trace:
 () at phar:///usr/local/bin/dep/src/Server/Remote/PhpSecLib.php:114
 Deployer\Server\Remote\PhpSecLib->run() at phar:///usr/local/bin/dep/src/functions.php:289
 run() at phar:///usr/local/bin/dep/recipe/common.php:129
 {closure}() at n/a:n/a
 call_user_func() at phar:///usr/local/bin/dep/src/Task/Task.php:66
 Deployer\Task\Task->run() at phar:///usr/local/bin/dep/src/Executor/SeriesExecutor.php:40
 Deployer\Executor\SeriesExecutor->run() at phar:///usr/local/bin/dep/src/Console/TaskCommand.php:116
 Deployer\Console\TaskCommand->execute() at phar:///usr/local/bin/dep/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:257
 Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/dep/vendor/symfony/console/Symfony/Component/Console/Application.php:874
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/dep/vendor/symfony/console/Symfony/Component/Console/Application.php:195
 Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/dep/vendor/symfony/console/Symfony/Component/Console/Application.php:126
 Symfony\Component\Console\Application->run() at phar:///usr/local/bin/dep/src/Deployer.php:91
 Deployer\Deployer->run() at phar:///usr/local/bin/dep/bin/dep:62
 require() at /usr/local/bin/dep:4


deploy [-p|--parallel]

Thanks.

Most helpful comment

The following was added to the docs not so long ago:

// Specify the repository from which to download your project's code.
// The server needs to have git installed for this to work.
// If you're not using a forward agent, then the server has to be able clone
// your project from this repository.
set('repository', '[email protected]:org/app.git');

And I just noticed a typo in it: https://github.com/deployphp/docs/pull/25 xD
My point is: I think the doc now covers this part.

A more interesting question would be: is it possible to detect this specific error during deployment?
I encountered this issue numerous times, and it would be great to have a friendly error message like:

Host key verification failed. It seems you forgot to add the repository's host's
fingerprint as a 'known host'. Run `ssh -T [email protected]` on the remote
server to add it to the list of known hosts, then try deploying again.

Here "[email protected]" could be extracted from the server configuration data.

All 14 comments

You should add public key from server to Deploy keys to bitbucket.

1 Copy public key:

cat ~/.ssh/id_rsa.pub

1.1 If not exist, then create:

ssh-keygen

2 Paste this key in Bitbucket repository deploy keys.

screenshot at 28 15-45-23

P.S. Before deploy, clone repository (for approve host):

cd /tmp
git clone .....

@ZhukV, thanks for your reponse. But I already have the Deployment key configured in bitbucket. Any other idea?
Thanks.

Try reset file .know_hosts

rm ~/.ssh/known_hosts

and clone repository on server.

Clone your repository manually on server to check what everything is ok.

I was able to successfully clone the bitbucket repo on the server. But, I saw the usual warning
The authenticity of host 'bitbucket.org (131.103.20.168)' can't be established. RSA key fingerprint is 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40. Are you sure you want to continue connecting (yes/no)?
So, After adding bitbucket.org to the list of know_hosts, "Deployer" now runs successfully.
So, we should probably add to the doc that the fingerprint server on which the repository resides should be in the know_hosts list of the server on which you are deploying.
Thanks everyone!

The following was added to the docs not so long ago:

// Specify the repository from which to download your project's code.
// The server needs to have git installed for this to work.
// If you're not using a forward agent, then the server has to be able clone
// your project from this repository.
set('repository', '[email protected]:org/app.git');

And I just noticed a typo in it: https://github.com/deployphp/docs/pull/25 xD
My point is: I think the doc now covers this part.

A more interesting question would be: is it possible to detect this specific error during deployment?
I encountered this issue numerous times, and it would be great to have a friendly error message like:

Host key verification failed. It seems you forgot to add the repository's host's
fingerprint as a 'known host'. Run `ssh -T [email protected]` on the remote
server to add it to the list of known hosts, then try deploying again.

Here "[email protected]" could be extracted from the server configuration data.

Indeed, such a friendly message would be a nice addition.
Great tool. Makes life much easier.
Thanks again, everybody!

@elfet Do you think this idea about the error message could be implemented?
Honestly I just can judge whether I should open an issue about it or not. :P

*can't

@ZeeCoder so what wrong with error reporting?

It's not like it's "wrong".

If you read my comment carefully, all I'm saying is that it could be more sophisticated by detecting this specific error and having a slightly more verbose error message for it.

But since I have no idea if something like this could be implemented or not, I thought I'd first ask you whether this worth opening a new issue or not.

This could be labeled as "DX" like in Symfony.
Developer Experience is very important imho.

I don't know ether.

I too thought that ->forwardAgent() makes the ssh-agent work as it supposed to work and forwarding my SSH keys to the ssh session. This would make my life easier (Capistrano can do it) because then I don't have to create a deployment key in BitBucket, the server does not have to have an RSA keypair, eg less maintenance cost.

Ah @ZeeCoder solved my issue, the current error message doesn't include that bit. Just shows:

[RuntimeException]
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

Would be a nice addition to add that little message about known host

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chouex picture chouex  Â·  4Comments

dima-stefantsov picture dima-stefantsov  Â·  4Comments

exts picture exts  Â·  3Comments

k-solnushkin picture k-solnushkin  Â·  5Comments

ElForastero picture ElForastero  Â·  3Comments