Skip to content

Commit 585a02e

Browse files
authored
Merge pull request #29 from ArielMAJ/release/2.0.1
Release/2.0.1
2 parents 1119f05 + 8e9531b commit 585a02e

11 files changed

Lines changed: 227 additions & 148 deletions

File tree

.env.docker.example

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
APPLICATION_HOST=sso
2+
APPLICATION_PORT=3000
3+
4+
POSTGRES_USER=postgres
5+
POSTGRES_PASSWORD=postgres
6+
POSTGRES_HOST=sso-db
7+
POSTGRES_DATABASE=postgres
8+
POSTGRES_PORT=5432
9+
10+
RELOAD=false
11+
12+
POSTGRES_ECHO=true # Set to false if you don't want to see SQL queries in the console
13+
DATABASE_ENABLE_CONNECTION_POOLING=true # Set to false to correctly work on Vercel
14+
15+
LOGGER_IGNORE_PATHS=GET:/docs,GET:/openapi.json
16+
LOGGER_IGNORE_INPUT_BODY_PATHS=POST:/user/register,PUT:/user/,POST:/auth/token
17+
LOGGER_IGNORE_OUTPUT_BODY_PATHS=POST:/auth/token
18+
19+
# Needs to be set to correctly work. Run `make generate-secret-key` to generate a random key.
20+
SECRET_KEY=
21+
ALGORITHM=
22+
ACCESS_TOKEN_EXPIRE_MINUTES=

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ celerybeat.pid
121121

122122
# Environments
123123
.env
124+
.env.local
125+
.env.prod
126+
.env.docker
124127
.venv
125128
env/
126129
venv/
@@ -158,3 +161,5 @@ cython_debug/
158161
# and can be added to the global gitignore or merged into this file. For a more nuclear
159162
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160163
#.idea/
164+
165+
.DS_Store

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.12.10-slim
2+
3+
WORKDIR /
4+
5+
COPY requirements.txt .
6+
7+
RUN pip install --upgrade pip && \
8+
pip install --no-cache-dir -r requirements.txt
9+
10+
COPY ./src ./src
11+
COPY ./alembic.ini .
12+
13+
EXPOSE 3000
14+
15+
CMD ["/bin/sh", "-c", "alembic upgrade head && python -m src.main"]

Makefile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@ install: ## Install Python package dependencies.
2121
test: ## Run automated tests.
2222
ENVIRONMENT=test poetry run pytest --cov
2323

24+
.PHONY: up
25+
up: ## Start all containers.
26+
$(COMPOSE) -f ./docker-compose.yml up -d --force-recreate
27+
28+
.PHONY: recreate
29+
recreate: ## Recreate all containers.
30+
$(COMPOSE) -f ./docker-compose.yml up -d --force-recreate --build
31+
2432
.PHONY: up-database
2533
up-database: ## Start database container.
26-
$(COMPOSE) up -d postgres --force-recreate
34+
$(COMPOSE) -f ./docker-compose.yml up -d database --force-recreate
2735

2836
.PHONY: down
2937
down: ## Stop all containers.
@@ -80,8 +88,15 @@ init-env: ## Copy .env.example to .env and populate SECRET_KEY, ALGORITHM, ACCES
8088
exit 1; \
8189
fi;
8290

91+
@if [ -f .env.docker ]; then \
92+
echo "Error: .env.docker already exists. Aborting."; \
93+
exit 1; \
94+
fi;
95+
8396
@cp .env.example .env
97+
@cp .env.docker.example .env.docker
8498
@sed -i '' -e '/^SECRET_KEY=/d' -e '/^ALGORITHM=/d' -e '/^ACCESS_TOKEN_EXPIRE_MINUTES=/d' .env
99+
@sed -i '' -e '/^SECRET_KEY=/d' -e '/^ALGORITHM=/d' -e '/^ACCESS_TOKEN_EXPIRE_MINUTES=/d' .env.docker
85100

