A step by step guide. Check the commit history of the step-by-step
branch!. In each step, the bold part will take you to the commit in the step-by-step
branch (read the comments!). The 'Go to x
' will show you the source of x
.
- Create the
pre_build
script: This script will be executed before the build step. Time to install Python 3.5.3 (if it's not there already), create your virtualenv fodler (same) and clean up your temporary directory. Go topre_build
- Create the
build
script: In this step, our requirements are installed in our virtual environment. We'll use Flask and Gunicorn (more on this later). Go tobuild
- Create a "Hello world!" Flask app: This Flask application will be served by Gunicorn later. It's simple... it's just a "Hello world!"... nothing too interesting. Go to
demo.py
- Create
requirements.txt
: This requirements will be installed in the build step. I put here everything that my app needs to run in Python. So I'll put here "Flask". Go torequirements.txt
- **Create
dev_requirements.txt**](https://github.com/aaossa/openshift-diy-python-how-to/commit/188438799034e2ea758f99b8cf9364b39a4e6ebe): In this file I put everything that my app needs to be executed from bash scripts (like Gunicorn and Virtualenv) and for testing (like Pytest). In this case I put "Gunicorn". [Go to
dev_requirements.txt` - Create the
start
script: The start script launches the application. Here I activate the virtual environment and use Gunicorn to serve in the background. Read the script, I liked it. Go tostart
- Create the
stop
script: This script uses the pid file created by Gunicorn in the start script to kill the process properly. Go tostop
This template provides Python 3.5.3, a "Hello world!" Flask app and a Gunicorn configuration that serves the Flask app. Now that everything that needs to be said has already been said... Take this code and use it with just one command
rhc app-create <app_name> diy-0.1 --from-code https://github.com/aaossa/openshift-diy-python-how-to.git
NOTE: To install Python, activate the environment, etc., the pre_build
script must be triggered. How to do that? Just push a commit. Install Python from source takes a lot of time (~10+ minutes). To set up Travis CI to deploy automatically to OpenShift read the wiki!