Skip to content

Instantly share code, notes, and snippets.

@trvswgnr
Last active February 12, 2019 04:03
Show Gist options
  • Save trvswgnr/4973a29408fcb51b7a2b9155d0994bfd to your computer and use it in GitHub Desktop.
Save trvswgnr/4973a29408fcb51b7a2b9155d0994bfd to your computer and use it in GitHub Desktop.
Travis CI Automated NPM Build & SSH Deploy
language: node_js # use 'generic' if not compiling anything
node_js:
- "node"
cache: npm
env:
global:
- DEVELOPMENT_PATH="/full/path/to/dev/deployment/directory"
- PRODUCTION_PATH="/full/path/to/production/deployment/directory"
- SSH_USER="username"
- SSH_HOST="example.com"
- DEPLOY_IGNORE="./deployignore"
addons:
ssh_known_hosts: example.com
before_install:
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then exit 0; fi
- openssl aes-256-cbc -K $encrypted_615321f5512c_key -iv $encrypted_615321f5512c_iv
-in deploy_rsa.enc -out /tmp/deploy_rsa -d
- eval "$(ssh-agent -s)"
- chmod 600 /tmp/deploy_rsa
- ssh-add /tmp/deploy_rsa
deploy:
- provider: script
skip_cleanup: true
script: bash ./deploy.sh
on:
all_branches: true
condition: "$TRAVIS_BRANCH =~ ^dev|master$"
#!/usr/bin/env bash
# NOTE: this file needs to have write and execute permissions (chmod u+x ./deploy.sh)
set -e
DEPLOY_PATH=$DEVELOPMENT_PATH
if [ $TRAVIS_BRANCH = "master" ]; then DEPLOY_PATH=$PRODUCTION_PATH; fi
rsync -r --delete-after --quiet $TRAVIS_BUILD_DIR/ --exclude-from=$DEPLOY_IGNORE $SSH_USER@$SSH_HOST:$DEPLOY_PATH
/.*
/node_modules/
/src/
/config.js
/package.json
/package-lock.json
/deploy_rsa.enc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment