Created
May 9, 2019 13:44
-
-
Save johanguse/31119e6ee0522e90a444cd2cd7f3d55f to your computer and use it in GitHub Desktop.
error on gitlab pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#image: keymetrics/pm2:latest-alpine | |
image: node:alpine | |
variables: | |
SCRIPTS_REPO: https://gitlab.com/cavalo-trucado/api | |
KEYPAIR: "/home/johan/.ssh/id_rsa.pub" | |
stages: | |
- build | |
- deploy | |
cache: | |
key: $CI_PROJECT_DIR | |
paths: | |
- node_modules/ | |
#policy: pull | |
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" | |
- 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' | |
- apk update && apk add rsync | |
#- docker info | |
- whoami | |
#- dd if=~/.ssh/id_rsa.pub | docker exec -it containername dd of=~/.ssh/authorized_keys | |
deploy: | |
stage: deploy | |
script: | |
- echo "====== Deploy to production server ======" | |
- apk update && apk upgrade | |
- apk add git openssh bash | |
- npm i -g pm2 | |
- pm2 deploy ecosystem.config.js production | |
tags: | |
- master | |
only: | |
# Trigger deployments only from master branch | |
- master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Host johanguse.com.br | |
HostName 173.82.240.136 | |
User johan | |
IdentityFile /home/johan/.ssh/id_rsa | |
Host gitlab | |
HostName gitlab.com | |
User johan | |
IdentityFile /home/johan/.ssh/id_rsa | |
Host github | |
User git | |
Hostname github.com | |
IdentityFile /home/johan/.ssh/id_rsa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
apps: [{ | |
name: 'node1', | |
port: 5000, | |
script: '/home/johan/apps/node1.johanguse.com.br/app/index.js', | |
watch: false, | |
autorestart: true, | |
//max_memory_restart: "1G", | |
exec_mode: "cluster", | |
env: { | |
NODE_ENV: 'development' | |
}, | |
env_production: { | |
NODE_ENV: 'production' | |
} | |
}, | |
{ | |
name: 'node2', | |
port: 5001, | |
autorestart: true, | |
script: '/home/johan/apps/node1.johanguse.com.br/app/index.js', | |
env: { | |
NODE_ENV: 'development' | |
}, | |
env_production: { | |
NODE_ENV: 'production' | |
} | |
} | |
], | |
deploy: { | |
production: { | |
// SSH key path, default to $HOME/.ssh | |
key: "/home/johan/.ssh/id_rsa.pub", | |
// SSH user | |
user: "johan", | |
host: ["173.82.240.136"], | |
ssh_options: "StrictHostKeyChecking=no", | |
ref: "origin/master", | |
repo: "git@gitlab.com:cavalo-trucado/api.git", | |
path: "/home/johan/apps/node1.johanguse.com.br/api2", | |
fetch: '--all', | |
"pre-deploy": "git fetch --all", | |
"post-deploy": "npm install && pm2 reload /home/johan/apps/ecosystem.config.js --env production", | |
"forward-agent": "yes" | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment