Creating a Python Hello World Application on Oracle Application Container Cloud


Options



Before You Begin

Purpose

In this tutorial you learn how to create a simple REST service in Python, and how to generate the application archive to deploy your application to Oracle Application Container Cloud Service.

Time to Complete

Approximately 15 minutes

Background

Oracle Application Container Cloud expands the functionality of the Oracle Cloud Platform by enabling customers to easily and rapidly deploy Java SE, Node.js, PHP, and Python applications along with any required libraries or frameworks available for each programming language.

What Do You Need?

Creating the REST Service

Create the app.py file and add the following code:

#!/usr/bin/python
import os
from http.server import BaseHTTPRequestHandler, HTTPServer
PORT_NUMBER = int(os.environ.get('PORT', 8084))

# HTTPRequestHandler class
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
 
  # GET
  def do_HEAD(self):
        # Send response status code
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()
        return
  # GET
  def do_GET(self):
        # Send response status code
        self.send_response(200)
 
        # Send headers
        self.send_header('Content-type','text/html')
        self.end_headers()
 
        # Send message back to client
        message = "Hello world!"
        # Write content as utf-8 data
        self.wfile.write(bytes(message, "utf8"))
        return
 
def run():
  print('starting server...')
 
  # Server settings
  # Choose port 8080, for port 80, which is normally used for a http server, you need root access
  server_address = ('0.0.0.0', PORT_NUMBER)
  httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
  print('running server...')
  httpd.serve_forever()
  
run()

Preparing the Application for Cloud Deployment

  1. Create the manifest.json file and add the following content:

    {
      "runtime": {
        "majorVersion": "3.6.0"
      },
      "command": "python app.py",
      },
      "notes": "Simple REST Service"
    } 
  2. Compress the manifest.json file and the app.py file together in a .zip file.

Deploying the Application to Oracle Application Container Cloud Service

In this section, you learn how to deploy your application to Oracle Container Cloud service using the service console.

  1. Log in to Oracle Cloud at http://cloud.oracle.com/. Enter the identity domain, user name, and password for your account.

  2. To open the Oracle Application Container Cloud Service console, click Instances in the Dashboard.

  3. In the Applications list view, click Create Application.

  4. Click Python.

  5. In the Application section, enter a name for your application and click Browse next to Archive.

  6. In the File Upload window, select the zip file of your application, and click Open.

  7. In the Instances section, configure the number of instances and the Gigabytes (GB) of memory for your application. Click Create.

    Create Application dialog box - Instances
    Description of this image
  8. In the confirmation dialog box click OK.

  9. Wait until the application is completely created and click the URL value.

    Your application could take a few minutes to complete the process.

    SimpleService application
    Description of this image
    SimpleService application home page
    Description of this image

What to Learn More?