From a8e04e69103b57f49d4ffacdac40c59d8078a766 Mon Sep 17 00:00:00 2001 From: PPswag Date: Mon, 9 Jun 2025 16:48:54 -0700 Subject: [PATCH] feat: add automatic alembic config generation and cryptography dependency --- credservice/Dockerfile | 8 ++- .../scripts/generate_alembic_config.py | 60 +++++++++++++++++++ pyproject.toml | 1 + 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 credservice/scripts/generate_alembic_config.py diff --git a/credservice/Dockerfile b/credservice/Dockerfile index 7112dd5..d82106b 100644 --- a/credservice/Dockerfile +++ b/credservice/Dockerfile @@ -10,10 +10,14 @@ COPY requirements.txt . # Install any needed packages specified in requirements.txt RUN pip install --no-cache-dir -r requirements.txt -# Copy the application code and Alembic setup +# Copy the application code and scripts COPY ./app ./app COPY ./alembic ./alembic -COPY alembic.ini . +COPY ./scripts ./scripts + +# Generate alembic.ini +RUN python scripts/generate_alembic_config.py + COPY run_service.sh . # Make port 8001 available to the world outside this container diff --git a/credservice/scripts/generate_alembic_config.py b/credservice/scripts/generate_alembic_config.py new file mode 100644 index 0000000..65c1c92 --- /dev/null +++ b/credservice/scripts/generate_alembic_config.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +"""Script to generate alembic.ini configuration file.""" + +import os +from pathlib import Path + +def generate_alembic_ini(output_dir: str = "."): + """ + Generate alembic.ini file in the specified directory. + + Args: + output_dir: Directory where alembic.ini should be created + """ + content = """[alembic] +script_location = alembic + +[loggers] +keys = root,sqlalchemy,alembic + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +""" + + output_path = Path(output_dir) / "alembic.ini" + with open(output_path, "w") as f: + f.write(content) + + print(f"✅ Generated alembic.ini at {output_path}") + +if __name__ == "__main__": + # Get the project root (assuming script is in scripts directory) + project_root = Path(__file__).parent.parent + generate_alembic_ini(str(project_root)) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 7e8fb45..31a1b4c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,7 @@ dependencies = [ "requests>=2.30.0", # HTTP client for API calls "toml>=0.10.2", # TOML config file parsing "pydantic>=2.0.0", # Data validation + "cryptography>=42.0.0", # Cryptographic primitives ] [project.optional-dependencies]