简体   繁体   English

将 pm2 与 CircleCI 一起使用

[英]Use pm2 with CircleCI

I am using pm2 on my remote ubuntu server and CircleCI for CI, I've got the following configuration files:我在我的远程 ubuntu 服务器和 CircleCI 上使用 pm2 for CI,我有以下配置文件:

version: 2.1
orbs:
  node: circleci/node@1.1.6
jobs:
  deploy-prod:
    docker:
    # specify the version you desire here (you might not want node)
    - image: circleci/node:7.10
    steps:
        - checkout
        - run: ssh -oStrictHostKeyChecking=no -v $DROPLET_USER@$DROPLET_IP ./deploy_project.sh $MICROSERVICE_NAME
workflows:
    build-and-test:
      jobs:
        - deploy-prod:
            filters:
              branches:
                only:
                  - master

In my deploy script I do the following:在我的部署脚本中,我执行以下操作:

cd /var/www/nodejs/$1
git pull git@github.com:DevandScorp/hippocrates_authorizationmicroservice.git
cd ..
pm2 restart ecosystem.config.js --only $1

But I've got the following error:但我有以下错误:

./deploy_project.sh: line 4: pm2: command not found

Is it possible to run my server's pm2 in CircleCI config or can I reload my microservice automatically in another way?是否可以在 CircleCI 配置中运行我的服务器的 pm2 或者我可以用另一种方式自动重新加载我的微服务?

So, if you want to make anything on your server using CircleCI, it's just a waste of time.所以,如果你想使用 CircleCI 在你的服务器上做任何事情,那只是浪费时间。 CircleCI provides a virtual environment, where you can, for example, make some tests. CircleCI 提供了一个虚拟环境,例如,您可以在其中进行一些测试。 Also you can push changes on your remote server, but CircleCI will not have any access to your server's system.您也可以在远程服务器上推送更改,但 CircleCI 将无法访问您的服务器系统。 So if we speak about pm2, you can enable watch mode and relaunch your microservice everytime CircleCI push changes to it因此,如果我们谈论 pm2,您可以启用监视模式并在每次 CircleCI 推送更改时重新启动您的微服务

Add your deploy SSH keys to Github (or whatever your remote source control is), link it to CircleCI to allow Circle CI to SSH into your remote server and have it run pm2 there.将部署的 SSH 密钥添加到 Github(或任何远程源代码控制),将其链接到 CircleCI 以允许 Circle CI 到 SSH 到您的远程服务器并让它在那里运行 pm2。

Adding your SSH Keys to Github将 SSH 密钥添加到 Github

You'd follow similar steps for Bitbucket, etc您将对 Bitbucket 等执行类似的步骤

https://github.com/settings/ssh/new https://github.com/settings/ssh/new

Add your SSH fingerprint to your CI steps:将您的 SSH 指纹添加到您的 CI 步骤:

      - add_ssh_keys:
          fingerprints:
            - "bb:bb:bb:bb:bb:bb:bb:bb:bb:bb:bb:bb:bb:bb:bb:bb"

CI SSHes into your remote server and runs pm2: CI 通过 SSH 连接到您的远程服务器并运行 pm2:

    steps:
      - checkout
      - run:
          name: Deploy over SSH
          command: ssh -p your_port_number your_user@your_host "cd ../path/to/your/project; git pull; pm2 start hello_sts";

I followed this guide: https://scribe.rip/@blueish/how-to-setup-ci-cd-with-circleci-and-deploy-your-nodejs-project-to-a-remote-server-275a31d1f6c4我遵循了本指南: https://scribe.rip/@blueish/how-to-setup-ci-cd-with-circleci-and-deploy-your-nodejs-project-to-a-remote-server-275a31d1f6c4

although it's for Bitbucket, not Github.尽管它适用于 Bitbucket,而不是 Github。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM