Skip to content

Instantly share code, notes, and snippets.

@loganknecht
Last active March 30, 2019 06:42
Show Gist options
  • Save loganknecht/b5e5673c8321651c572b207328c23431 to your computer and use it in GitHub Desktop.
Save loganknecht/b5e5673c8321651c572b207328c23431 to your computer and use it in GitHub Desktop.
HOW TO: Heroku Docker Deployment
  1. Create Something to Deploy
    • Create a Dockerfile in the root directory of the project
      • The Dockerfile location determines the root directory that the docker file's environment is built from
        • I.E. it'll affect ADD, COPY, VOLUME, etc.
      • This should set up the environment for the project to run
      • IF THIS RELIES ON WEB TRAFFIC: a $PORT environment variable is required to be used because Heroku by default doesn't allow port selection. This means you need to rely on the environment having the $PORT variable available when crafting the launch command
        • Example: CMD gunicorn --bind 0.0.0.0:$PORT example.wsgi
    • Try to do all set up in here. A script will only complicate it and make it hard to understand deployment
  2. (Optional) Clean up
    • List existing remotes
      • git remote --verbose
    • Delete unecessary remotes
      • git remote rm $REMOTE_NAME
    • List Heroku apps
      • heroku apps
    • Destroy heroku app if needed
      • heroku apps:destroy $HEROKU_APP_NAME --confirm=$HEROKU_APP_NAME
  3. Create a heroku.yml in the root of the repository
    • Please see the documentation for how it should look.
    • Pitfall: The dockerfile's location will determine the context for when docker build is called on it
      • Example
        build: 
            docker: 
                example_image: example_api/Dockerfile
        
        • In the above example the root context for the build will be example_api
  4. Create Heroku App if it doesn't exist
    • heroku create $HEROKU_APP_NAME --remote $HEROKU_APP_GIT_REMOTE_NAME
      • --remote $HEROKU_APP_GIT_REMOTE_NAME doesn't need to provided, it will default to heroku
      • --remote $HEROKU_APP_GIT_REMOTE_NAME is used because this is a mono repo so different repos will be deploying through different git remote hooks
    • This should only need to be done once in the repo to connect it to heroku
  5. Set heroku to use a container stack in order to use Docker/heroku.yml deployments
  6. Deploy to Heroku
    • Default deploy
      • git push $HEROKU_APP_GIT_REMOTE_NAME $DESIRED_BRANCH_TO_DEPLOY:master
    • Forcing a deploy in the current branch
      • git push --force $HEROKU_APP_GIT_REMOTE_NAME HEAD:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment