Fix(Docker): Seperate DEV and PROD

- Restructured the project
This commit is contained in:
minhtrannhat 2023-10-10 14:33:11 -04:00
parent 975efc5ee9
commit 782fa386d5
Signed by: minhtrannhat
GPG Key ID: E13CFA85C53F8062
10 changed files with 70 additions and 1 deletions

View File

@ -1 +1,11 @@
# neo-neo-todo # Neo Neo Todo API
## Backend
- Run the live `uvicorn` webserver with `uvicorn neo_neo_todo.main:app --reload` at the backend root.
### Backend dependencies
## Frontend
## Frontend dependencies

12
backend/.dockerignore Normal file
View File

@ -0,0 +1,12 @@
# Python files
__pycache__/
.venv/
# ide files
.vscode/
# Pytest
.pytest_cache/
# enviroment constants
.envrc

33
backend/Dockerfile Normal file
View File

@ -0,0 +1,33 @@
# build stage
FROM python:3.11 AS builder
# install PDM
RUN pip install -U pip setuptools wheel
RUN pip install pdm
# copy files
COPY pyproject.toml pdm.lock README.md /backend/
COPY install.sh /backend/
COPY src/ /backend/src
# import ENV
ARG ENV
# install dependencies and project into the local packages directory
WORKDIR /backend
RUN mkdir __pypackages__ && chmod u+x install.sh && ./install.sh
# run stage
FROM python:3.11
# retrieve packages from build stage
ENV PYTHONPATH=/backend/pkgs
COPY --from=builder /backend/__pypackages__/3.11/lib /backend/pkgs
# retrieve executables
COPY --from=builder /backend/__pypackages__/3.11/bin/* /bin/
EXPOSE 8080
# set command/entrypoint, adapt to fit your needs
CMD ["python3","-m", "uvicorn", "neo_neo_todo.main:app", "--reload"]

1
backend/README.md Normal file
View File

@ -0,0 +1 @@
# Backend Technical Write Up

7
backend/install.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
if [ ${ENV} = "DEV" ]; then
pdm sync --dev
else
pdm sync --prod --no-editable
fi

View File

View File

@ -39,11 +39,17 @@ asyncio_mode = "auto"
pythonpath = ["src"] pythonpath = ["src"]
[tool.pdm.scripts] [tool.pdm.scripts]
# python code formatting # python code formatting
format-black = "black src/ tests/" format-black = "black src/ tests/"
# python code linting # python code linting
lint-ruff = "ruff check src/ tests/" lint-ruff = "ruff check src/ tests/"
format = {composite = ["format-black"]} format = {composite = ["format-black"]}
lint = {composite = ["lint-ruff"]} lint = {composite = ["lint-ruff"]}
test = "pytest tests/" test = "pytest tests/"
start = "uvicorn neo_neo_todo.main:app --reload"