Skip to main content
The 2024 Developer Survey results are live! See the results
1179
1

Introduction

In the present day, business organizations are concerned about the time saved by streamlined business processes. Online reservation management is a vastly used practical solution to achieve this. Allowing users to make reservations online provides advantages to both parties (the service providers and service consumers). In this blog we are going to deploy a containerized Flask reservation management application, capable of performing CRUD(Create, Read, Update, Delete) operations for reservations. Users can view all the existing reservations and a given reservation can be managed using a reservation ID.

Flask boosted the world of web development due to its simplicity, flexibility, and rapid development capabilities and empowers developers to build web applications quickly without unnecessary complexity. Its minimalist design encourages learning and experimentation, making it an ideal choice for Small and Medium Size Enterprise (SME) web service development .

Deploying an application to a platform with a lot of in-built additional features such as DevOps, business insight generation, observability, testing capability, automatic deployments, security, rate-limits etc reduces the deployment challenges most businesses have to face and also speeds up the time to market. Choreo is an internal developer platform that accelerates integration experiences. It accelerates development and helps organizations go to market faster.


How it works

The Flask reservation management application mainly contains two resource endpoints to view, create, update and delete reservations. The application maintains reservations in memory and can be integrated with a database if required.

  • /reservations

    • Provides all the available reservations available in the application.
  • /reservations/{reservationId}

    • Allows to perform CRUD operation considering a given reservation ID

In this blog we will deploy our Reservation management Flask application to Choreo. Initial data to the application will be provided as a config file (a mounted file) through the Choreo UI. After successful deployment we will test the application and apply error handling support as a change to the application to observe how automatic deployments are applied in Choreo. We will then apply security and rate limiting to the resources. We will also view usage insights reports, observability data and DevOps configuration capabilities available in Choreo.

Prerequisites

  • Choreo user account.

  • Containerised Flask application. Sample application is available here.

  • Connect your flask application’s GitHub repository to Choreo as explained here.

Step 1: Deploying the Flask reservation management application in Choreo

  1. Sign up or login to Choreo.

  2. Click the create button in the Service component card.

  3. Enter the name and description field values and click next.

    enter image description here

  4. In the authorization section, select Authorize with GitHub and click next.

    enter image description here

  5. Provide the following values correctly to build the docker image and click create.

    enter image description here

  6. Your component will be created. Now we need to deploy the created service component.

  7. Navigate to the Deploy tab.

    enter image description here

  8. Click the configure and deploy button. In the file mounting section we need to provide a file with the initial dataset for the application. Add the following values and click deploy.

    • Mount path: /python-docker/data.txt

    • Data:

      [{"reservationCreator": "John Doe", "reservationId": "1234", "contact": "011-123-4567"}, {"reservationCreator": "Jane Doe", "reservationId": "5678", "contact": "011-123-4562"}, {"reservationCreator": "John Smith", "reservationId": "9012", "contact": "011-123-4523"}]

  9. After completing the required steps, the Flask reservation management application will be deployed and available in the Choreo developer environment.

    enter image description hereenter image description here

  10. To test the application, select the Console under the Test section. Let’s test the /reservations resource Click Try Out and then click Execute. The result should be the reservation details we added to the file mount.

enter image description here

Congratulations !!! 👏👏

You have deployed and tested the reservation management Flask application in Choreo in just  a few steps.

Step 2: Auto deploy the application with latest changes

Let’s apply a change to the application to observe the automatic deployment capability in Choreo. The initial version of the flask application does not have the error handling capability for the getReservation method. Let’s handle it and see how we can easily apply the changes to an application deployed in Choreo.

Edit the route relevant to the reservation management function as below.

@app.route('/rs/reservation/<reservationId>', methods=['GET', 'POST', 'PUT', 'DELETE'])
def reservation_management(reservationId):
    try:
        if request.method == "GET":
            return str("Your reservation details: " + getReservation(reservationId))
        elif request.method == "POST":
            return str("Your added reservation details: " + addReservation(request))
        elif request.method == "PUT":
            return "Reservation updated: " + updateReservation(reservationId, request) ;
        elif request.method == "DELETE":
            return "Reservation deleted: " + deleteReservation(reservationId)
    except:
         return "Cannot handle the given reservation ID"

Push the changes upstream after testing it locally.

Choreo will automatically deploy the application with the new changes you just pushed. Navigate to the Console view in the Test page and invoke the /reservation/{reservationId} resource with a reservation that is not available

Step 3: Observing additional inbuilt capabilities in Choreo.

Adding security and rate-limiting for the resources

Choreo’s inbuilt features allow you to apply security and rate-limiting settings to the resources you define.

Navigate to the settings tab in the Manage section and apply the changes shown below.

After applying the changes,

  • Security will be disabled for the GET /reservations operation

  • GET  /reservations/<reservationID>  operation will have a rate-limit of 4 requests per minute.

Save and apply the changes.

Invoke the resources as demonstrated below and notice that the security and rate-limiting settings have been applied correctly.

Usage insights

Choreo allows you to obtain the usage insights relevant to the resource invocations. To view the usage insights follow steps below.

  1. Go to the project level in the top navigation menu.
  2. Select Usage Insights in the left navigation bar. You can view usage insights related to different aspects (latency, traffic, cache, devices etc) now.

Observability

In Choreo you can view your application’s behaviour during the deployment and after the deployment. To view observability details select your created service component and select observability in the left navigation menu.

DevOps

In the DevOps section you can configure the parameters relevant to your Flask application’s deployment. To view DevOps configurations click the DevOps section in the left navigation menu.

Conclusion:

In this article we deployed a containerised Flask reservation management  application to Choreo in a few clicks. We also discovered how easily Choreo applies the updated changes to the deployed Flask application due to the auto deploy on commit capability. We tested the deployed application and it helped discover the outputs and errors before promoting it to the production environment. Due to the multi-environment capability in Choreo we can test the application in the developer environment before directly applying changes to production. Choreo provides inbuilt support to apply security and rate-limiting to the resources you created.

Usage insights provide how invocations relevant to the application happened considering different aspects. The observability section lets you view the behaviour of the application during and after deployment. If we want to configure configurable values, add health checks, view container metrics, the DevOps section in the Choreo provides all of those capabilities. All these capabilities are enabled in Choreo by default.  You are only required to bring a correctly configured containerised application to the Choreo to deploy it. This helps to save time while enabling top grade production level applications with a lot of additional features related to it. Try Out Choreo today!

References:

Choreo: https://wso2.com/choreo/docs/what-is-choreo/

Service components in Choreo: https://wso2.com/choreo/docs/develop-components/develop-services/develop-a-service/#what-is-a-service-component

Deploy a containerized application in Choreo: https://wso2.com/choreo/docs/develop-components/deploy-a-containerized-application/