Nice to meet you. This is Taro Man. I usually develop web services.
-** Siltrend **
彡 (゜) (゜) "I want to make a ** service ** and publish it ~" 彡 (゜) (゜) "But it's ** trouble ** to rent a rental server ..." 彡 (゜) (゜) "** Server fee ** I don't want to pay ..."
Have you ever felt like this? I'm sure there is.
In that case, use the ** Heroku Free Plan **. In this article, I'll write about how to publish your application on Heroku's free plan.
▷ Heroku official website is here
You can do most of the things. You can use it without any problems if you deploy and operate the application on the server.
There are two restrictions to keep in mind with Heroku's free plan:
--Free Dyno hours (operating hours) is 550 hours / month ――The app goes to sleep if there is no access for 30 minutes
If you leave Heroku's free plan at its default, you'll only get 550 hours of Dyno hours a month.
30 days x 24 hours = 720 hours, so if you try to run it at full capacity for a month, the free plan is not enough.
However, this can be solved if you have a ** credit card **.
Even with the free plan, if you register a credit card in your account 450 hours / month of free Dyno hours will be added, allowing you to use up to a total of ** 1,000 hours ** / month.
With the free plan, the app will sleep if there is no access for 30 minutes, The response will be slow ** by the time the app is launched the next time you access it.
However, this can be solved with ** Heroku Scheduler **.
Heroku Scheduler is a feature that allows you to periodically execute specified commands. It's like Linux cron.
By running the ** curl command ** on your app's URL on Heroku Scheduler You can keep running without dropping the app.
▷ How to set up Heroku Scheduler is summarized in this article.
Install the libraries needed for your project to run on Heroku.
pip install gunicorn django-heroku
Create a file in ** directly under the project directory ** that tells Heroku the execution environment of the project.
runtime.txt
A file that describes the Python version.
runtime.txt
python-3.6.6
Procfile
This file contains commands to start the Heroku process.
Replace <your-project-name>
with your own project name.
Procfile
web: gunicorn <your-project-name>.wsgi --log-file -
requirements.txt
Here is a list of dependent packages.
Let's save the output result of the pip freeze
command as it is.
commandline
pip freeze > requirements.txt
Change the DEBUG = Ture
part of settings.py
for production use.
your-project/settings.py
DEBUG = False
Create & commit a local repository in Git.
python
git init
git config user.name "Your Name"
git config user.email [email protected]
git add .
git commit -m "first commit"
Deploy to Heroku with the Heroku command.
When you run the heroku login
command, your browser will launch and you will be asked to authenticate with Heroku.
After logging in, you can go back to the terminal ** without dropping your browser for further work.
python
heroku login
heroku create <your-app-name>
git push heroku master
heroku ps:scale web=1
heroku run python manage.py migrate
We hope that as many engineers as possible can publish their products to the world.
Recommended Posts