[PYTHON] Publish your web app in 4 minutes 33 seconds using Heroku x bottle

About this article

We will introduce how you can start web application development easily and quickly using the following two. The goal is 4 minutes and 33 seconds from the start of development to the release.

Actually, I don't think there is a need for a request * to be released immediately * in 4 minutes and 33 seconds after meeting. However, being able to deploy in 4 minutes and 33 seconds is proof that the hurdles for web development are steadily falling, and I think it is important to have that feeling with the code.

What you can understand by reading this article

From environment construction to publication

0. Preparation

The following must be installed.

1. Environment construction (Git repository initialization / Python virtual environment creation)

$ mkdir agile-dev
$ cd agile-dev
$ git init
$ pyenv virtualenv 2.7.9 agile-dev	#Any
$ pyenv local agile-dev				#Any

2. Hello world app development

Installation of libraries and application implementation required for development. By the way, the contents of ʻapp.py` are Recipes — Bottle 0.13-dev documentation-, So I'm just copying here.

$ pip install bottle

app.py


import os
from bottle import route, run

@route("/")
def hello_world():
        return "Hello World!"

run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))

3. Create the files needed for Heroku deployment

$ pip freeze > requirements.txt			#List of dependent libraries
$ echo web: python app.py > Procfile	#Application type and entry point specification

This is the end of development, so commit it.

$ git add .
$ git commit -m "initial commit"

4. Create and publish Heroku app

I will publish it immediately.

$ heroku apps:create agile-dev
$ git push heroku master

When remote: Verifying deploy ... done. is returned as the command execution result, the deployment is complete, so let's check it with a browser. The publishing URL should be displayed in the terminal. remote: https://agile-dev.herokuapp.com/ deployed to Heroku

$ open https://agile-dev.herokuapp.com/

スクリーンショット 2015-04-29 16.14.22.png

It was released safely!

lead time

Comparing the date command execution results before and after the start of work ... ** 3 minutes 54 seconds **. It ended shorter than 4 minutes and 33 seconds.

macbook-pro:~ ohbarye$ date
Wednesday, April 29, 2015 15:40:49 JST
~~(abridgement)~~
macbook-pro:agile-dev ohbarye$ date
Wednesday, April 29, 2015 15:44:43 JST

Clean up

Clean it up and put it back in place.

$ heroku apps:destroy --app agile-dev --confirm agile-dev
$ pyenv uninstall agile-dev
$ cd ../
$ rm -rf agile-dev

By the way, it was ** 1 minute 8 seconds **, so it was a little over 5 minutes in total.

Runtime result log

I will paste it for reference.

Development-deploy


macbook-pro:~ ohbarye$ date
Wednesday, April 29, 2015 15:40:49 JST
macbook-pro:~ ohbarye$ mkdir agile-dev
macbook-pro:~ ohbarye$ cd agile-dev
macbook-pro:agile-dev ohbarye$ git init
Initialized empty Git repository in /Users/ohbarye/dev/~/agile-dev/.git/
macbook-pro:agile-dev ohbarye$ pyenv virtualenv 2.7.9 agile-dev
New python executable in /Users/ohbarye/.pyenv/versions/agile-dev/bin/python2.7
Also creating executable in /Users/ohbarye/.pyenv/versions/agile-dev/bin/python
Installing setuptools, pip...done.
Ignoring indexes: https://pypi.python.org/simple/
Requirement already satisfied (use --upgrade to upgrade): setuptools in /Users/ohbarye/.pyenv/versions/agile-dev/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): pip in /Users/ohbarye/.pyenv/versions/agile-dev/lib/python2.7/site-packages
Cleaning up...
macbook-pro:agile-dev ohbarye$ pyenv local agile-dev
macbook-pro:agile-dev ohbarye$ pip install bottle
Collecting bottle
  Using cached bottle-0.12.8.tar.gz
Installing collected packages: bottle
  Running setup.py install for bottle
Successfully installed bottle-0.12.8
macbook-pro:agile-dev ohbarye$ vim app.py
macbook-pro:agile-dev ohbarye$ pip freeze > requirements.txt
macbook-pro:agile-dev ohbarye$ echo web: python app.py > Procfile
macbook-pro:agile-dev ohbarye$ git add .
macbook-pro:agile-dev ohbarye$ git commit -m "initial commit"
[master (root-commit) f213a06] initial commit
 4 files changed, 11 insertions(+)
 create mode 100644 .python-version
 create mode 100644 Procfile
 create mode 100644 app.py
 create mode 100644 requirements.txt
macbook-pro:agile-dev ohbarye$ heroku apps:create agile-dev
Creating agile-dev... done, stack is cedar-14
https://agile-dev.herokuapp.com/ | https://git.heroku.com/agile-dev.git
Git remote heroku added
macbook-pro:agile-dev ohbarye$ git push heroku master
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (6/6), 518 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote: -----> Installing runtime (python-2.7.9)
remote: -----> Installing dependencies with pip
remote:        Collecting bottle==0.12.8 (from -r requirements.txt (line 1))
remote:          Downloading bottle-0.12.8.tar.gz (69kB)
remote:        Installing collected packages: bottle
remote:          Running setup.py install for bottle
remote:            changing mode of build/scripts-2.7/bottle.py from 600 to 755
remote:            changing mode of /app/.heroku/python/bin/bottle.py to 755
remote:        Successfully installed bottle-0.12.8
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing... done, 35.1MB
remote: -----> Launching... done, v3
remote:        https://agile-dev.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/agile-dev.git
 * [new branch]      master -> master
macbook-pro:agile-dev ohbarye$ open https://agile-dev.herokuapp.com/
macbook-pro:agile-dev ohbarye$ date
Wednesday, April 29, 2015 15:44:43 JST
macbook-pro:agile-dev ohbarye$ 

Clean up


macbook-pro:agile-dev ohbarye$ date
Wednesday, April 29, 2015 15:49:11 JST
macbook-pro:agile-dev ohbarye$ heroku apps:destroy --app agile-dev --confirm agile-dev
Destroying agile-dev (including all add-ons)... done
macbook-pro:agile-dev ohbarye$ pyenv uninstall agile-dev
pyenv: remove /Users/ohbarye/.pyenv/versions/agile-dev? y
macbook-pro:agile-dev ohbarye$ cd ../
macbook-pro:~ ohbarye$ rm -rf agile-dev/
macbook-pro:~ ohbarye$ date
Wednesday, April 29, 2015 15:50:19 JST
macbook-pro:~ ohbarye$ 

Recommended Posts

Publish your web app in 4 minutes 33 seconds using Heroku x bottle
Easy 3 minutes TensorBoard in Google Colab (using TensorFlow 2.x)
Web application using Bottle (1)
How to deploy a Django app on heroku in just 5 minutes
Deploy Django in 3 minutes using docker-compose
Set up a local web server in 30 seconds using python 3's http.server
Until you publish (deploy) a web application made with bottle on Heroku