Coder Social home page Coder Social logo

prr101-1480960048028's Introduction

#Sample Bluemix Python Web application

The sample is using Flask microframework and is intented to test the Python support on IBM's Bluemix environment which is based on Cloud Foundry.

IBM Bluemix contains the Python buildpack from Cloud Foundry and so will be auto-detected as long as a requirements.txt or a setup.py is located in the root of your application.

If you just wish to automatically deploy this sample to Bluemix then just click the 'Deploy to Bluemix' button and see this sample deployed into your space.

Deploy to Bluemix

Alternatively follow the steps below to get the sample code and see how to deploy manually.

##Get this sample From a terminal navigate to a location where you want this application code to be downloaded to and issue:

git clone https://github.com/IBM-Bluemix/bluemix-python-flask-sample

or download the zip file containing this sample code.

##Deploy to Bluemix manually From a terminal login into Bluemix and set the api endpoint to the Bluemix region you wish to deploy to:

cf login -a api.ng.bluemix.net

or for the UK region:

cf login -a api.eu-gb.bluemix.net

The login will ask you for you email(username) and password, plus the organisation and space if there is more than one to choose from.

From the root directory of the application code execute the following to deploy the application to Bluemix. (By default the route (application URL) will be based on your application name so make sure your application name is unique or use the -n option on the cf push command to define your hostname)

cf push <YOUR_APP_NAME> -m 128M 

to deploy when you don't have a requirements.txt or setup.py then use:

cf push <YOUR_APP_NAME> -m 128M -b https://github.com/cloudfoundry/python-buildpack

to deploy with a different hostname to the app name:

cf push <YOUR_APP_NAME> -m 128M -n <YOUR_HOST_NAME>

##View App Once the application is deployed and started open a web browser and point to the application route defined at the end of the cf push command i.e. http://bluemix-python-flask-sample.eu-gb.mybluemix.net/. This will execute the code under the / app route defined in the welcome.py file. Navigate to http://bluemix-python-flask-sample.eu-gb.mybluemix.net/myapp to see the other /myapp route.

##Structure of application Procfile - Contains the command to run when you application starts on Bluemix. It is represented in the form web: <command> where <command> in this sample case is to run the py command and passing in the the welcome.py script.

requirements.txt - Contains the external python packages that are required by the application. These will be downloaded from the python package index and installed via the python package installer (pip) during the buildpack's compile stage when you execute the cf push command. In this sample case we wish to download the Flask package at version 0.10.1

runtime.txt - Controls which python runtime to use. In this case we want to use 2.7.9.

README.md - this readme.

welcome.py - the python application script. This is implemented as a simple Flask application. The routes are defined in the application using the @app.route() calls. This application has a / route and a /myapp route defined. The application deployed to Bluemix needs to listen to the port defined by the VCAP_APP_PORT environment variable as seen here:

port = os.getenv('VCAP_APP_PORT', '5000')
if __name__ == "__main__":
    app.run(host='0.0.0.0', port=int(port))

This is the port given to your application so that http requests can be routed to it. If the property is not defined then it falls back to port 5000 allowing you to run this sample appliction locally.

prr101-1480960048028's People

Contributors

lgolender avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.