Deploy to Heroku - mzogheib/quoll GitHub Wiki

Prerequisits

  • Install heroku globally and login
npm install -g heroku
heroku login

Initial Setup

  1. Create an app for each package:

    heroku create quoll-api --remote heroku-quoll-api
    heroku create quoll-client --remote heroku-quoll-client
    
  2. Add a Procfile for each, with:

    // packages/api/Procfile
    web: node server.js
    
    // packages/client/Procfile
    web: bin/boot
    
  3. Add buildpacks. The monorepo one needs to be "defined first". Or add via the Heroku Dashboard.

    heroku buildpacks:add -a quoll-api https://github.com/lstoll/heroku-buildpack-monorepo
    heroku buildpacks:add -a quoll-client https://github.com/lstoll/heroku-buildpack-monorepo
    
    heroku buildpacks:add -a quoll-api https://github.com/heroku/heroku-buildpack-nodejs
    
    heroku buildpacks:add -a quoll-client mars/create-react-app
    

    https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-nodejs

    https://elements.heroku.com/buildpacks/lstoll/heroku-buildpack-monorepo

    https://elements.heroku.com/buildpacks/mars/create-react-app-buildpack

  4. Then add this config variable to each app.

    // in quoll-api
    APP_BASE=packages/api
    
    
    // in quoll-client
    APP_BASE=packages/client
    
  5. Add any other config (env) variables required to run the app. Create React App env variables are prefixed with REACT_APP_.

  6. Make some changes and commit them.

  7. Deploy to Heroku.

    # If on master
    git push heroku-quoll-api master
    git push heroku-quoll-client master
    
    # If another branch
    git push heroku-quoll-api another-branch:master
    git push heroku-quoll-client another-branch:master
    
  8. For some reason api needs to manually start the server...? https://stackoverflow.com/questions/11405826/error-h14-no-web-processes-running-deploy-on-heroku.

    heroku ps:scale web=1 --remote heroku-quoll-api
    

References

Force a redeploy

  • Sometimes you may want to redeploy the apps even though no code changes were made.
  • Create an empty commit and deploy.
git commit --allow-empty -m  "chore: force deploy" --no-verify
git push heroku-quoll-client master

After a git clone to a new machine or folder

  1. First, check your remotes. If a heroku remote(s) already exists then ... deal with it
git remote -v
  1. Set up the remotes
git remote add heroku-quoll-api https://git.heroku.com/quoll-api.git
git remote add heroku-quoll-client https://git.heroku.com/quoll-client.git
  1. Go through the deploy step above as normal

References