Skip to content

Commit e50e95b

Browse files
committed
Add Gunicorn configuration.
1 parent d04157d commit e50e95b

File tree

11 files changed

+350
-301
lines changed

11 files changed

+350
-301
lines changed

Diff for: Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,32 @@ all help:
2424

2525
env: $(VIRTUAL_ENV)
2626

27+
2728
$(VIRTUAL_ENV):
2829
if [ ! -d $(VIRTUAL_ENV) ]; then \
2930
echo "Creating Python virtual env in \`${VIRTUAL_ENV}\`"; \
3031
python3 -m venv $(VIRTUAL_ENV); \
3132
fi
3233

34+
3335
.PHONY: run
3436
run: env
3537
$(LOCAL_PYTHON) -m gunicorn -w 4 wsgi:app
3638

39+
3740
.PHONY: install
3841
install: env
3942
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
4043
$(LOCAL_PYTHON) -m pip install -r requirements.txt && \
4144
echo Installed dependencies in \`${VIRTUAL_ENV}\`;
4245

46+
4347
.PHONY: deploy
4448
deploy:
4549
make install && \
4650
make run
4751

52+
4853
.PHONY: test
4954
test: env
5055
$(LOCAL_PYTHON) -m \
@@ -53,18 +58,21 @@ test: env
5358
coverage html --title='Coverage Report' -d .reports && \
5459
open .reports/index.html
5560

61+
5662
.PHONY: update
5763
update: env
5864
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
5965
poetry update && \
6066
poetry export -f requirements.txt --output requirements.txt --without-hashes && \
6167
echo Installed dependencies in \`${VIRTUAL_ENV}\`;
6268

69+
6370
.PHONY: format
6471
format: env
6572
$(LOCAL_PYTHON) -m isort --multi-line=3 . && \
6673
$(LOCAL_PYTHON) -m black .
6774

75+
6876
.PHONY: lint
6977
lint: env
7078
$(LOCAL_PYTHON) -m flake8 . --count \
@@ -73,6 +81,7 @@ lint: env
7381
--show-source \
7482
--statistics
7583

84+
7685
.PHONY: clean
7786
clean:
7887
find . -name '.coverage' -delete && \

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Flask-SQLAlchemy Tutorial
22

33
![Python](https://img.shields.io/badge/Python-v^3.10-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
4-
![Flask](https://img.shields.io/badge/Flask-v2.3.3-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
4+
![Flask](https://img.shields.io/badge/Flask-v3.0.3-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
55
![Flask-SQLAlchemy](https://img.shields.io/badge/Flask--SQLAlchemy-3.1.1-red.svg?longCache=true&style=flat-square&logo=flask&logoColor=white&colorA=4c566a&colorB=5e81ac)
66
![GitHub Last Commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c)
77
[![GitHub Issues](https://img.shields.io/github/issues/hackersandslackers/flask-sqlalchemy-tutorial.svg?style=flat-square&colorA=4c566a&colorB=ebcb8b&logo=Github)](https://github.com/hackersandslackers/flask-sqlalchemy-tutorial/issues)
@@ -11,7 +11,7 @@
1111
![Flask-SQLAlchemy Tutorial](https://github.com/hackersandslackers/flask-sqlalchemy-tutorial/blob/master/.github/[email protected]?raw=true)
1212

1313
Connect your Flask app to a database using Flask-SQLAlchemy.
14-
14+
1515
* **Tutorial**: [https://hackersandslackers.com/manage-database-models-with-flask-sqlalchemy/](https://hackersandslackers.com/manage-database-models-with-flask-sqlalchemy/)
1616
* **Demo**: [https://flasksqlalchemy.hackersandslackers.com](https://flasksqlalchemy.hackersandslackers.com)
1717

Diff for: config.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Flask configuration variables."""
2+
23
from os import environ, path
34

45
from dotenv import load_dotenv

Diff for: flask_sqlalchemy_tutorial/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Initialize Flask app."""
2+
23
from flask import Flask
34
from flask_sqlalchemy import SQLAlchemy
45

Diff for: flask_sqlalchemy_tutorial/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Database models."""
2+
23
from . import db
34

45

Diff for: flask_sqlalchemy_tutorial/routes.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Application routes."""
2+
23
from datetime import datetime
34

45
from flask import current_app as app

Diff for: gunicorn.conf.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Gunicorn configuration file."""
2+
3+
from os import environ, path
4+
5+
from dotenv import load_dotenv
6+
7+
# Read environment variables from ".env" file.
8+
basedir = path.abspath(path.dirname(__file__))
9+
load_dotenv(path.join(basedir, ".env"))
10+
11+
# Fetch deployment environment from environment variables.
12+
ENVIRONMENT = environ.get("ENVIRONMENT")
13+
14+
proc_name = "flasksession"
15+
wsgi_app = "wsgi:app"
16+
bind = "unix:flask.sock"
17+
threads = 4
18+
workers = 2
19+
20+
if ENVIRONMENT == "development" or ENVIRONMENT is None:
21+
reload = True
22+
workers = 1
23+
threads = 1
24+
bind = ["127.0.0.1:8000"]
25+
elif ENVIRONMENT == "production":
26+
daemon = True
27+
accesslog = "/var/log/flasksession/access.log"
28+
errorlog = "/var/log/flasksession/error.log"
29+
loglevel = "trace"
30+
dogstatsd_tags = "env:prod,service:flasksession,language:python"
31+
else:
32+
raise ValueError(f"Unknown environment provided: `{ENVIRONMENT}`. Must be `development` or `production`.")

Diff for: poetry.lock

+280-279
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pyproject.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mypy = "*"
2424
gunicorn = "^21.2.0"
2525

2626
[tool.poetry.scripts]
27-
run = "main:app"
27+
run = "wsgi:app"
2828

2929
[tool.poetry.urls]
3030
issues = "https://github.com/hackersandslackers/flask-sqlalchemy-tutorial/issues"
@@ -36,7 +36,9 @@ build-backend = "poetry.masonry.api"
3636
[tool.black]
3737
line-length = 120
3838
target-version = ['py310']
39-
src_paths = ["flask_sqlalchemy_tutorial", "config", "main"]
39+
40+
[tool.isort]
41+
profile = "black"
4042

4143
[tool.pylint.'MESSAGES CONTROL']
4244
disable = "C0103,C0301,W0703,W0621"

Diff for: requirements.txt

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
black==23.9.1 ; python_version >= "3.10" and python_version < "4.0"
2-
blinker==1.6.2 ; python_version >= "3.10" and python_version < "4.0"
1+
black==24.4.0 ; python_version >= "3.10" and python_version < "4.0"
2+
blinker==1.7.0 ; python_version >= "3.10" and python_version < "4.0"
33
click==8.1.7 ; python_version >= "3.10" and python_version < "4.0"
44
colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and (sys_platform == "win32" or platform_system == "Windows")
5-
exceptiongroup==1.1.3 ; python_version >= "3.10" and python_version < "3.11"
5+
exceptiongroup==1.2.0 ; python_version >= "3.10" and python_version < "3.11"
66
flask-sqlalchemy==3.1.1 ; python_version >= "3.10" and python_version < "4.0"
7-
flask==2.3.3 ; python_version >= "3.10" and python_version < "4.0"
8-
greenlet==2.0.2 ; python_version >= "3.10" and python_version < "4.0" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32")
7+
flask==3.0.3 ; python_version >= "3.10" and python_version < "4.0"
8+
greenlet==3.0.3 ; python_version >= "3.10" and python_version < "4.0" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32")
99
gunicorn==21.2.0 ; python_version >= "3.10" and python_version < "4.0"
1010
iniconfig==2.0.0 ; python_version >= "3.10" and python_version < "4.0"
11-
isort==5.12.0 ; python_version >= "3.10" and python_version < "4.0"
11+
isort==5.13.2 ; python_version >= "3.10" and python_version < "4.0"
1212
itsdangerous==2.1.2 ; python_version >= "3.10" and python_version < "4.0"
13-
jinja2==3.1.2 ; python_version >= "3.10" and python_version < "4.0"
14-
markupsafe==2.1.3 ; python_version >= "3.10" and python_version < "4.0"
13+
jinja2==3.1.3 ; python_version >= "3.10" and python_version < "4.0"
14+
markupsafe==2.1.5 ; python_version >= "3.10" and python_version < "4.0"
1515
mypy-extensions==1.0.0 ; python_version >= "3.10" and python_version < "4.0"
16-
mypy==1.5.1 ; python_version >= "3.10" and python_version < "4.0"
17-
packaging==23.1 ; python_version >= "3.10" and python_version < "4.0"
18-
pathspec==0.11.2 ; python_version >= "3.10" and python_version < "4.0"
19-
platformdirs==3.10.0 ; python_version >= "3.10" and python_version < "4.0"
20-
pluggy==1.3.0 ; python_version >= "3.10" and python_version < "4.0"
16+
mypy==1.9.0 ; python_version >= "3.10" and python_version < "4.0"
17+
packaging==24.0 ; python_version >= "3.10" and python_version < "4.0"
18+
pathspec==0.12.1 ; python_version >= "3.10" and python_version < "4.0"
19+
platformdirs==4.2.0 ; python_version >= "3.10" and python_version < "4.0"
20+
pluggy==1.4.0 ; python_version >= "3.10" and python_version < "4.0"
2121
pymysql==1.1.0 ; python_version >= "3.10" and python_version < "4.0"
22-
pytest==7.4.2 ; python_version >= "3.10" and python_version < "4.0"
23-
python-dotenv==1.0.0 ; python_version >= "3.10" and python_version < "4.0"
24-
sqlalchemy==2.0.20 ; python_version >= "3.10" and python_version < "4.0"
22+
pytest==8.1.1 ; python_version >= "3.10" and python_version < "4.0"
23+
python-dotenv==1.0.1 ; python_version >= "3.10" and python_version < "4.0"
24+
sqlalchemy==2.0.29 ; python_version >= "3.10" and python_version < "4.0"
2525
tomli==2.0.1 ; python_version >= "3.10" and python_version < "3.11"
26-
typing-extensions==4.8.0 ; python_version >= "3.10" and python_version < "4.0"
27-
werkzeug==2.3.7 ; python_version >= "3.10" and python_version < "4.0"
26+
typing-extensions==4.11.0 ; python_version >= "3.10" and python_version < "4.0"
27+
werkzeug==3.0.2 ; python_version >= "3.10" and python_version < "4.0"

Diff for: wsgi.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""App entry point."""
2+
23
from flask_sqlalchemy_tutorial import create_app
34

45
app = create_app()

0 commit comments

Comments
 (0)