Minimal example of a pipeline for deploying Yesod to Heroku through CircleCI.
When you push change to the repository, CircleCI builds yesod application, runs tests and pushes statically linked binary to the Heroku.
As the Yesod app is statically compiled resulting binary doesn't need any dependencies.
Environment variables you need to define in CircleCI project settings:
HEROKU_PROJECT
- Name of your Heroku projectHEROKU_LOGIN
- Your emailHEROKU_API_KEY
- Can be found on https://dashboard.heroku.com/account
- Create a minimal Yesod app
tack new YOUR_APP_NAME yesod-minimal
- Update
src/Main.hs
to use port from thePORT
env var (example) - Create
.circleci
directory in the root of your project and add config.yml and setup-heroku.sh - Create a Heroku project with null buildpack
heroku create YOUR_PROJECT_NAME --buildpack http://github.com/ryandotsmith/null-buildpack.git
- Add Heroku remote to your project
heroku git:remote -a YOUR_HEROKU_PROJECT_NAME
- Add Procfile with default web process pointing to binary which will be created durinng CircleCI build -
dist/YOUR_APP_NAME
(example) - Push your changes to your project's repo (Github or Bitbucket will both work)
- Create new CircleCI project for project's repository and add required environment variables (
HEROKU_PROJECT
,HEROKU_LOGIN
,HEROKU_API_KEY
) in CircleCI's project settings. (In case you are not familiar with CircleCI check out CircleCI 2.0 - First Steps) - Now when you commit and push to your repository it will trigger CircleCI build which will deploy your app to Heroku
- Once CircleCI build is finished, visit your app on Heroku and verify that it works - https://YOUR_HEROKU_PROJECT_NAME.herokuapp.com/
- Celebrate
Another good alternative is to use Stack's docker integration to build a docker image and deploy it to Heroku Container Registry.