【问题标题】:Deployer - no tty present and no askpass program specified - How to deploy with DeployerDeployer - 不存在 tty 且未指定 askpass 程序 - 如何使用 Deployer 进行部署
【发布时间】:2017-05-20 19:45:27
【问题描述】:

我无法使用 Deployer 4.0.2 进行部署,我需要在这方面比我更有经验的人的帮助。

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

我使用laravel homestead 作为开发环境,我还安装了部署程序。从那里我 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.pubkey。所以我将它们从根文件夹复制到我的主文件夹中,并在 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的解决方案?

【问题讨论】:

标签: php git laravel ssh deployment


【解决方案1】:

试试这个:

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

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

至于你的 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 中的服务器设置

【讨论】:

    猜你喜欢
    • 2014-04-23
    • 2017-02-24
    • 2014-03-06
    • 2021-11-02
    • 2020-04-28
    相关资源
    最近更新 更多