An awesome template to jumpstart your python script hosting projects on Heroku!
View Demo
·
Report Bug
·
Request Feature
There are many great heroku templates available on GitHub, however, I didn't find one that was configured to host and run python scripts quickly on heroku (on a worker dyno) so I created this enhanced one.
Here's why:
- Your time should be focused on creating something amazing. A project that solves a problem and helps others.
- You shouldn't be doing the same tasks over and over like preparing files for deployment on heroku from scratch.
- You should reserve the DRY principles to the rest of your life 😄
Of course, no one template will serve all projects since your needs may be different. So I'll be adding more in the near future. You may also suggest changes by forking this repo and creating a pull request or opening an issue.
First things first, this template is configured to host a worker dyno which allows you to host python scripts on heroku. You can modify this template to run a flask frontend by editing the procfile to web: gunicorn app:server
(Renamed server.py file to app.py). Many templates and/or documentations are available online for the same. I'll be going over the steps to configure a worker dyno for hosting scripts on heroku only for the purposes of this guide.
Before we begin, you need a couple of things installed...
- Download and Install Heroku CLI and type the following to log into your heroku account
heroku login
. - Download and Install git
After Downloading git, you can run these commands to set your username and password.
git config --global user.email "your_email_address@example.com"
git config user.password "your password"
- Scroll to the top of this page, and click on the Use This Template button to create your own repo using this template.
- Connect the remote repo to your local machine using
git remote add origin <remote-repo-url>
- Edit the server.py file in the repo to add your own python scripts.
- If you've used any external packages you need to mention them in the requirements.txt file.
- If you've changed the name of the file in Step 1 then you need to edit it in the Procfile as well.
worker: python file-name.py
- To deploy to heroku, follow the usual steps for any heroku deployment.
git add.
git commit -m"Heroku push"
heroku create
git push heroku master
- Now, once deployed, we need to give a command to heroku to start the worker process. (Your script won't start executing unless you run this line in terminal)
heroku ps:scale worker=1
Additionally, you can also tell heroku to stop executing once you have got your output by running the command
heroku ps:scale worker=0
Contributions are what make the open source community such an amazing place to be, learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Reuben Rapose - @reubence - reuben.rapose@gmail.com
Project Link: https://github.com/reubence/Heroku-Script-Deployment-Template