Skip to content

Instantly share code, notes, and snippets.

@glebec
Created March 1, 2018 05:36
Show Gist options
  • Save glebec/c164f76a7cc76651d298e096d9eea44c to your computer and use it in GitHub Desktop.
Save glebec/c164f76a7cc76651d298e096d9eea44c to your computer and use it in GitHub Desktop.
Fast Travis deployment with build from dev dependencies

Fast Travis Build & Heroku Deployment

Below is a sample .travis.yml which:

  • Uses dist: trusty + sudo: false to enable fast Docker containers
  • Uses npm ci to install quickly before testing
  • Builds from modules in devDependencies
  • Includes the build in the deployment
  • Omits node_modules (smaller tarball & no Heroku warning)
language: node_js
node_js:
  - node # uses most recent stable node version
services:
  - postgresql # starts up postgres
addons:
  postgresql: '9.6' # highest available postgres version on Travis
dist: trusty # uses trusty environment
sudo: false # when on trusty, uses Docker containers for speed
install:
  - npm i -g npm@5.7.1 # delete once 5.7.X is out of "pre-release"
  - npm ci             # faster, goes only from package-lock
before_script:
  - psql -c 'create database "coolproject-test";' -U postgres
before_deploy:
  - webpack # make the bundle
  - rm -rf node_modules # omit from the tarball, since we skip cleanup
deploy:
  skip_cleanup: true # prevents travis from deleting the build
  provider: heroku
  app: YOUR-HEROKU-APP-NAME-HERE
  api_key:
    secure: YOUR-***ENCRYPTED***-API-KEY-HERE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment