Skip to content

Instantly share code, notes, and snippets.

@joseadrian
Forked from camwhite/.gitlab-ci.yml
Created March 19, 2020 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseadrian/49e69835bc7345f6aa2adb18545dd1cc to your computer and use it in GitHub Desktop.
Save joseadrian/49e69835bc7345f6aa2adb18545dd1cc to your computer and use it in GitHub Desktop.
image: node:8.9.0
cache:
paths:
- node_modules/
stages:
- deploy
before_script:
# Check for ssh-agent + rsync and install if not present
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
- eval $(ssh-agent -s)
# Inject the remote's private key
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
# Append keyscan output into known hosts
- ssh-keyscan $SERVER_IP >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- npm install
- npm run build
deploy:
stage: deploy
script:
- rsync -avuz --exclude=".*" $CI_PROJECT_DIR $SERVER_USER@$SERVER_IP:~
# Non interactive ssh gracefully reloads server
- ssh $SERVER_USER@$SERVER_IP '. /etc/profile; pm2 reload all'
only:
# Trigger deployments only from master branch
- master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment