diff --git a/.env.example b/.env.example index d49ae3e..10accd8 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ +# OAUTH OAUTH_CLIENT_ID = "" OAUTH_CLIENT_SECRET = "" OAUTH_REDIRECT_URI = "http://localhost:8080/callback" @@ -5,11 +6,13 @@ OAUTH_URL_AUTHORIZE = "https://www.bling.com.br/Api/v3/oauth/authorize" OAUTH_URL_ACCESS_TOKEN = "https://www.bling.com.br/Api/v3/oauth/token" # DATABASE -DB_NAME = 'ajusta_bling' -DB_USER = 'ajusta_bling' -DB_PASS = 'ajusta_bling' -DB_HOST = 'winhost' -DB_PORT = '5432' +POSTGRES_USER = 'ajusta_bling' +POSTGRES_PASSWORD = 'ajusta_bling' +POSTGRES_DB = 'ajusta_bling' + +# FLASK +FLASK_HOST = "0.0.0.0" +FLASK_PORT = 8080 +FLASK_ENV=development + -WEB_HOST = "0.0.0.0" -WEB_PORT = "8080" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3792713 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.12-alpine3.20 + +ENV PYTHONUNBUFFERED 1 +ENV PYTHONPATH /ajusta_bling +ENV FLASK_APP ajusta_bling.__main__ +ENV FLASK_RUN_HOST 0.0.0.0 + +WORKDIR /app + +COPY . /app +RUN pip install --no-cache-dir -r requirements.txt +RUN pip install --no-cache-dir setuptools wheel +RUN pip install --no-cache-dir -e . + +EXPOSE 5000 + +CMD ["python", "-m", "ajusta_bling"] + + diff --git a/ajusta_bling/__init__.py b/ajusta_bling/__init__.py index e69de29..8d1c8b6 100644 --- a/ajusta_bling/__init__.py +++ b/ajusta_bling/__init__.py @@ -0,0 +1 @@ + diff --git a/ajusta_bling/__main__.py b/ajusta_bling/__main__.py index 9c58930..ddb5021 100644 --- a/ajusta_bling/__main__.py +++ b/ajusta_bling/__main__.py @@ -1,9 +1,6 @@ import argparse import os from typing import Sequence - -from dotenv import load_dotenv - """ This is always the entry point so you don't technically need to do the __name__ == "__main__" check, but its still common practice to show that @@ -44,7 +41,7 @@ def main(argv: Sequence[str] | None = None) -> int: type=str, action=EnvDefault, required=True, - envvar="DB_USER", + envvar="POSTGRES_USER", help="PostgreSQL User", ) @@ -52,25 +49,22 @@ def main(argv: Sequence[str] | None = None) -> int: "--dbpassword", "-dP", type=str, action=EnvDefault, - envvar="DB_PASS", + envvar="POSTGRES_PASSWORD", help="PostgreSQL Password", ) parser.add_argument( "--dbhost", "-dh", type=str, - action=EnvDefault, - required=True, - envvar="DB_HOST", + required=False, + default='db', help="PostgreSQL Host", ) parser.add_argument( "--dbport", "-dp", type=int, - action=EnvDefault, - required=True, - envvar="DB_PORT", + default=5432, help="PostgreSQL Port", ) @@ -79,7 +73,7 @@ def main(argv: Sequence[str] | None = None) -> int: type=str, action=EnvDefault, required=True, - envvar="DB_NAME", + envvar="POSTGRES_DB", help="PostgreSQL Database", ) @@ -88,26 +82,24 @@ def main(argv: Sequence[str] | None = None) -> int: type=str, action=EnvDefault, required=True, - envvar="WEB_HOST", + envvar="FLASK_HOST", help="Web server host", ) parser.add_argument( "--webport", "-wp", type=int, - action=EnvDefault, - required=True, - envvar="WEB_PORT", + default=5000, help="Web server port", ) parser.add_argument( - "--debug", - type=bool, + "--env", + type=str, action=EnvDefault, - envvar="WEB_DEBUG", + envvar="FLASK_ENV", default=False, - help="Enable web server debug", + help="Changes flask environment", ) args = parser.parse_args(argv) @@ -121,5 +113,4 @@ def main(argv: Sequence[str] | None = None) -> int: return 0 if __name__ == "__main__": - load_dotenv(".env") - raise SystemExit(main()) \ No newline at end of file + raise SystemExit(main()) diff --git a/ajusta_bling/common.py b/ajusta_bling/common.py index 7c3abb8..2510468 100644 --- a/ajusta_bling/common.py +++ b/ajusta_bling/common.py @@ -12,4 +12,4 @@ class Args: webhost: str webport: int - debug: bool = True \ No newline at end of file + env: str diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..7548c3a --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,39 @@ +services: + web: + build: . + container_name: ajusta_bling_app + ports: + - "${FLASK_PORT}:5000" + environment: + - FLASK_HOST + - FLASK_PORT + - FLASK_ENV + - OAUTH_CLIENT_ID + - OAUTH_CLIENT_SECRET + - OAUTH_REDIRECT_URI + - OAUTH_URL_AUTHORIZE + - OAUTH_URL_ACCESS_TOKEN + - POSTGRES_USER + - POSTGRES_PASSWORD + - POSTGRES_DB + volumes: + - ./ajusta_bling:/app/ajusta_bling + depends_on: + - db + restart: always + command: > + sh -c "python3.12 -m ajusta_bling" + db: + image: postgres:16.3-alpine3.20 + container_name: ajusta_bling_db + ports: + - "5432:5432" + environment: + - POSTGRES_USER + - POSTGRES_PASSWORD + - POSTGRES_DB + volumes: + - postgres_data:/var/lib/postgresql/data + +volumes: + postgres_data: diff --git a/setup.cfg b/setup.cfg index 99dcdc4..e563546 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,5 +36,9 @@ testing = [options.package_data] ajusta_bling = py.typed +[options.entry_points] +console_scripts = + ajusta_bling = ajusta_bling.__main__:main + [flake8] max-line-length = 160