node.js - pm2 创建了一个 "source"目录并将我的所有文件复制到其中,为什么?

标签 node.js amazon-web-services deployment pm2

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

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

当我跑 pm2 show projet2 ,我可以看到exec cwd/home/ubuntu/projet2/sourcesource是我从未创建过的文件夹!

.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

生态系统配置文件
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'
    }
  }
}

最佳答案

答案是:是的!这是正常行为!
这是意料之中的,因为您现在正在使用 pm2 运行东西,而 pm2 知道如何处理它。
通过运行:pm2 deploy ecosystem.config.js someNamepm2 正在使用提供的用户和 key 对提供的主机进行 SSH。然后,在与提供的主机成功连接后,pm2 继续尝试从 ref 内提供的引用分支执行 git pull,该分支属于提供的存储库。拉取的数据将放置在“路径”中提供的路径中,添加一个“源”目录 .成功拉取后,将触发后期部署,它负责执行 npm 安装,然后执行其他一些操作(取决于您告诉它做什么)。但是,尽管如此,源文件夹的创建是 pm2 机制内置的,也是意料之中的。它不应该太打扰你。

关于node.js - pm2 创建了一个 "source"目录并将我的所有文件复制到其中,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58150852/

相关文章:

javascript - 设置输入值而不是 sendKeys() - Selenium WebDriver nodejs

node.js - 在单独的线程 Node Js 中运行长时间运行的快速 API 进程

javascript - 使用电子邮件或用户名的 Node.js Passport 策略登录

amazon-web-services - 将物理名称从一个堆栈导出和导入到另一个堆栈

amazon-web-services - s3 - 调用 HeadObject 操作时发生错误 (403) : Forbidden

java - 将 Java Web Start jar 与 Web 应用程序集成

javascript - 使用 'nestjs/jwt' 签名动态/用户相关的 secret

ruby-on-rails - 云形成中 "Rails App Server"的类型是什么?

c++ - Qt Qt5Network 链接错误的静态构建

c# - 如何使用 SQL Server 数据库部署或发布 Windows 应用程序