86101
@SECRET_KEY=$$( \
87102
if command -v python >/dev/null 2>&1; then \
@@ -96,10 +111,12 @@ init-env: ## Copy .env.example to .env and populate SECRET_KEY, ALGORITHM, ACCES
96111
echo "Error: Failed to generate SECRET_KEY. Aborting."; \
97112
exit 1; \
98113
fi; \
99-
echo "SECRET_KEY=$$SECRET_KEY" >> .env
114+
echo "SECRET_KEY=$$SECRET_KEY" | tee -a .env .env.docker > /dev/null
100115

101116
@echo "ALGORITHM=HS256" >> .env
102117
@echo "ACCESS_TOKEN_EXPIRE_MINUTES=30" >> .env
118+
@echo "ALGORITHM=HS256" >> .env.docker
119+
@echo "ACCESS_TOKEN_EXPIRE_MINUTES=30" >> .env.docker
103120

104121
.PHONY: clean
105122
clean: ## Clean project's temporary files.

docker-compose.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
services:
2-
postgres:
2+
sso:
3+
build:
4+
context: ./
5+
dockerfile: ./Dockerfile
6+
env_file:
7+
- .env.docker
8+
environment:
9+
- APPLICATION_PORT=3000
10+
ports:
11+
- "${SSO_PORT:-3001}:3000"
12+
depends_on:
13+
- database
14+
15+
sso-db:
316
image: postgres:16.3
417
restart: always
5-
environment:
6-
POSTGRES_DB: ${POSTGRES_DATABASE}
7-
POSTGRES_USER: ${POSTGRES_USER}
8-
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
18+
env_file:
19+
- .env.docker
920
ports:
10-
- "5432:5432"
21+
- "${POSTGRES_PORT:-5432}:${POSTGRES_PORT:-5432}"
1122
volumes:
1223
- pgdata:/var/lib/postgresql/data
1324

poetry.lock

Lines changed: 136 additions & 122 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fastapi-backend-template"
3-
version = "2.0.0"
3+
version = "2.0.1"
44
description = "A FastAPI backend template."
55
authors = ["ArielMAJ <ariel.maj@hotmail.com>"]
66
readme = "README.md"

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ email-validator==2.2.0 ; python_version >= "3.12" and python_version < "4.0"
1111
fastapi-async-sqlalchemy==0.6.1 ; python_version >= "3.12" and python_version < "4.0"
1212
fastapi-cache2==0.2.2 ; python_version >= "3.12" and python_version < "4.0"
1313
fastapi==0.115.12 ; python_version >= "3.12" and python_version < "4.0"
14-
greenlet==3.2.2 ; python_version >= "3.12" and python_version < "4.0"
14+
greenlet==3.2.3 ; python_version >= "3.12" and python_version < "4.0"
1515
h11==0.16.0 ; python_version >= "3.12" and python_version < "4.0"
1616
httpcore==1.0.9 ; python_version >= "3.12" and python_version < "4.0"
1717
httptools==0.6.4 ; python_version >= "3.12" and python_version < "4.0"
@@ -36,11 +36,11 @@ sniffio==1.3.1 ; python_version >= "3.12" and python_version < "4.0"
3636
sqlalchemy==2.0.41 ; python_version >= "3.12" and python_version < "4.0"
3737
sqlalchemy[asyncio]==2.0.41 ; python_version >= "3.12" and python_version < "4.0"
3838
starlette==0.46.2 ; python_version >= "3.12" and python_version < "4.0"
39-
typing-extensions==4.13.2 ; python_version >= "3.12" and python_version < "4.0"
39+
typing-extensions==4.14.0 ; python_version >= "3.12" and python_version < "4.0"
4040
typing-inspection==0.4.1 ; python_version >= "3.12" and python_version < "4.0"
4141
tzdata==2025.2 ; python_version >= "3.12" and python_version < "4.0"
42-
uvicorn==0.34.2 ; python_version >= "3.12" and python_version < "4.0"
43-
uvicorn[standard]==0.34.2 ; python_version >= "3.12" and python_version < "4.0"
42+
uvicorn==0.34.3 ; python_version >= "3.12" and python_version < "4.0"
43+
uvicorn[standard]==0.34.3 ; python_version >= "3.12" and python_version < "4.0"
4444
uvloop==0.21.0 ; (sys_platform != "win32" and sys_platform != "cygwin") and platform_python_implementation != "PyPy" and python_version >= "3.12" and python_version < "4.0"
4545
watchfiles==1.0.5 ; python_version >= "3.12" and python_version < "4.0"
4646
websockets==15.0.1 ; python_version >= "3.12" and python_version < "4.0"

src/schemas/auth.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
from datetime import datetime
22
from typing import Union
33

4-
from pydantic import BaseModel, field_serializer
4+
from pydantic import BaseModel
55

66

77
class Token(BaseModel):
88
access_token: str
99
token_type: str
1010
expires_at: datetime
1111

12-
@field_serializer("expires_at")
13-
def serialize_expires_at(self, value: datetime):
14-
return value.strftime("%d-%m-%Y %H:%M:%S")
15-
1612

1713
class TokenData(BaseModel):
1814
email: Union[str, None] = None

src/schemas/base_db_schema.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from datetime import datetime
2-
from typing import Optional
32

4-
from pydantic import BaseModel, field_serializer
3+
from pydantic import BaseModel
54

65

76
class BaseDBSchema(BaseModel):
@@ -12,8 +11,8 @@ class BaseDBSchema(BaseModel):
1211
class Config:
1312
from_attributes = True
1413

15-
@field_serializer("created_at", "updated_at")
16-
def serialize_dt(self, dt: Optional[datetime]):
17-
if not dt:
18-
return dt
19-
return dt.strftime("%d-%m-%Y %H:%M:%S")
14+
# @field_serializer("created_at", "updated_at")
15+
# def serialize_dt(self, dt: Optional[datetime]):
16+
# if not dt:
17+
# return dt
18+
# return dt.strftime("%d-%m-%Y %H:%M:%S")

0 commit comments

Comments
 (0)