Skip to content

Commit cab7d09

Browse files
committed
Organize
1 parent a1a0d68 commit cab7d09

File tree

12 files changed

+783
-0
lines changed

12 files changed

+783
-0
lines changed

.flake8

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
max-line-length = 100
3+
# mccabe
4+
max-complexity = 10
5+
ignore =
6+
# E203 # whitespace before :

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM python:3.7-slim-buster
2+
3+
ENV PYTHONIOENCODING UTF-8
4+
ENV LC_ALL C.UTF-8
5+
ENV LANG C.UTF-8
6+
7+
RUN apt-get update && \
8+
apt-get install -y \
9+
make \
10+
curl
11+
12+
COPY . /app
13+
14+
WORKDIR /app
15+
16+
# update to avoid 'setup.py' not found error
17+
# RUN pip3 install -U pip
18+
RUN pip3 install .
19+
20+
RUN rm -rf /var/lib/apt/lists/*
21+
22+
CMD [ "make", "launch" ]

Makefile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
##### docker
3+
IMAGE_NAME := python-api-template
4+
CONTAINER_NAME := ${IMAGE_NAME}-container
5+
SRC_PORT := 4600
6+
DST_PORT := 9876
7+
8+
build-image:
9+
docker build -t ${IMAGE_NAME} ./
10+
11+
run-container:
12+
docker run -it -d \
13+
--name ${CONTAINER_NAME} \
14+
-p ${SRC_PORT}:${DST_PORT} \
15+
${IMAGE_NAME}
16+
17+
##### ci
18+
ci: typecheck test lint
19+
20+
typecheck:
21+
@echo check types
22+
mypy ./ \
23+
--disallow-untyped-defs \
24+
--disallow-any-expr \
25+
--no-implicit-optional \
26+
--no-site-packages \
27+
28+
lint:
29+
@echo check style
30+
flake8 --show-source --statistics
31+
32+
test:
33+
@echo testing
34+
pytest -rf --cov=./
35+
36+
37+
##### application
38+
GUNICORN_CONFIG_PATH := config/gunicorn.py
39+
40+
install:
41+
poetry install
42+
43+
launch:
44+
gunicorn app:app -c ${GUNICORN_CONFIG_PATH}
45+
46+
launch-develop:
47+
python app.py

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# python-api-template

app.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
import os
3+
4+
from python_api_template.controller import create_app
5+
6+
7+
app = create_app()
8+
9+
10+
if __name__ == "__main__":
11+
# running with debugging purpose ** NOT for production **
12+
port = int(os.environ["FLASK_APP_PORT"]) if "FLASK_APP_PORT" in os.environ else 5000
13+
app.run(
14+
host="0.0.0.0",
15+
port=port,
16+
debug=True
17+
)

config/gunicorn.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
bind = '0.0.0.0:{}'.format(str(os.getenv('GNICORN_APP_PORT', 9876)))
4+
workers = 1

0 commit comments

Comments
 (0)