pm2 创建一个“源”目录并将我的所有文件复制到其中,为什么?

mat*_*un7 7 deployment amazon-web-services node.js pm2

之前的问题我删了,因为不是很清楚,问题没有暴露出来。我有一个实例@aws,一个存储库@gitlab,并且设置了gitlab CI。我在 node.js 中做了一个小应用程序,因为我想尝试所有这些新东西。但是,当 gitlab-ci 运行脚本时,pm2 会在我的文件夹中创建一个“源”目录,然后将我的所有文件复制到该目录中,这显然是当前工作目录 (CWD)。这是一种令人惊讶的行为,我对此感到不舒服。

有谁知道为什么?正常吗?为什么我的文件不能保留在 ~/projet2/ 中,因为我设置了?

当我运行时pm2 show projet2,我可以看到exec cwdis /home/ubuntu/projet2/sourcewhilesource是一个我从未创建过的文件夹!

.git-ci.yml

# This file is a template, and might need editing before it works on your project.
# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/node/tags/
image: node:alpine

stages:
  - deploy

deploy:
  stage: deploy
  before_script:
    # Install ssh-agent if not already installed, it is required by Docker.
    # (change apt-get to yum if you use a CentOS-based image)
    - 'which ssh-agent || ( apk add --update openssh )'

    # Add bash
    - apk add --update bash

    # Add git
    - apk add --update git

    # Run ssh-agent (inside the build environment)
    - eval $(ssh-agent -s)

    # Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
    - echo "$SSH_PRIVATE_KEY" > "./pk.pem"
    - chmod 400 ./pk.pem
    - echo "$SSH_PRIVATE_KEY" | ssh-add -

    # For Docker builds disable host key checking. Be aware that by adding that
    # you are suspectible to man-in-the-middle attacks.
    # WARNING: Use this only with the Docker executor, if you use it with shell
    # you will overwrite your user's SSH config.
    - mkdir -p ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    # In order to properly check the server's host key, assuming you created the
    # SSH_SERVER_HOSTKEYS variable previously, uncomment the following two lines
    # instead.
    # - mkdir -p ~/.ssh
    # - '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'
  script:
  - npm i -g pm2
  - pm2 deploy ecosystem.config.js production setup
  - pm2 deploy ecosystem.config.js production
  only:
  - master
Run Code Online (Sandbox Code Playgroud)

生态系统配置文件

module.exports = {
  apps: [{
    name: 'projet2',
    script: '/home/ubuntu/projet2/index.js',
    cwd: '/home/ubuntu/projet2/'
  }],
  deploy: {
    production: {
      user: 'ubuntu',
      host: 'xxxxxxxxxxxx',
      ref: 'origin/master',
      repo: 'git@gitlab.com:xxxxxxx/projet2.git',
      key: './pk.pem',
      path: '/home/ubuntu/projet2/',
      'post-deploy': 'npm install && pm2 startOrRestart /home/ubuntu/projet2/ecosystem.config.js'
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Tal*_*avy 4

答案是:是的!这是正常行为!

这是可以预料的,因为你现在正在使用 pm2 运行东西,并且 pm2 知道如何处理它。

通过运行:

pm2 deploy ecosystem.config.js someName

pm2 使用提供的用户和密钥与提供的主机建立 SSH。然后,在成功连接到提供的主机后,pm2 继续尝试从 ref 内提供的引用分支执行操作git pull,该分支属于提供的存储库。拉取的数据将放置在“path”内提供的路径中,并添加“source”目录。成功拉取后,将触发部署后,它负责执行以下操作npm install,然后执行更多操作(取决于您告诉它执行的操作)。但尽管如此,源文件夹的创建是 pm2 机制内置的,并且是预期的。它不应该让你太烦恼。