【发布时间】:2020-01-28 17:49:13
【问题描述】:
我之前的问题删除了,因为不是很清楚,问题暴露的不是很清楚。我有一个实例@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
生态系统.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'
}
}
}
【问题讨论】:
-
我知道这是旧的,但如果其他人仍然在这里结束我也想说我:) 另外:我的解决方法是 cp -r 从 /source 到 ./ 作为第一个命令在“部署后”中。我无法找到正确的解决方案,这可以满足我的需求。
标签: node.js amazon-web-services deployment pm2