diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml b/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml index 87f801c67a362825fc1d4a8ae13f20034db61ae9..aa218e22a51980e0f969a4f164bcd0a6ef40e259 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml @@ -43,7 +43,7 @@ pytest: {%- endif %} {%- endif %} script: - - pytest -vv --cov="{{cookiecutter.project_name}}" . + - pytest -vv --cov="{{cookiecutter.project_name}}" . --test-alembic black: extends: diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/deploy/Dockerfile b/fastapi_template/template/{{cookiecutter.project_name}}/deploy/Dockerfile index 7e052a8d4434ca12da97169984d5d322960e34ca..07662ead3de009d9ead5095b1e0038e635c8bb23 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/deploy/Dockerfile +++ b/fastapi_template/template/{{cookiecutter.project_name}}/deploy/Dockerfile @@ -4,30 +4,24 @@ RUN apt-get update && apt-get install -y \ wait-for-it \ && apt-get clean && rm -rf /var/lib/apt/lists/* -RUN useradd -m {{cookiecutter.project_name}} - -USER {{cookiecutter.project_name}} - -ENV PATH="${PATH}:/home/{{cookiecutter.project_name}}/.poetry/bin:/home/{{cookiecutter.project_name}}/.local/bin" +# ENV PATH="${PATH}:/home/{{cookiecutter.project_name}}/.poetry/bin:/home/{{cookiecutter.project_name}}/.local/bin" RUN pip install poetry==1.1.8 # Installing requirements RUN poetry config virtualenvs.create false -COPY pyproject.toml poetry.lock /home/{{cookiecutter.project_name}}/app/ -WORKDIR /home/{{cookiecutter.project_name}}/app/ +COPY pyproject.toml poetry.lock /app/src/ +WORKDIR /app/src RUN poetry install --no-dev # Copying actuall application -COPY . /home/{{cookiecutter.project_name}}/app/src/ -WORKDIR /home/{{cookiecutter.project_name}}/app/src/ +COPY . /app/src/ RUN pip install --use-feature=in-tree-build . -USER root -RUN chown -R {{cookiecutter.project_name}} /home/{{cookiecutter.project_name}} -RUN chmod -R 700 /home/{{cookiecutter.project_name}} -USER {{cookiecutter.project_name}} +{%- if cookiecutter.db_info.name == "sqlite" %} +VOLUME [ "/db_data" ] +{%- endif %} CMD python -m {{cookiecutter.project_name}} diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.yml b/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.yml index 27a7ef0dd49e34749fcc2c22bbae26cbea979680..248b1e3892a81be7bad0b2089fd520a2a182a1d9 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.yml @@ -10,6 +10,13 @@ services: - .env environment: - {{cookiecutter.project_name | upper }}_HOST=0.0.0.0 + {%- if cookiecutter.db_info.name == "sqlite" %} + - {{cookiecutter.project_name | upper }}_DB_FILE=/db_data/db.sqlite3 + {%- endif %} + {%- if cookiecutter.db_info.name == "sqlite" %} + volumes: + - {{cookiecutter.project_name}}-db-data:/db_data/ + {%- endif %} {%- if cookiecutter.db_info.name == "postgresql" %} db: @@ -35,13 +42,21 @@ services: - {{cookiecutter.project_name}}-db-data:/bitnami/mysql/data {%- endif %} - {% if cookiecutter.db_info.name != 'none' %} + {% if cookiecutter.enable_alembic == 'True' %} migrator: build: context: . dockerfile: ./deploy/Dockerfile image: {{cookiecutter.project_name}}:latest + {%- if cookiecutter.db_info.name == "sqlite" %} + command: alembic upgrade head + environment: + - {{cookiecutter.project_name | upper }}_DB_FILE=/db_data/db.sqlite3 + volumes: + - {{cookiecutter.project_name}}-db-data:/db_data/ + {%- else %} command: wait-for-it {{cookiecutter.project_name}}-db:{{cookiecutter.db_info.port}} -- alembic upgrade head + {%- endif %} {%- endif %} {%- if cookiecutter.enable_redis == "True" %} diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/settings.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/settings.py index 03e236859b6778573732113e7deca6dae3b76796..11f869127e0a08b294e4fe0d2bdfdd934660d102 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/settings.py +++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/settings.py @@ -21,14 +21,14 @@ class Settings(BaseSettings): {%- if cookiecutter.db_info.name != "none" %} {%- if cookiecutter.db_info.name == "sqlite" %} db_file: Path = TEMP_DIR / "db.sqlite3" - {% else %} + {%- else %} db_host: str = "{{cookiecutter.project_name}}-db" db_port: int = {{cookiecutter.db_info.port}} db_user: str = "{{cookiecutter.project_name}}" db_pass: str = "{{cookiecutter.project_name}}" db_base: str = "{{cookiecutter.project_name}}" - db_echo: bool = False {%- endif %} + db_echo: bool = False {%- endif %} {%- if cookiecutter.enable_redis == "True" %} diff --git a/pyproject.toml b/pyproject.toml index 7904b9b86a6360412e8f161a51be9baf484b9aa6..2976e9efa494549b46c7ed68fd58f952914bd89c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fastapi_template" -version = "2.1.2" +version = "2.1.3" description = "Feature-rich robust FastAPI template" authors = ["Pavel Kirilin <win10@list.ru>"] packages = [