Deploying a Minimalistic Flask Application to OpenShift

Some colleagues and I were discussing the network access policy of OpenShift. I realized it would be very helpful to have a trivial app that I could deploy to OpenShift that would then try to make a call to another service. So I wrote it using Python3 and Flask. Now that I have it working, I want to deploy it in OpenShift, again, in a trivial manner.

I would not deploy a Flask App into production without a Web server to front it. But that is what I am going to do for this test app.

Here is the code.

The first step is just to attempt to deploy the code using the Web UI and Python S2I/ Git Based deployment. This gets through the build, but then fails with:

ERROR: don’t know how to run your application.Please set either APP_MODULE, APP_FILE or APP_SCRIPT environment variables, or create a file ‘app.py’ to launch your application.

In my case, I want to make an app.sh file that will run flask. Here is the contents:

export FLASK_APP=ckaccess
flask run

With that, the app deployment succeeds. But I still cannot connect to the app: The link from the WebUI gives me “Application is not available”

I need to make two changes to get the app exposed. First, I need to listen on all interfaces, so 0.0.0.0. Second, I need to listen on port 8080 instead of 5000. Thus, my script looks like this:

export FLASK_APP=ckaccess
flask run -p 8080 --host=0.0.0.0

There are obviously other ways to solve this problem, but I was going for “straight line distance” in this effort.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.