November 07, 2018
The previous post discussed about the Flask app I created using the Austin, TX Open Data Portal. To deploy the app on Heroku without leaking API keys, I had to do some git manipulation. 💥
Supossing that you already have the heroku-cli installed in your system, and that the files that contain the API keys are .gitignored, commit all files in the application.
$ heroku login
$ heroku apps:create niceFlaskAppName
$ pip install gunicorn
$ echo 'web: gunicorn flaskAppMainFileName:app --log-file=-' > Procfile
The most confusing part of this, especially if you’re new to flask is figuring out the main file that runs the Flask app. This is found in the root folder.
runtime.txtwhich specifies the version of Python used in the app.
$ echo python-3.7.0 > runtime.txt
$ heroku local
Otherwise, skip this step.
pip freeze > requirements.txt
Commit everything in the folder in git.
Instead of pushing to heroku at this point, create another branch. I name my branch
deploy or something like that.
$ git checkout -b deploy
$ git add -f pathToSecretFile $ git commit -m 'Deploying' $ git push --force heroku deploy:master
This will now build your app on heroku. Use
heroku logs --tail to find see errors if there are any.
$ heroku open
Or open the app from the Heroku dashboard on the browser.
Again, this does not account for if the app has a database. For that, Heroku Add-ons is needed to be configured.
Lastly, don’t forget to avoid merging the deploy branch into master. 🌝 Good luck!