Skip to content

Commit e1f1d72

Browse files
committedDec 12, 2022
🔄 Synced file(s) with devstream-io/devstream
1 parent de18999 commit e1f1d72

11 files changed

+122
-1
lines changed
 

‎.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.venv/
2+
3+
*.pyc
4+
__pycache__/
5+
6+
instance/
7+
8+
.pytest_cache/
9+
.coverage
10+
htmlcov/
11+
12+
dist/
13+
build/
14+
*.egg-info/

‎Dockerfile.tpl

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM python:3.10-alpine
2+
3+
WORKDIR /code
4+
5+
COPY ./requirements.txt /code/requirements.txt
6+
7+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8+
9+
COPY ./wsgi.py /code/
10+
COPY ./app /code/app
11+
12+
USER 1000
13+
14+
CMD ["gunicorn", "--conf", "app/gunicorn.conf.py", "--bind", "0.0.0.0:8080", "wsgi:app"]

‎README.md

+35-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
# dtm-repo-scaffolding-python-flask
1+
# dtm-repo-scaffolding-python-flask
2+
3+
This repo contains templates used by DevStream plugin "repo-scaffolding" (thereafter: the plugin).
4+
5+
This repo isn't intended to be used directly without DevStream. It should only be consumed by the plugin automatically.
6+
7+
The plugin (together with this repo of templates) can create a repo in GitHub and set up the project layout and initialize the reop with necessary files that are typical for a Go web app. The followings can be created automatically:
8+
9+
- a Python web app example using the Flask framework
10+
- directory structure, following Flask/Python best practice
11+
- `.gitignore`, suggested by Flask
12+
- Dockerfile with Python alpline
13+
- a simplified Helm chart with Deployment and Service
14+
15+
## Usage
16+
17+
- Render all files using go template whose name end with `.tpl` suffix.
18+
- Files whose name don't end with `.tpl` extension don't need to be rendered.
19+
- subdirectory "helm/**_app_name_**" (the **_app_name_** part) should be rendered with `AppName`
20+
- subdicrectory "cmd/**_app_name_**" (the **_app_name_** part) should be rendered with `AppName`
21+
22+
Example of required parameters to render these templates:
23+
24+
```yaml
25+
AppName: hello
26+
Repo:
27+
Owner: ironcore864
28+
Name: hello
29+
imageRepo: ironcore864/hello # dockerhub
30+
```
31+
32+
## Where does this repo come from?
33+
34+
`dtm-repo-scaffolding-python-flask` is synced from https://github.com/devstream-io/devstream/blob/main/staging/dtm-repo-scaffolding-python-flask.
35+
Code changes are made in that location, merged into `devstream-io/devstream` and later synced here.

‎README.md.tpl

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# [[.AppName]]
2+
3+
This is a repo for app [[.AppName]]; bootstrapped by DevStream.
4+
5+
By default, the automatically generated scaffolding contains:
6+
7+
- a piece of sample Python [Flask](https://flask.palletsprojects.com/en/2.2.0/) web app
8+
- sample unittest
9+
- .gitignore
10+
- requirements.txt
11+
- wsgi.py
12+
- Dockerfile
13+
- Helm chart
14+
15+
## Test
16+
17+
```shell
18+
python3 -m unittest
19+
```

‎app/_app_name_.py.tpl

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from flask import Flask
2+
3+
app = Flask(__name__)
4+
5+
6+
@app.route("/")
7+
def hello():
8+
return "Hello, World!"
9+
10+
11+
if __name__ == "__main__":
12+
app.run(host='0.0.0.0')

‎app/gunicorn.conf.py.tpl

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Gunicorn config variables
2+
loglevel = "info"
3+
errorlog = "-" # stderr
4+
accesslog = "-" # stdout
5+
worker_tmp_dir = "/dev/shm"
6+
graceful_timeout = 120
7+
timeout = 120
8+
keepalive = 5
9+
threads = 3

‎requirements.txt.tpl

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Flask==2.2.0
2+
gunicorn==20.1.0

‎test/__init__.py

Whitespace-only changes.

‎test/__init__.py.tpl

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

‎test/test__app_name_.py.tpl

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
3+
from app.[[.AppName]] import hello
4+
5+
6+
class TestHello(unittest.TestCase):
7+
def test_hello(self):
8+
self.assertEqual(hello(), "Hello, World!")
9+
10+
11+
if __name__ == '__main__':
12+
unittest.main()

‎wsgi.py.tpl

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from app.[[.AppName]] import app
2+
3+
if __name__ == "__main__":
4+
app.run()

0 commit comments

Comments
 (0)
Please sign in to comment.