Skip to content
Grant Steinfeld edited this page Mar 4, 2020 · 7 revisions

Code Pattern

Deploy an application to Openshift 4 using Redhat's universal base image

By Grant Steinfeld grant.steinfeld@ibm.com

get the code

Summary

This code pattern is part of the Bee Travels project that focuses on deploying a Python currency exchange application to Openshift 4 using Redhat's universal base image

Technologies

  • Python
  • Flask
  • RedHat Universal Base Image (UBI)
  • OpenShift 4
  • Microservices

Description

Red Hat Universal Base Images (UBI) are OCI-compliant container base operating system images with complementary runtime languages and packages that are freely redistributable. Like previous RHEL base images, they are built from portions of Red Hat Enterprise Linux

This code pattern will show you how to create a world class currency conversion microservice using Test Driven Development (TDD) in Python. This code pattern is a microservice that is a part of the Bee Travels project

When you have completed this code pattern, you will understand how to:

  • Design and create a Python microservice with a REST interface that has a swagger test harness where you can manually inspect, discover, and run the various API endpoints.
  • Use and run this simple microservice.
  • Build a docker image of this microservice using the RedHat Universal Base Image(UBI)
  • Deploy and run this microservice on OpenShift version 4

Architecture

This is the flow of the currency conversion microservice.

architecture flow diagram

figure 1: Architecture flow

  1. Client API Consumer calls the microservice over the internet (http/s request).
  2. Flask process acts as a web server and accepts the REST request (e.g. GET /convertCurrency/ZAR/USD/600.66).
  3. Code routing in Flask passes the request to a service module which in turn calls the External European Currency Exchange API (http://api.exchangeratesapi.io).
  4. An exchange rate for ZAR is retrieved and stored. The value of 600.66 South African Rands (ZAR) is converted to US Dollars(USD).
  5. Flask then sends a response to the calling consumer with the dollar amount (in this case, $40.59 ).

Steps to run this code pattern

Follow these steps to set up and run this code pattern locally and on the cloud. The steps are described in detail below.

  1. Clone the GitHub repository locally
  2. Build a docker image, then run it locally
  3. Deploy to IBM RedHat OpenShift 4 Cluster

Runtimes

  • Python3 / Flask

Related Links

Introducing the Red Hat Universal Base Image - RedHat blog by Scott McCarty

Python RESTful APIs using flask-restplus