├── .cfignore
├── .dockerignore
├── .gitignore
├── Dockerfile
├── Dockerfile-tools
├── LICENSE
├── Pipfile
├── README.md
├── manage.py
├── manifest.yml
├── public
├── 404.html
├── 500.html
├── index.html
├── swagger-ui
│ ├── css
│ │ ├── print.css
│ │ ├── reset.css
│ │ ├── screen.css
│ │ ├── style.css
│ │ └── typography.css
│ ├── fonts
│ │ ├── DroidSans-Bold.ttf
│ │ └── DroidSans.ttf
│ ├── images
│ │ ├── collapse.gif
│ │ ├── expand.gif
│ │ ├── explorer_icons.png
│ │ ├── favicon-16x16.png
│ │ ├── favicon-32x32.png
│ │ ├── favicon.ico
│ │ ├── logo_small.png
│ │ ├── pet_store_api.png
│ │ ├── throbber.gif
│ │ └── wordnik_api.png
│ ├── index.html
│ ├── lang
│ │ ├── ca.js
│ │ ├── el.js
│ │ ├── en.js
│ │ ├── es.js
│ │ ├── fr.js
│ │ ├── geo.js
│ │ ├── it.js
│ │ ├── ja.js
│ │ ├── ko-kr.js
│ │ ├── pl.js
│ │ ├── pt.js
│ │ ├── ru.js
│ │ ├── tr.js
│ │ ├── translator.js
│ │ └── zh-cn.js
│ ├── lib
│ │ ├── backbone-min.js
│ │ ├── es5-shim.js
│ │ ├── handlebars-4.0.5.js
│ │ ├── highlight.9.1.0.pack.js
│ │ ├── highlight.9.1.0.pack_extended.js
│ │ ├── jquery-1.8.0.min.js
│ │ ├── jquery.ba-bbq.min.js
│ │ ├── jquery.slideto.min.js
│ │ ├── jquery.wiggle.min.js
│ │ ├── js-yaml.min.js
│ │ ├── jsoneditor.min.js
│ │ ├── lodash.min.js
│ │ ├── marked.js
│ │ ├── object-assign-pollyfill.js
│ │ ├── sanitize-html.min.js
│ │ └── swagger-oauth.js
│ ├── o2c.html
│ ├── swagger-ui.js
│ └── swagger-ui.min.js
└── swagger.yaml
├── requirements.txt
├── run-dev
├── server
├── __init__.py
├── config
│ └── __init__.py
├── routes
│ ├── __init__.py
│ ├── health.py
│ ├── index.py
│ ├── prometheus.py
│ └── swagger.py
└── services
│ ├── __init__.py
│ └── service_manager.py
├── setup.py
└── tests
├── __init__.py
└── app_tests.py
/.cfignore:
--------------------------------------------------------------------------------
1 | .pyc
2 | .egg-info
--------------------------------------------------------------------------------
/.dockerignore:
--------------------------------------------------------------------------------
1 | Dockerfile
2 | Dockerfile-tools
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | .DS_Store
3 | *.pyc
4 | *.egg-info
5 | server/localdev-config.json
6 | credentials.json
7 | localdev-config.json
8 | server/localdev-config.json
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.6-alpine
2 |
3 | WORKDIR /app
4 |
5 | COPY requirements.txt /tmp/requirements.txt
6 | RUN apk --update add python py-pip openssl ca-certificates py-openssl wget bash linux-headers
7 | RUN apk --update add --virtual build-dependencies libffi-dev openssl-dev python-dev py-pip build-base \
8 | && pip install --upgrade pip \
9 | && pip install --upgrade pipenv\
10 | && pip install --upgrade -r /tmp/requirements.txt\
11 | && apk del build-dependencies
12 |
13 | COPY . /app
14 | ENV FLASK_APP=server/__init__.py
15 | CMD ["python", "manage.py", "start", "0.0.0.0:3000"]
16 |
--------------------------------------------------------------------------------
/Dockerfile-tools:
--------------------------------------------------------------------------------
1 | FROM python:3.6-alpine
2 |
3 | WORKDIR /app
4 |
5 | COPY requirements.txt /tmp/requirements.txt
6 | RUN apk --update add python py-pip openssl ca-certificates py-openssl wget bash linux-headers
7 | RUN apk --update add --virtual build-dependencies libffi-dev openssl-dev python-dev py-pip build-base \
8 | && pip install --upgrade pip \
9 | && pip install --upgrade -r /tmp/requirements.txt \
10 | && apk del build-dependencies
11 | ENV FLASK_APP=server/__init__.py
12 | ENV FLASK_DEBUG=true
13 |
14 | COPY . /app
15 | COPY run-dev /bin
16 | RUN chmod 777 /bin/run-dev
17 |
18 |
19 | ARG bx_dev_user=root
20 | ARG bx_dev_userid=1000
21 |
22 | RUN BX_DEV_USER=$bx_dev_user
23 | RUN BX_DEV_USERID=$bx_dev_userid
24 | RUN if [ "$bx_dev_user" != root ]; then adduser -D -s /bin/bash -u $bx_dev_userid $bx_dev_user; fi
25 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Pipfile:
--------------------------------------------------------------------------------
1 | [[source]]
2 |
3 | url = "https://pypi.python.org/simple"
4 | verify_ssl = true
5 | name = "pypi"
6 |
7 |
8 | [dev-packages]
9 |
10 |
11 | [packages]
12 | livereload ='*'
13 | ibmcloudenv ='~=0.0'
14 | Flask = "==0.11.1"
15 | gunicorn = "==19.7.1"
16 | prometheus-client = "*"
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WARNING: This repository is no longer maintained :warning:
2 |
3 | > Please see the replacement repositories available for [Node.js](https://github.com/IBM/node-express-app), [Go](https://github.com/IBM/go-gin-app), [Java Liberty](https://github.com/IBM/java-liberty-app), [Java Spring](https://github.com/IBM/java-spring-app), [Python Flask](https://github.com/IBM/python-flask-app), [Python Django](https://github.com/IBM/python-django-app), and [Swift](https://github.com/IBM/swift-kitura-app).
4 |
5 | > This repository will not be updated. The repository will be kept available in read-only mode.
6 |
7 |
8 |
22 |
23 |
24 | # Create and deploy a Python Flask microservice
25 |
26 | > We have similar applications available for [Go](https://github.com/IBM/go-microservice), [Java Liberty](https://github.com/IBM/java-liberty-microservice), [Spring](https://github.com/IBM/spring-microservice), and [Node](https://github.com/IBM/nodejs-microservice).
27 |
28 | In this sample application, you will create a Python microservice using Flask. A microservice is an individual component of an application that follows the **microservice architecture** - an architectural style that structures an application as a collection of loosely coupled services, which implement business capabilities. The microservice exposes a RESTful API matching a [Swagger](http://swagger.io) definition.
29 |
30 | ## Steps
31 |
32 | You can [deploy this application to IBM Cloud](https://cloud.ibm.com/developer/appservice/create-app?starterKit=0702b041-860f-39a6-8ef0-48d7528dee7d) or [build it locally](#building-locally) by cloning this repo first. Once your app is live, you can access the `/health` endpoint to quickly build out your cloud native application.
33 |
34 | ### Deploying to IBM Cloud
35 |
36 |
41 |
42 | Click **Deploy to IBM Cloud** to deploy this same application to IBM Cloud. This option creates a deployment pipeline, complete with a hosted GitLab project and a DevOps toolchain. You can deploy your app to Cloud Foundry, a Kubernetes cluster, or a Red Hat OpenShift cluster. OpenShift is available only through a standard cluster, which requires you to have a billable account.
43 |
44 | [IBM Cloud DevOps](https://www.ibm.com/cloud/devops) services provides toolchains as a set of tool integrations that support development, deployment, and operations tasks inside IBM Cloud.
45 |
46 | ### Building Locally
47 |
48 | To get started building this application locally, you can either run the application natively or use the [IBM Cloud Developer Tools](https://cloud.ibm.com/docs/cli?topic=cloud-cli-getting-started) for containerization and easy deployment to IBM Cloud.
49 |
50 | #### Native Application Development
51 |
52 | * Install [Python](https://www.python.org/downloads/)
53 |
54 | Running Flask applications has been simplified with a `manage.py` file to avoid dealing with configuring environment variables to run your app. From your project root, you can download the project dependencies with:
55 |
56 | ```bash
57 | pip install -r requirements.txt
58 | ```
59 |
60 | To run your application locally:
61 |
62 | ```bash
63 | python manage.py start
64 | ```
65 |
66 | `manage.py` offers a variety of different run commands to match the proper situation:
67 | * `start`: starts a server in a production setting using `gunicorn`.
68 | * `run`: starts a native Flask development server. This includes backend reloading upon file saves and the Werkzeug stack-trace debugger for diagnosing runtime failures in-browser.
69 | * `livereload`: starts a development server via the `livereload` package. This includes backend reloading as well as dynamic frontend browser reloading. The Werkzeug stack-trace debugger will be disabled, so this is only recommended when working on frontend development.
70 | * `debug`: starts a native Flask development server, but with the native reloader/tracer disabled. This leaves the debug port exposed to be attached to an IDE (such as PyCharm's `Attach to Local Process`).
71 |
72 | There are also a few utility commands:
73 | * `build`: compiles `.py` files within the project directory into `.pyc` files
74 | * `test`: runs all unit tests inside of the project's `test` directory
75 |
76 | Your application is running at: `http://localhost:3000/` in your browser.
77 | - Your [Swagger UI](http://swagger.io/swagger-ui/) is running on: `/explorer`
78 | - Your Swagger definition is running on: `/swagger/api`
79 | - Health endpoint: `/health`
80 |
81 | There are two different options for debugging a Flask project:
82 | 1. Run `python manage.py runserver` to start a native Flask development server. This comes with the Werkzeug stack-trace debugger, which will present runtime failure stack-traces in-browser with the ability to inspect objects at any point in the trace. For more information, see [Werkzeug documentation](http://werkzeug.pocoo.org/).
83 | 2. Run `python manage.py debug` to run a Flask development server with debug exposed, but the native debugger/reloader turned off. This grants access for an IDE to attach itself to the process (i.e. in PyCharm, use `Run` -> `Attach to Local Process`).
84 |
85 | #### IBM Cloud Developer Tools
86 |
87 | Install [IBM Cloud Developer Tools](https://cloud.ibm.com/docs/cli?topic=cloud-cli-getting-started) on your machine by running the following command:
88 | ```
89 | curl -sL https://ibm.biz/idt-installer | bash
90 | ```
91 |
92 | Create an application on IBM Cloud by running:
93 |
94 | ```bash
95 | ibmcloud dev create
96 | ```
97 |
98 | This will create and download a starter application with the necessary files needed for local development and deployment.
99 |
100 | Your application will be compiled with Docker containers. To compile and run your app, run:
101 |
102 | ```bash
103 | ibmcloud dev build
104 | ibmcloud dev run
105 | ```
106 |
107 | This will launch your application locally. When you are ready to deploy to IBM Cloud on Cloud Foundry or Kubernetes, run one of the commands:
108 |
109 | ```bash
110 | ibmcloud dev deploy -t buildpack // to Cloud Foundry
111 | ibmcloud dev deploy -t container // to K8s cluster
112 | ```
113 |
114 | You can build and debug your app locally with:
115 |
116 | ```bash
117 | ibmcloud dev build --debug
118 | ibmcloud dev debug
119 | ```
120 |
121 | ## Next Steps
122 | * Learn more about the services and capabilities of [IBM Cloud](https://cloud.ibm.com).
123 | * Explore other [sample applications](https://cloud.ibm.com/developer/appservice/starter-kits) on IBM Cloud.
124 |
125 | ## License
126 |
127 | This sample application 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](https://developercertificate.org/) and the [Apache License, Version 2](https://www.apache.org/licenses/LICENSE-2.0.txt).
128 |
129 | [Apache License FAQ](https://www.apache.org/foundation/license-faq.html#WhatDoesItMEAN)
130 |
131 |
--------------------------------------------------------------------------------
/manage.py:
--------------------------------------------------------------------------------
1 | import os, sys, argparse, subprocess, signal
2 |
3 | # Project defaults
4 | FLASK_APP = 'server/__init__.py'
5 | DEFAULT_IP = '0.0.0.0:3000'
6 |
7 | class Command:
8 | def __init__(self, name, descr, runcmd, env={}):
9 | self.name = name
10 | self.descr = descr
11 | self.runcmd = runcmd
12 | self.env = env
13 |
14 | def run(self, conf):
15 | cmd = self.runcmd(conf)
16 | env = os.environ
17 | env.update(conf)
18 | env.update(self.env)
19 | subprocess.call(cmd, env=env, shell=True)
20 |
21 | class CommandManager:
22 | def __init__(self):
23 | self.commands = {}
24 |
25 | def add(self, command):
26 | self.commands[command.name] = command
27 |
28 | def configure(self, conf):
29 | self.conf = conf
30 |
31 | def run(self, command):
32 | if command in self.commands:
33 | self.commands[command].run(self.conf)
34 | else:
35 | print("invalid command specified\n")
36 | print(self.availableCommands())
37 |
38 | def availableCommands(self):
39 | commands = sorted(self.commands.values(), key=lambda c: c.name)
40 | space = max([len(c.name) for c in commands]) + 2
41 | description = 'available subcommands:\n'
42 | for c in commands:
43 | description += ' ' + c.name + ' ' * (space - len(c.name)) + c.descr + '\n'
44 | return description
45 |
46 | cm = CommandManager()
47 |
48 | cm.add(Command(
49 | "build",
50 | "compiles python files in project into .pyc binaries",
51 | lambda c: 'python -m compileall .'))
52 |
53 | cm.add(Command(
54 | "start",
55 | "runs server with gunicorn in a production setting",
56 | lambda c: 'gunicorn -b {0}:{1} server:app'.format(c['host'], c['port']),
57 | {
58 | 'FLASK_APP': FLASK_APP,
59 | 'FLASK_DEBUG': 'false'
60 | }))
61 |
62 | cm.add(Command(
63 | "run",
64 | "runs dev server using Flask's native debugger & backend reloader",
65 | lambda c: 'python -m flask run --host={0} --port={1} --debugger --reload'.format(c['host'], c['port']),
66 | {
67 | 'FLASK_APP': FLASK_APP,
68 | 'FLASK_DEBUG': 'true'
69 | }))
70 |
71 | cm.add(Command(
72 | "livereload",
73 | "runs dev server using livereload for dynamic webpage reloading",
74 | lambda c: 'python -m flask run',
75 | {
76 | 'FLASK_APP': FLASK_APP,
77 | 'FLASK_LIVE_RELOAD': 'true',
78 | }))
79 |
80 | cm.add(Command(
81 | "debug",
82 | "runs dev server in debug mode; use with an IDE's remote debugger",
83 | lambda c: 'python -m flask run --host={0} --port={1} --no-debugger --no-reload'.format(c['host'], c['port']),
84 | {
85 | 'FLASK_APP': FLASK_APP,
86 | 'FLASK_DEBUG': 'true'
87 | }))
88 |
89 | cm.add(Command(
90 | "test",
91 | "runs all tests inside of `tests` directory",
92 | lambda c: 'python -m unittest discover -s tests -p "*.py"'))
93 |
94 | # Create and format argument parser for CLI
95 | parser = argparse.ArgumentParser(description=cm.availableCommands(),
96 | formatter_class=argparse.RawDescriptionHelpFormatter)
97 | parser.add_argument("subcommand", help="subcommand to run (see list above)")
98 | parser.add_argument("ipaddress", nargs='?', default=DEFAULT_IP,
99 | help="address and port to run on (i.e. {0})".format(DEFAULT_IP))
100 | def livereload_check():
101 | check = subprocess.call("lsof -n -i4TCP:3000", shell=True)
102 | if (check == 0):
103 | output = subprocess.check_output("pgrep Python", shell=True)
104 | pypid = int(output)
105 | os.kill(pypid, signal.SIGKILL)
106 | print("Discovered rogue Python process: {0}".format(pypid))
107 | print("Killing PID {0}...".format(pypid))
108 | else:
109 | print(" No rogue Python process running")
110 |
111 | # Take in command line input for configuration
112 | try:
113 | args = parser.parse_args()
114 | cmd = args.subcommand
115 | addr = args.ipaddress.split(':')
116 | cm.configure({
117 | 'host': addr[0],
118 | 'port': addr[1],
119 | })
120 | cm.run(cmd)
121 | except KeyboardInterrupt:
122 | if 'FLASK_LIVE_RELOAD' in os.environ and os.environ['FLASK_LIVE_RELOAD'] == 'true':
123 | livereload_check()
124 | except:
125 | if len(sys.argv) == 1:
126 | print(cm.availableCommands())
127 | sys.exit(0)
128 |
--------------------------------------------------------------------------------
/manifest.yml:
--------------------------------------------------------------------------------
1 | ---
2 | applications:
3 | - instances: 1
4 | timeout: 180
5 | name: flaskmicroservice
6 | buildpack: python_buildpack
7 | command: python manage.py start 0.0.0.0:$PORT
8 | memory: 512M
9 | domain: not-used.net
10 | host: not-used
11 | env:
12 | FLASK_APP : server
13 | FLASK_DEBUG : false
14 |
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | IBM Cloud Web Starter
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
404!
14 |
Whoops! Looks like you got lost or couldn't find your page.