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

时间:2019-09-28 22:46:20

标签: 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/source,而source是我从未创建过的文件夹!

.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

ecosystem.config.js

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'
    }
  }
}

0 个答案:

没有答案