A simple shell script that will setup a Python-Flask server project structure, which can be readily deployed on IBM Cloud.
- In terminal, run the following command to clone the repo.
git clone https://github.com/manojjahgirdar/Automated-Flask-Server-Setup
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>
-
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
- Visit http://localhost:8080 on your browser to view the application.
- The project can be deployed on IBM Cloud by following the simple steps.
-
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.
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.