Skip to content
This repository was archived by the owner on Feb 19, 2023. It is now read-only.

Commit a3cc81e

Browse files
committed
chore: replace psql with mongo; feat: add new proxy with lets encrypt
1 parent 738d416 commit a3cc81e

File tree

22 files changed

+320
-83
lines changed

22 files changed

+320
-83
lines changed

.env_example

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
ENV=dev
2-
PROJECT_NAME=
2+
PROJECT_NAME=fastapi_backend_base
3+
VERSION=v1
34

4-
POSTGRES_DB=
5-
POSTGRES_USER=
6-
POSTGRES_PASSWORD=
7-
POSTGRES_HOST=db
5+
MONGODB_USER=fastapibackendbase
6+
MONGODB_PASS=fastapibackendbase1234
7+
MONGODB_HOST=mongodb
8+
MONGODB_DATABASE=fastapibackendbase
9+
MONGODB_PORT=27017
10+
11+
MONGO_INITDB_ROOT_USERNAME=admin
12+
MONGO_INITDB_ROOT_PASSWORD=admin1234
13+
MONGO_INITDB_DATABASE=fastapibackendbase
814

915
NGINX_HOST=localhost
1016
UPSTREAMS=/:backend:8000

.github/workflows/mian.yml renamed to .github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ on:
77

88
jobs:
99
linter:
10-
runs-on: ubuntu-18.04
10+
runs-on: ubuntu-20.04
1111
name: Check python linting
1212
steps:
1313
- name: Checkout
1414
uses: actions/checkout@v2
1515
- name: Start linter
1616
run: |
17-
docker run --rm -w="/code/backend" -v $(pwd):/code alpine/flake8:3.5.0 .
17+
docker run --rm -w="/code/backend" -v $(pwd):/code alpine/flake8:3.9.2 .

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
.env
22

33
__pycache__
4+
.pytest_cache
5+
*.out
6+
7+
htmlcov/
8+
coverage.xml
9+
.coverage

backend/Dockerfile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
FROM python:3.8-slim-buster
1+
FROM alpine:3.11
2+
3+
LABEL maintainer Nick <[email protected]>
24

35
ARG env
4-
ARG requirements_file
5-
ENV REQUIREMENTS_FILE ${requirements_file:-dev.txt}
6+
ENV REQUIREMENTS_FILE ${env:-dev}.txt
7+
ENV PYTHONPATH "${PYTHONPATH}:/code/backend/src"
68

7-
RUN apt-get update &&\
8-
apt-get install --yes --no-install-recommends \
9-
gcc \
10-
musl-dev \
11-
postgresql-client \
12-
postgresql-contrib \
9+
RUN apk add --no-cache \
10+
bash \
1311
python3-dev \
14-
python3-pip &&\
15-
apt-get clean &&\
16-
rm -rf /var/lib/apt/lists/*
17-
18-
RUN pip3 install --no-cache-dir --upgrade pip
12+
py3-pip \
13+
gcc \
14+
musl-dev &&\
15+
pip3 install --upgrade pip &&\
16+
rm -rf /tmp/*
1917

2018
ADD /requirements/base.txt /requirements/$REQUIREMENTS_FILE /tmp/
2119
RUN pip3 install --no-cache-dir -r /tmp/$REQUIREMENTS_FILE
2220

2321
ADD . /code/
2422
WORKDIR /code/
23+
24+
EXPOSE 8000

backend/logconfig.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: 1
2+
disable_existing_loggers: False
3+
formatters:
4+
default:
5+
"()": uvicorn.logging.DefaultFormatter
6+
format: '[%(asctime)s] - %(name)s - %(levelname)s - %(message)s'
7+
datefmt: "%d/%b/%Y %H:%M:%S"
8+
access:
9+
"()": uvicorn.logging.AccessFormatter
10+
format: '[%(asctime)s] - %(name)s - %(levelname)s - %(message)s'
11+
datefmt: "%d/%b/%Y %H:%M:%S"
12+
handlers:
13+
default:
14+
formatter: default
15+
class: logging.StreamHandler
16+
stream: ext://sys.stderr
17+
access:
18+
formatter: access
19+
class: logging.StreamHandler
20+
stream: ext://sys.stdout
21+
loggers:
22+
uvicorn.error:
23+
level: INFO
24+
handlers:
25+
- default
26+
propagate: yes
27+
uvicorn.access:
28+
level: INFO
29+
handlers:
30+
- access
31+
propagate: no
32+
src.utils.runbot:
33+
level: DEBUG
34+
propogate: no
35+
handlers:
36+
- default

backend/pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[tool.black]
2+
line-length = 100
3+
include = '\.pyi?$'
4+
exclude = '''
5+
/(
6+
\.git
7+
| \.hg
8+
| \.mypy_cache
9+
| \.tox
10+
| \.venv
11+
| _build
12+
)/
13+
'''

backend/requirements/base.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# api
22
fastapi==0.65.1
33
uvicorn==0.13.4
4-
requests==2.25.1
54

65
# database
7-
databases[postgresql]==0.4.3
8-
psycopg2-binary==2.8.6
96
SQLAlchemy==1.3.24
10-
asyncpg==0.23.0
7+
pydantic==1.8.2
8+
motor==2.4.0
9+
10+
# utils
11+
PyYAML==5.4.1

backend/requirements/dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
pytest==6.2.3
44
black==21.5b1
55
flake8==3.9.2
6+
pytest-cov==2.12.0

backend/src/api/routes.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
from fastapi import APIRouter
1+
from fastapi import APIRouter, status
2+
from fastapi.responses import PlainTextResponse
23

34
from src.api.v1 import health
45

56

7+
home_router = APIRouter()
8+
9+
10+
@home_router.get("/", response_description="Homepage", include_in_schema=False)
11+
async def home():
12+
return PlainTextResponse("127.0.0.1", status_code=status.HTTP_200_OK)
13+
14+
615
api_router = APIRouter()
716
api_router.include_router(health.router)

backend/src/api/v1/health.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
router = APIRouter()
55

66

7-
@router.get("/ping")
7+
@router.get("/ping", tags=["health"])
88
async def pong():
99
# some async operation could happen here
1010
# example: `data = await get_all_datas()`

0 commit comments

Comments
 (0)