From fa05870cbcf506dd07ecec15bb4f7d72865b5e95 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 16 Oct 2023 23:06:19 +0200 Subject: [PATCH 1/3] add dockerfile --- Dockerfile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c3cd200 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim AS backend-builder +WORKDIR /app + +COPY requierements.txt /app/ + + +RUN pip install --upgrade pip +RUN pip install -r requierements.txt + +# Create the final image +FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim + +WORKDIR /app + +COPY --from=backend-builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages +COPY app /app/app + + +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file From f78745ef7bfab437253adbdf3aca24f6ec1aca03 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 16 Oct 2023 23:25:24 +0200 Subject: [PATCH 2/3] update Dockerfile for backend python --- Dockerfile | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index c3cd200..d7b455a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,11 @@ -FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim AS backend-builder +FROM python:3.11.6-alpine3.18 WORKDIR /app COPY requierements.txt /app/ - - -RUN pip install --upgrade pip -RUN pip install -r requierements.txt - -# Create the final image -FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim - -WORKDIR /app - -COPY --from=backend-builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages COPY app /app/app +RUN pip install --upgrade pip && pip install -r requierements.txt + + CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file From 6d46456bca61387a82d09c1c9502e5c91b39e04f Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 17 Oct 2023 21:37:36 +0200 Subject: [PATCH 3/3] user env --- app/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 8297dde..1f3552f 100644 --- a/app/main.py +++ b/app/main.py @@ -11,8 +11,10 @@ app.include_router(token.router) @app.on_event("startup") async def startup_event(): - user_add.add(username="Peter93", password="toto", roles="Admin") - user_add.add(username="Robert80", password="titi", roles="User") + if len(os.environ["USERNAME_ADMIN"]) > 0 and len(os.environ["PASSWORD_ADMIN"]) > 0: + user_add.add(username=os.environ["USERNAME_ADMIN"], password=os.environ["PASSWORD_ADMIN"], roles="Admin") + if len(os.environ["USERNAME_TEST"]) > 0 and len(os.environ["PASSWORD_TEST"]) > 0: + user_add.add(username=os.environ["USERNAME_TEST"], password=os.environ["PASSWORD_TEST"], roles="User") @app.get("/") async def root():