PaaS (Platform as a Service) provided by heroku, which was founded in the United States in 2007.
PaaS is a service that allows you to publish an application without initializing the server. This allows developers to focus on application development.
Scale-out is one of the methods to increase the processing power of the system and enhance the computer environment by increasing the number of servers that make up the system. After developing and publishing the application, it can be operated smoothly. "Maintaining an optimal environment" is indispensable for this. As the number of users who use the app increases, it will be necessary to enhance the environment so that the app can run smoothly. In order to provide a stable service to many users, it is important to scale out to improve the performance of the hardware. ** Also, on heroku, you can change the scale out immediately by operating on the dashboard screen or executing a simple command. ** **
Scale-out is one of the methods to increase the processing power of the system and enhance the computer environment by increasing the number of servers that make up the system. After developing and publishing the application, it can be operated smoothly. "Maintaining an optimal environment" is indispensable for this. As the number of users who use the app increases, it will be necessary to enhance the environment so that the app can run smoothly. In order to provide a stable service to many users, it is important to scale out to improve the performance of the hardware. ** Also, on heroku, you can change the scale out immediately by operating on the dashboard screen or executing a simple command. ** **
Heroku
brew tap heroku/brew && brew install heroku
Create an account on Heroku and make a note of your login email address and password. Type the login command in Terminal.
heroku login
The state of executing the above command is as follows.
Create a directory to put the project files and change to the directory. Execute the following command in the terminal.
mkdir flaskonheroku
cd flaskonheroku
Create the required files.
touch app.py Procfile
Edit app.py as follows.
app.py
# -*- coding: utf-8 -*-
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'hello, world'
if __name__ == '__main__':
app.run()
Edit the Procfile as follows.
web: gunicorn app:app --log-file=-
Install the required libraries this time with pip install. Do the following in your terminal:
pip3 install Flask
pip3 install gunicorn
Create requirements.txt.
pip freeze > requirements.txt
Edit requirements.txt as follows.
Flask==1.1.2
click==7.1.2
gunicorn==20.0.4
Jinja2==2.11.2
$ python app.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
It is OK if you access the address and the following screen appears.
Execute the following command in the terminal to initialize it as a git repository
git init
git add .
git commit -m "first commit"
Create an app on Heroku with the heroku create
command.
$ heroku create
Creating app... done, ⬢ secret-refuge-44790
https://secret-refuge-●●●●●●●●.herokuapp.com/ | https://git.heroku.com/secret-refuge-●●●●●●●●.git
You can also specify the app name with heroku create app name
.
If you do not specify an app name, the app name will be assigned automatically. (Can be changed later)
A remote repository has been created, so push it.
$ git remote
heroku
git push heroku master
The state of executing the command and deploying is as follows.
When you execute the following command, the browser will automatically start and the deployed Flask application will start.
heroku open
The state of the browser screen where the following screen actually started up.
・ What is heroku? Introducing the basics and features that even beginners can understand in 5 minutes | Samurai Blog --Site for beginners in programming ・ Heroku deploy on mac --Qiita ・ Active engineers explain how to deploy Python applications using heroku [for beginners] | TechAcademy Magazine -Introduction and initial settings of Heroku CLI ・ Heroku operation CLI --Qiita
Recommended Posts