I deleted my previous question because it was not very clear, and the problem was not clearly exposed. I have an instance @aws, a repository @gitlab, and gitlab CI is setup. I made a little app in node.js because I want to try all these new stuff. But, when gitlab-ci runs the script, pm2 creates a "source" directory in my folder, then copied all my files in this directory, which is appearently the Current Working Directory (CWD). That's a surprising behavior, and I'm not comfortable with it.
Anyone knows why ? Is it normal ? Why can't my files stay in ~/projet2/, as I set up ?
When I run pm2 show projet2
, I can see the exec cwd
is /home/ubuntu/projet2/source
while source
is a folder I've never created !
.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: '[email protected]:xxxxxxx/projet2.git',
key: './pk.pem',
path: '/home/ubuntu/projet2/',
'post-deploy': 'npm install && pm2 startOrRestart /home/ubuntu/projet2/ecosystem.config.js'
}
}
}
PM2 is an acronym of Process Management Module which is used to run and manage Node. js applications. It's an open-source with an in-built load balancer. When a process goes down, PM2 will automatically restart the service and make it Live.
The default configuration file is ecosystem. core3. config. js , and is located in the root folder of lisk-service : It contains a configuration to connect to a local Lisk Core node.
yes, you need to install it globally.
The answer is: Yes! This is normal behavior!
It is to be expected, since you are running things with pm2 now, and pm2 knows how to handle it.
By running:
pm2 deploy ecosystem.config.js someName
the pm2 is making an SSH to the provided host, using the provided user and key. Then, on a successful connection to the provided host, pm2 proceeds to try and do a git pull
from the provided referenced branch inside ref, which belongs to the provided repo. The pulled data will be placed in the provided path inside 'path', with the addition of a 'source' directory. After a successful pull, the post-deploy will be triggered, which is in charge of doing the npm install
and then some more stuff (depending on what you tell it to do). But nevertheless, the creation of the source folder is something that is built-in to the pm2 mechanism, and is to be expected. It shouldn't bother you too much.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With