pm2 deploy和gitlab私有存储库

时间:2018-03-23 16:22:54

标签: node.js ssh gitlab pm2

我想使用pm2 deploy在我的远程服务器上部署我的应用程序。

以下是我的ecosystem.config.js文件的内容:

module.exports = {
  apps: [
    {
      name: `cms`,
      script: 'cms.js',
      env: {
        COMMON_VARIABLE: 'true'
      },
      env_development: {
        NODE_ENV: 'development',
      },
    }
  ],
  deploy: {
    development: {
      user: 'username',
      host: 'xxx.xxx.xxx.xxx',
      ref: 'origin/development',
      repo: 'git@gitlab.com:MyGitlabOrg/myproject.git',
      path: '/home/username/sites/development/cms',
      'post-deploy':
        '\
        mkdir -p logs && \
        npm install && \
        npm run install:development && npm run make:development && \
        NODE_ENV=development pm2 reload ecosystem.config.js --env development',
      ssh_options: ['StrictHostKeyChecking=no', 'PasswordAuthentication=no'],
      env: {
        NODE_ENV: 'development'
      }
    }
  }
};

以下是我在我的学期(在我的本地机器上)使用的命令:

$ pm2 deploy ecosystem.config.js development setup
--> Deploying to development environment
--> on host xxx.xxx.xxx.xxx
  â hook pre-setup
  â running setup
  â cloning git@gitlab.com:MyGitlabOrg/myproject.git
  â full fetch
Clonage dans '/home/username/sites/development/cms'...
GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

  failed to clone

Deploy failed

如您所见,我收到了这个奇怪的错误GitLab: The project you were looking for could not be found. ...

我已经检查了所有ssh密钥,我可以从本地计算机ssh到远程服务器,并且我也可以从远程服务器克隆回购。

您是否知道如何解决此问题?

谢谢!

2 个答案:

答案 0 :(得分:2)

SSH进入您的服务器并运行

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

这将生成私钥和公钥。 现在,复制公钥的内容以将其粘贴到GitLab上。

cat /home/ubuntu/.ssh/id_rsa.pub

接下来,检查对存储库的SSH访问权限

ssh -T git@gitlab.com

您应该会看到来自GitLab的欢迎消息。

现在您可以从PM2进行部署了。

答案 1 :(得分:0)

根据上面的示例为非root用户设置ssh,因此您必须为用户名设置ssh ...所以它将在/home/username/.ssh/id_rsa *