Skip to content

Setup a Python-Flask server with the project structure ready to be deployed on IBM Cloud

Notifications You must be signed in to change notification settings

manojjahgirdar/Automated-Flask-Server-Setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Automated Flask Server Setup

About

A simple shell script that will setup a Python-Flask server project structure, which can be readily deployed on IBM Cloud.

Steps

Step 1: Clone the Repo

  • In terminal, run the following command to clone the repo.
git clone https://github.com/manojjahgirdar/Automated-Flask-Server-Setup

Step 2: Run the shell script

Make sure you have python 3.x installed before proceeding.

  • Give the executable permission to the shellscript, Open terminal in cloned repo and run the following command.
chmod +x ./init-python-flask-project.sh
  • The init-python-flask-project.sh takes one parameter <project-name> where <project-name> is the project that you want to create.

    • init-python-flask-project.sh <project-name>
  • Create a Python-Flask server with the project structure which is ready to be deployed on IBM Cloud by running the following command in the terminal.

./init-python-flask-project.sh <project-name>

terminal-screenshot

  • The Script will automatically open Visual Studio Code for you to start coding right away! It will also create a python3 virtual environment, install requirements and run the flask server ready listening on 8080.

  • The following files will be created in the directory with <project-name>

<project-name>
├── Procfile
├── app.py
├── dockerfile
├── manifest.yml
├── requirements.txt
├── runtime.txt
├── static
│   ├── carbon-components
│   │   └── . . .
│   ├── carbon-icons
│   │   └── . . .
│   ├── css
│   │   └── style.css
│   └── javascript
│       └── script.js
└── templates
    └── index.html

UI

  • The project can be deployed on IBM Cloud by following the simple steps.

Step 3: Deploy on IBM Cloud (optional)

  • Before you proceed, make sure you have installed IBM Cloud CLI in your deployment machine.

  • Open the project directory in terminal, and run the following commands to deploy the Application to IBM Cloud Foundry.

  • Log in to your IBM Cloud account, and select an API endpoint.
$ ibmcloud login

NOTE: If you have a federated user ID, instead use the following command to log in with your single sign-on ID.

$ ibmcloud login --sso
  • Target a Cloud Foundry org and space:
$ ibmcloud target --cf
  • From within the project directory push your app to IBM Cloud.
$ ibmcloud cf push
  • The manifest.yml file will be used here to deploy the application to IBM Cloud Foundry.

  • On Successful deployment of the application you will see something similar on your terminal as shown.

Invoking 'cf push'...

Pushing from manifest to org manoj.jahgirdar@in.ibm.com / space dev as manoj.jahgirdar@in.ibm.com...

...

Waiting for app to start...

name:              Flask-App
requested state:   started
routes:            Flask-App.xx-xx.mybluemix.net 
last uploaded:     Sat 16 May 18:05:16 IST 2020
stack:             cflinuxfs3
buildpacks:        python

type:            web
instances:       1/1
memory usage:    256M
start command:   python app.py
     state     since                  cpu     memory           disk           details
#0   running   2020-05-16T12:36:15Z   25.6%   116.5M of 256M   796.2M of 1
  • Once the app is deployed you can visit the routes to launch the application.

License

This code pattern is licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 and the Apache License, Version 2.

Apache License FAQ

About

Setup a Python-Flask server with the project structure ready to be deployed on IBM Cloud

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published