forked from DHBW-FN-TIT20/essensfindung
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* changed main folder * added gunicorn * added Dockerfile * added .env * now use env for config * updated from poetry * updated * refactored the config for docker * Updated for Docker * added * updated * delete folder * some fixes * added for easy * added docker-compose * updated test path * updated working directory * updated working directories * added poetry
- Loading branch information
1 parent
926049d
commit 6c5b50c
Showing
79 changed files
with
339 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
*.md | ||
app/tests | ||
__pycache__ | ||
.env | ||
*example* | ||
.git | ||
.vscode | ||
.venv | ||
*cache* | ||
.github | ||
app/logs | ||
app/essensfindung.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Base Source https://fastapi.tiangolo.com/deployment/docker | ||
# This is the first stage, to create the requirements.txt | ||
FROM python:3.9 as requirements-stage | ||
|
||
WORKDIR /tmp | ||
RUN apt-get update && apt-get install -y \ | ||
build-essential \ | ||
libssl-dev \ | ||
libffi-dev \ | ||
python3-dev \ | ||
cargo \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
RUN pip install poetry | ||
COPY ["./pyproject.toml", "./poetry.lock", "/tmp/"] | ||
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes | ||
|
||
# Start final stage | ||
FROM python:3.9 | ||
|
||
# Install Dependencies | ||
COPY --from=requirements-stage /tmp/requirements.txt /tmp/requirements.txt | ||
RUN /usr/local/bin/python -m pip install --upgrade pip && \ | ||
pip install --no-cache-dir --upgrade -r /tmp/requirements.txt | ||
|
||
# Expose port 80 | ||
EXPOSE 80 | ||
|
||
# Copy the app | ||
RUN ["mkdir", "-p", "/essensfindung/"] | ||
COPY ./app /essensfindung/app | ||
WORKDIR /essensfindung/app | ||
|
||
|
||
# Setup local DB if needed | ||
RUN ["mkdir", "data"] | ||
VOLUME [ "/essensfindung/app/data" ] | ||
|
||
# Start gunicorn server with 2 workers, uvicorn worker type and use the 0.0.0.0 host with port 80 | ||
ENTRYPOINT ["gunicorn", "-w", "2", "-k", "uvicorn.workers.UvicornWorker", "-b", "0.0.0.0:80", "main:app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
build: clean_python | ||
docker build -t essensfindung . | ||
|
||
clean_python: | ||
find . -type d -name __pycache__ -exec rm -r {} \+ | ||
rm -r -f app/logs | ||
rm -f app/essensfindung.db | ||
|
||
clean_docker: | ||
docker rm --force essensfindung | ||
docker container prune --force | ||
docker volume prune --force | ||
|
||
clean_all: clean_python clean_python clean_docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GOOGLE_API_KEY=KEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
GOOGLE_API_KEY=KEY | ||
POSTGRES_USER=USER! | ||
POSTGRES_PASSWORD=PASSWORD! | ||
POSTGRES_SERVER=DB_SERVER! | ||
POSTGRES_DATABASE=DATABASE! | ||
POSTGRES_PORT=5432 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Create the connection to the Database""" | ||
from pathlib import Path | ||
from typing import Generator | ||
|
||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker | ||
from tools.config import settings | ||
|
||
if settings.SQL_LITE: | ||
Path("./data").mkdir(exist_ok=True) | ||
SQLALCHEMY_DATABASE_URL = "sqlite:///./data/essensfindung.db" | ||
# Use connect_args parameter only with sqlite | ||
engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}) | ||
else: | ||
SQLALCHEMY_DATABASE_URL = f"postgresql://{settings.POSTGRES_USER}:{settings.POSTGRES_PASSWORD}@{settings.POSTGRES_SERVER}:{settings.POSTGRES_PORT}/{settings.POSTGRES_DATABASE}" | ||
engine = create_engine(SQLALCHEMY_DATABASE_URL) | ||
|
||
|
||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | ||
|
||
|
||
def get_db() -> Generator: | ||
try: | ||
database = SessionLocal() | ||
yield database | ||
finally: | ||
database.close() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
from dotenv import load_dotenv | ||
|
||
ENV_PATH = Path("./.env") | ||
load_dotenv(dotenv_path=ENV_PATH) | ||
|
||
|
||
class Setting: | ||
"""Contains all Settings - Loads from the os env""" | ||
|
||
GOOGLE_API_KEY: str = os.getenv("GOOGLE_API_KEY") | ||
|
||
if os.getenv("POSTGRES_SERVER"): | ||
SQL_LITE: bool = False | ||
POSTGRES_USER: str = os.getenv("POSTGRES_USER") | ||
POSTGRES_PASSWORD: str = os.getenv("POSTGRES_PASSWORD") | ||
POSTGRES_SERVER: str = os.getenv("POSTGRES_SERVER") | ||
POSTGRES_DATABASE: str = os.getenv("POSTGRES_DATABASE") | ||
POSTGRES_PORT: str = os.getenv("POSTGRES_PORT") | ||
else: | ||
SQL_LITE: bool = True | ||
|
||
|
||
settings = Setting() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.