Skip to content

Commit 1de0044

Browse files
committed
Basic Flask app with RPM creation using PKG Deploy
0 parents  commit 1de0044

16 files changed

Lines changed: 324 additions & 0 deletions

.gitignore

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# PKG Deploy
2+
.vagrant/
3+
4+
### OSX ###
5+
.DS_Store
6+
.AppleDouble
7+
.LSOverride
8+
9+
# Icon must end with two \r
10+
Icon
11+
12+
# Thumbnails
13+
._*
14+
15+
# Files that might appear on external disk
16+
.Spotlight-V100
17+
.Trashes
18+
19+
# Directories potentially created on remote AFP share
20+
.AppleDB
21+
.AppleDesktop
22+
Network Trash Folder
23+
Temporary Items
24+
.apdisk
25+
26+
# Editors
27+
.vscode/
28+
29+
### Python ###
30+
# Byte-compiled / optimized / DLL files
31+
__pycache__/
32+
*.py[cod]
33+
34+
# C extensions
35+
*.so
36+
37+
# Distribution / packaging
38+
.Python
39+
venv/
40+
env/
41+
develop-eggs/
42+
dist/
43+
downloads/
44+
eggs/
45+
lib/
46+
lib64/
47+
parts/
48+
sdist/
49+
var/
50+
*.egg-info/
51+
.installed.cfg
52+
*.egg
53+
54+
# PyInstaller
55+
# Usually these files are written by a python script from a template
56+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
57+
*.manifest
58+
#*.spec
59+
60+
# Installer logs
61+
pip-log.txt
62+
pip-delete-this-directory.txt
63+
64+
# Unit test / coverage reports
65+
htmlcov/
66+
.tox/
67+
.coverage
68+
.cache
69+
nosetests.xml
70+
coverage.xml
71+
.testmondata
72+
73+
# Translations
74+
*.mo
75+
*.pot
76+
77+
# Sphinx documentation
78+
docs/_build/
79+
80+
# PyBuilder
81+
target/
82+
83+
84+
### Django ###
85+
*.log
86+
*.pot
87+
*.pyc
88+
__pycache__/
89+
local_settings.py
90+
91+
# Local dev
92+
.env
93+
.localenv
94+
*.sqlite3

.pkgdeploy/config_centos7.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: pkgdeploy-flaskapp
2+
format: rpm
3+
distribution: centos7
4+
architecture: 64-bit
5+
description: A simple flask project to show how PKG Deploy works
6+
url: https://www.pkgdeploy.com
7+
license: GPLv3
8+
maintainer: PKG Deploy Devs <devs@pkgdeploy.com>
9+
10+
build:
11+
directory: /opt/pkgdeploy/flaskapp/
12+
requires:
13+
- python36-pip
14+
commands: |
15+
python3.6 -m venv ./venv/
16+
./venv/bin/pip install -r requirements.txt
17+
18+
install:
19+
requires:
20+
- python36
21+
- nginx
22+
user: pkgdeploy
23+
group: pkgdeploy
24+
copy:
25+
- source: ./
26+
destination: /opt/pkgdeploy/flaskapp/
27+
user: pkgdeploy
28+
group: pkgdeploy
29+
permissions: 755
30+
- source: nginx.conf
31+
destination: /etc/nginx/conf.d/flaskapp.conf
32+
- source: flaskapp.service
33+
destination: /etc/systemd/system/flaskapp.service
34+
35+
after_install: |
36+
# Configure Nginx
37+
rm -f /etc/nginx/conf.d/default.conf
38+
sed -i '/listen 80 default_server/d' /etc/nginx/nginx.conf
39+
systemctl enable --now nginx
40+
nginx -s reload
41+
# Start app
42+
systemctl enable --now flaskapp
43+
44+
after_upgrade:
45+
- file: .pkgdeploy/upgrade_commands.sh

