diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/.env b/fastapi_template/template/{{cookiecutter.project_name}}/.env index 0a784e0..e7dc08b 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/.env +++ b/fastapi_template/template/{{cookiecutter.project_name}}/.env @@ -1,6 +1,6 @@ {{cookiecutter.project_name | upper}}_RELOAD=True {%- if cookiecutter.db_info.name == "sqlite" %} {{cookiecutter.project_name | upper}}_DB_FILE=db.sqlite3 -{%- else %} +{%- elif cookiecutter.db_info.name != 'none' %} {{cookiecutter.project_name | upper}}_DB_HOST=localhost {%- endif %} diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml b/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml index a869b8d..e6fd52d 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml @@ -47,9 +47,10 @@ jobs: run: poetry run mypy . pytest: runs-on: ubuntu-latest - {%- if cookiecutter.db_info.name != "none" %} - {%- if cookiecutter.db_info.name != "sqlite" %} + {%- if ((cookiecutter.db_info.name != "none" and cookiecutter.db_info.name != "sqlite") or + (cookiecutter.enable_rmq == "True")) %} services: + {%- if cookiecutter.db_info.name != "none" and cookiecutter.db_info.name != "sqlite" %} {{cookiecutter.project_name}}-db: image: {{ cookiecutter.db_info.image }} env: @@ -72,7 +73,18 @@ jobs: {%- endif %} ports: - {{ cookiecutter.db_info.port }} - {%- endif %} + {%- endif %} + {%- if cookiecutter.enable_rmq == "True" %} + {{cookiecutter.project_name}}-rmq: + image: rabbitmq:3.9.16-alpine + env: + RABBITMQ_DEFAULT_USER: "guest" + RABBITMQ_DEFAULT_PASS: "guest" + RABBITMQ_DEFAULT_VHOST: "/" + options: --health-cmd="rabbitmq-diagnostics check_running -q" --health-interval=10s --health-timeout=5s --health-retries=8 + ports: + - 5672 + {%- endif %} {%- endif %} steps: - uses: actions/checkout@v2 @@ -86,10 +98,15 @@ jobs: POETRY_VIRTUALENVS_CREATE: false - name: Run pytest check run: poetry run pytest -vv --cov="{{cookiecutter.project_name}}" . + env: + {{ cookiecutter.project_name | upper }}_HOST: "0.0.0.0" {%- if cookiecutter.db_info.name != "none" %} {%- if cookiecutter.db_info.name != "sqlite" %} - env: {{ cookiecutter.project_name | upper }}_DB_HOST: localhost {{ cookiecutter.project_name | upper }}_DB_PORT: {{'${{'}}job.services.{{cookiecutter.project_name}}-db.ports['{{cookiecutter.db_info.port}}']{{'}}'}} {%- endif %} {%- endif %} + {%- if cookiecutter.enable_rmq == "True" %} + {{ cookiecutter.project_name | upper }}_RABBIT_HOST: localhost + {{ cookiecutter.project_name | upper }}_RABBIT_PORT: {{'${{'}}job.services.{{cookiecutter.project_name}}-rmq.ports['5672']{{'}}'}} + {%- endif %} diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml b/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml index 094d90e..2eeedf2 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml @@ -35,25 +35,37 @@ mypy: pytest: extends: - .test-template - {%- if cookiecutter.db_info.name != "none" %} - {%- if cookiecutter.db_info.name != "sqlite" %} + {%- if ((cookiecutter.db_info.name != "none" and cookiecutter.db_info.name != "sqlite") or + (cookiecutter.enable_rmq == "True")) %} services: + {%- if cookiecutter.db_info.name != "none" and cookiecutter.db_info.name != "sqlite" %} - name: {{ cookiecutter.db_info.image }} + alias: database + {%- endif %} + {%- if cookiecutter.enable_rmq == "True" %} + - name: rabbitmq:3.9.16-alpine + alias: rmq + {%- endif %} variables: {%- if cookiecutter.db_info.name == "postgresql" %} - {{ cookiecutter.project_name | upper }}_DB_HOST: localhost + {{ cookiecutter.project_name | upper }}_DB_HOST: database POSTGRES_PASSWORD: {{ cookiecutter.project_name }} POSTGRES_USER: {{ cookiecutter.project_name }} POSTGRES_DB: {{ cookiecutter.project_name }} {%- endif %} {%- if cookiecutter.db_info.name == "mysql" %} - {{ cookiecutter.project_name | upper }}_DB_HOST: localhost + {{ cookiecutter.project_name | upper }}_DB_HOST: database MYSQL_PASSWORD: {{ cookiecutter.project_name }} MYSQL_USER: {{ cookiecutter.project_name }} MYSQL_DATABASE: {{ cookiecutter.project_name }} ALLOW_EMPTY_PASSWORD: yes {%- endif %} - {%- endif %} + {%- if cookiecutter.enable_rmq == "True" %} + RABBITMQ_DEFAULT_USER: "guest" + RABBITMQ_DEFAULT_PASS: "guest" + RABBITMQ_DEFAULT_VHOST: "/" + {{ cookiecutter.project_name | upper }}_RABBIT_HOST: rmq + {%- endif %} {%- endif %} script: {%- if cookiecutter.db_info.name != "none" %} @@ -63,4 +75,10 @@ pytest: - wait-for-it -t 180 ${{ cookiecutter.project_name | upper }}_DB_HOST:{{cookiecutter.db_info.port}} {%- endif %} {%- endif %} - - pytest -vv --cov="{{cookiecutter.project_name}}" . + - pytest -vv --junitxml=report.xml --cov="{{cookiecutter.project_name}}" . + - coverage xml + artifacts: + when: always + reports: + cobertura: coverage.xml + junit: report.xml diff --git a/pyproject.toml b/pyproject.toml index a9ad143..1cd29e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fastapi_template" -version = "3.3.3" +version = "3.3.4" description = "Feature-rich robust FastAPI template" authors = ["Pavel Kirilin "] packages = [{ include = "fastapi_template" }]