部署者 - 没有tty存在且没有指定askpass程序 - 如何使用Deployer进行部署

时间:2017-01-06 04:40:36

标签: php git laravel ssh deployment

我在使用Deployer 4.0.2进行部署时遇到了麻烦,我需要帮助那些比我更有经验的人。

我想将我的存储库部署到Ubuntu 16.04服务器。

我使用laravel homestead作为开发环境,我也安装了deployer。从那里我ssh到我的远程服务器。

我能够使用root用户部署我的代码,直到我点击导致部署中止的RuntimeException

Do not run Composer as root/super user! See https://getcomposer.org/root for details

这让我创建了另一个名为george的用户,我授予了他们超级用户权限。我将我的公钥从本地计算机复制到新生成的~/.ssh/authorized_keys文件,这使我有权通过ssh访问服务器。

然而,当我使用新用户运行dep deploy时:

server('production', '138.68.99.157')
    ->user('george')
    ->identityFile()
    ->set('deploy_path', '/var/www/test');

我得到另一个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. 

现在看来新用户george无法访问~/.ssh/id_rsa.pub密钥。所以我将它们从根文件夹复制到我的主文件夹中,并在Github SSH设置中添加公钥。

cp root/.ssh/id_rsa.pub home/george/.ssh/id_rsa.pub
cp root/.ssh/id_rsa home/george/.ssh/id_rsa

只是为了得到与以前相同的错误。

最后,我必须将github添加到我的授权主机列表中:

ssh-keyscan -H github.com >> ~/.ssh/known_hosts

仅获取下一个RuntimeException

[RuntimeException]
sudo: no tty present and no askpass program specified

我设法在deploy.php

中评论此代码
// desc('Restart PHP-FPM service');
// task('php-fpm:restart', function () {
//     // The user must have rights for restart service
//     // /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service
//     run('sudo systemctl restart php-fpm.service');
// });
// after('deploy:symlink', 'php-fpm:restart');

最终完成部署过程,现在我问自己,如果php-fpm的restart真的有必要,我可以继续调试这个部署工具吗?或者我可以没有它吗?

如果我需要它,有人可以帮我理解我需要它吗?也许作为奢侈品还提供RuntimeException的解决方案?

1 个答案:

答案 0 :(得分:1)

试试这个:

->identityFile('~/.ssh/id_rsa.pub', '~/.ssh/id_rsa', 'pass phrase')

它对我很有用 - 不需要提问通过程序 根据我的经验,这有助于明确。

关于你的phpfm重启任务..我以前没见过。不应该需要。 :)

编辑:

您提供密码可能是一个好的迹象,如果您将其保留在源代码管理下,您应该稍微重构一下Deployer代码。

我正在加载YAML文件中的网站特定数据 - 我 提交源代码管理。

stage.yml的第一位:

# Site Configuration
# -------------
prod_1:
    host: hostname
    user: username
    identity_file:
        public_key: /home/user/.ssh/key.pub
        private_key: /home/user/.ssh/key
        password: "password"
    stage: production
    repository: https://github.com/user/repository.git
    deploy_path: /var/www
    app:
        debug: false
        stage: 'prod'

然后,在我的deploy.php

if (!file_exists (__DIR__ . '/deployer/stage/servers.yml')) {
  die('Please create "' . __DIR__ . '/deployer/stage/servers.yml" before continuing.' . "\n");
}
serverList(__DIR__ . '/deployer/stage/servers.yml');
set('repository', '{{repository}}');

set('default_stage', 'production');

请注意,当您使用serverList时,它会替换deploy.php

中的服务器设置
相关问题