.pkgdeploy/config_ubuntu.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: pkgdeploy-flaskapp
2+
format: deb
3+
distribution: ubuntu18
4+
architecture: 64-bit
5+
description: A simple flask project to show how PKG Deploy works
6+
url: https://www.pkgdeploy.com
7+
license: GPLv3
8+
maintainer: PKG Deploy Devs <devs@pkgdeploy.com>
9+
10+
build:
11+
directory: /opt/pkgdeploy/flaskapp/
12+
requires:
13+
- python3-pip
14+
- python3-venv
15+
commands: |
16+
python3 -m venv ./venv/
17+
./venv/bin/pip install -r requirements.txt
18+
19+
install:
20+
requires:
21+
- python3
22+
- nginx
23+
user: pkgdeploy
24+
group: pkgdeploy
25+
copy:
26+
- source: ./
27+
destination: /opt/pkgdeploy/flaskapp/
28+
user: pkgdeploy
29+
group: pkgdeploy
30+
permissions: 755
31+
- source: nginx.conf
32+
destination: /etc/nginx/conf.d/flaskapp.conf
33+
- source: flaskapp.service
34+
destination: /etc/systemd/system/flaskapp.service
35+
36+
after_install: |
37+
unlink /etc/nginx/sites-enabled/default
38+
systemctl enable --now nginx
39+
nginx -s reload
40+
systemctl enable --now flaskapp
41+
42+
after_upgrade:
43+
- file: .pkgdeploy/upgrade_commands.sh

.pkgdeploy/upgrade_commands.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nginx -s reload
2+
systemctl daemon-reload
3+
systemctl restart flaskapp

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Flask example for PKG Deploy
2+
3+
4+
RPM builds with:
5+
* Python3.6 / pip
6+
* Flask
7+
* Gunicorn
8+
* Nginx
9+
* Systemd
10+
11+
12+
_Note: This is just an example. The settings, requirements, layout etc are
13+
not done using best practices and are not production ready._
14+
15+
16+
## Local setup
17+
```
18+
python3.6 -m venv ./venv
19+
source ./venv/bin/activate
20+
pip install -r requirements.txt
21+
22+
FLASK_APP=app.py flask run --host 0.0.0.0:5000
23+
```

flaskapp.service

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=Basic flask app to show off PKG Deploy
3+
After=network.target
4+
5+
[Service]
6+
User=pkgdeploy
7+
Group=pkgdeploy
8+
WorkingDirectory=/opt/pkgdeploy/flaskapp
9+
Environment="PATH=/opt/pkgdeploy/flaskapp/venv/bin"
10+
ExecStart=/opt/pkgdeploy/flaskapp/venv/bin/gunicorn --bind unix:flaskapp.sock --workers 4 flaskapp.wsgi:app
11+
Restart=always
12+
13+
[Install]
14+
WantedBy=multi-user.target

flaskapp/__init__.py

Whitespace-only changes.

flaskapp/app.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from flask import Flask, render_template
2+
3+
app = Flask(__name__)
4+
5+
6+
@app.route('/')
7+
def index():
8+
return render_template('index.html')
9+
10+
11+
@app.route('/test/')
12+
def test():
13+
return 'Test'
14+
15+
16+
@app.route('/test/<some_var>')
17+
def test_var(some_var):
18+
return f'Test {some_var}'
19+
20+
21+
@app.route('/healthcheck')
22+
def healthcheck():
23+
return 'OK'
24+
25+
26+
if __name__ == '__main__':
27+
app.run(host='0.0.0.0')

flaskapp/static/css/style.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
body {
2+
margin: 50px;
3+
font: 11px sans-serif;
4+
display: flex;
5+
justify-content: center;
6+
}
7+
8+
#wrapper {
9+
display: flex;
10+
flex-direction: column;
11+
}
12+
13+
header {
14+
text-align: center;
15+
}
16+
17+
#logo {
18+
width: 150px;
19+
}
20+
21+
main {
22+
display: flex;
23+
justify-content: center;
24+
}

flaskapp/static/img/favicon.ico

14.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)