From 769783a981662a97b799046efaa17aaa338d9727 Mon Sep 17 00:00:00 2001 From: Katant Date: Sat, 13 Dec 2025 21:55:50 +1000 Subject: [PATCH 1/9] feat: update ci --- .../.github/workflows/tests.yml | 47 +++++++------- .../.gitlab-ci.yml | 19 +++--- .../.pre-commit-config.yaml | 5 ++ .../{{cookiecutter.project_name}}/Dockerfile | 63 ++++++++++++------- .../deploy/docker-compose.dev.yml | 1 + .../docker-compose.yml | 1 + .../pyproject.toml | 5 +- 7 files changed, 85 insertions(+), 56 deletions(-) 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 a9c8603..b0afa17 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml @@ -6,38 +6,41 @@ jobs: lint: strategy: matrix: - cmd: - - black - - ruff - - mypy + include: + - name: Ruff format + cmd: ruff format + - name: Ruff check + cmd: ruff check {{cookiecutter.project_name}} tests + - name: Mypy + cmd: mypy {{cookiecutter.project_name}} tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Install poetry - run: pipx install poetry - - name: Set up Python - uses: actions/setup-python@v5 + - uses: actions/checkout@v6 + + - name: Install the latest version of uv + uses: astral-sh/setup-uv@v7 with: - python-version: '3.11' - cache: 'poetry' + version: '0.9.17' + python-version: '3.13' + enable-cache: "auto" + - name: Install deps - run: poetry install + run: uv sync --locked --all-groups + - name: Run lint check - run: poetry run pre-commit run -a {{ '${{' }} matrix.cmd {{ '}}' }} + run: uv run {{ '${{' }} matrix.cmd {{ '}}' }} + pytest: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 + - name: Create .env run: touch .env - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.11' + - name: Update docker-compose - uses: KengoTODA/actions-setup-docker-compose@v1 - with: - version: "2.28.0" + uses: docker/setup-compose-action@v1 + - name: run tests - run: docker-compose run --rm api pytest -vv + run: docker compose run --rm api pytest -vv diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml b/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml index 4f0100c..e818b5d 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml @@ -1,33 +1,38 @@ stages: - "test" +variables: + UV_VERSION: "0.9.17" + PYTHON_VERSION: "3.13" + BASE_LAYER: bookworm-slim + UV_LINK_MODE: copy + .test-template: stage: test - image: ghcr.io/astral-sh/uv:0.9.12-python3.13-bookworm-slim + image: ghcr.io/astral-sh/uv:$UV_VERSION-python$PYTHON_VERSION-$BASE_LAYER tags: - kubernetes-runner - docker-runner except: - tags before_script: - - apt update && apt install -y git - - uv sync + - uv sync --locked --all-extras --dev -black: +formatter: extends: - .test-template script: - - pre-commit run ruff-format -a + - uv run ruff-format -a ruff: extends: - .test-template script: - - pre-commit run ruff -a + - uv run ruff {{cookiecutter.project_name}} tests mypy: extends: - .test-template script: - - pre-commit run mypy -a + - uv run mypy {{cookiecutter.project_name}} tests diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/.pre-commit-config.yaml b/fastapi_template/template/{{cookiecutter.project_name}}/.pre-commit-config.yaml index a8a296b..9d44f22 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/.pre-commit-config.yaml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/.pre-commit-config.yaml @@ -2,6 +2,11 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: + - repo: https://github.com/astral-sh/uv-pre-commit + rev: 0.9.17 + hooks: + - id: uv-lock + - repo: local hooks: diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile b/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile index 9894639..ba7bdaf 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile +++ b/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile @@ -1,10 +1,8 @@ -FROM ghcr.io/astral-sh/uv:0.9.12-bookworm AS uv - # ----------------------------------- -# STAGE 1: prod stage +# STAGE BUILDER: Prepare builder image # Only install main dependencies # ----------------------------------- -FROM python:3.13-slim-bookworm AS prod +FROM ghcr.io/astral-sh/uv:0.9.17-python3.13-bookworm-slim AS builder {%- if cookiecutter.db_info.name == "mysql" %} RUN apt-get update && apt-get install -y \ @@ -21,37 +19,56 @@ RUN apt-get update && apt-get install -y \ && rm -rf /var/lib/apt/lists/* {%- endif %} -ENV UV_COMPILE_BYTECODE=1 -ENV UV_LINK_MODE=copy -ENV UV_PROJECT_ENVIRONMENT=/usr/local -ENV UV_PYTHON_DOWNLOADS=never -ENV UV_NO_MANAGED_PYTHON=1 -{%- if cookiecutter.orm == 'piccolo' %} -ENV PICCOLO_CONF="{{cookiecutter.project_name}}.piccolo_conf" -{%- endif %} +ENV UV_COMPILE_BYTECODE=1 \ + UV_LINK_MODE=copy \ + UV_PYTHON_DOWNLOADS=0 \ + UV_PROJECT_ENVIRONMENT=/opt/.venv \ + VIRTUAL_ENV="/opt/.venv" \ + PATH="/opt/.venv/bin:$PATH" \ + UV_NO_DEV=1 \ + {%- if cookiecutter.orm == 'piccolo' %} + PICCOLO_CONF="{{cookiecutter.project_name}}.piccolo_conf" \ + {%- endif %} WORKDIR /app/src -RUN --mount=from=uv,source=/usr/local/bin/uv,target=/bin/uv \ - --mount=type=cache,target=/root/.cache/uv \ +RUN --mount=type=cache,target=/root/.cache/uv \ --mount=type=bind,source=uv.lock,target=uv.lock \ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ uv sync --locked --no-install-project --no-dev COPY . . -RUN --mount=from=uv,source=/usr/local/bin/uv,target=/bin/uv \ - --mount=type=cache,target=/root/.cache/uv \ +RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --locked --no-dev -CMD ["/usr/local/bin/python", "-m", "{{cookiecutter.project_name}}"] +# ----------------------------------- +# STAGE PROD: Production image +# Copy dependencies and environment from builder image +# ----------------------------------- +FROM python:3.13-slim-bookworm AS prod + +RUN groupadd --system --gid 999 nonroot \ + && useradd --system --gid 999 --uid 999 --create-home nonroot + +ENV VIRTUAL_ENV="/opt/.venv" \ + PATH="/opt/.venv/bin:$PATH" \ + {%- if cookiecutter.orm == 'piccolo' %} + PICCOLO_CONF="{{cookiecutter.project_name}}.piccolo_conf" \ + {%- endif %} + +COPY --from=builder --chown=nonroot:nonroot /app/src /app/src +COPY --from=builder --chown=nonroot:nonroot /opt/.venv /opt/.venv + +USER nonroot + +WORKDIR /app/src # ----------------------------------- -# STAGE 3: development build -# Includes dev dependencies +# STAGE DEVELOPMENT: Development image +# Copy dependencies and environment from builder image and add dev dependencies # ----------------------------------- -FROM prod AS dev +FROM builder AS dev -RUN --mount=from=uv,source=/usr/local/bin/uv,target=/bin/uv \ - --mount=type=cache,target=/root/.cache/uv \ - uv sync --locked --all-groups +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --locked --all-groups --dev diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.dev.yml b/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.dev.yml index 733f1c2..fc88a97 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.dev.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.dev.yml @@ -5,6 +5,7 @@ services: - "8000:8000" build: context: . + target: dev volumes: # Adds current directory as volume. - .:/app/src/ diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/docker-compose.yml b/fastapi_template/template/{{cookiecutter.project_name}}/docker-compose.yml index ad3b8b3..dac5b4b 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/docker-compose.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/docker-compose.yml @@ -3,6 +3,7 @@ services: build: context: . dockerfile: ./Dockerfile + target: prod image: {{cookiecutter.project_name}}:{{"${" }}{{cookiecutter.project_name | upper }}_VERSION:-latest{{"}"}} restart: always env_file: diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml b/fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml index ce05943..c3c0e87 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml @@ -133,7 +133,7 @@ dependencies = [ "aiokafka >=0.12.0,<1", {%- endif %} {%- if cookiecutter.enable_taskiq == "True" %} - "taskiq >=0.12.0,<1", + "taskiq[reload] >=0.12.0,<1", "taskiq-fastapi >=0.3.6,<1", {%- if cookiecutter.enable_redis == "True" %} "taskiq-redis >=1.1.2,<2", @@ -166,9 +166,6 @@ dev = [ "nest-asyncio >=1.6.0,<2", {%- endif %} "httpx >=0.28.1,<1", -{%- if cookiecutter.enable_taskiq == "True" %} - "taskiq[reload] >=0.12.0,<1", -{%- endif %} ] From 80ed023da827f95eb1e42cf7c09a6b3390167e43 Mon Sep 17 00:00:00 2001 From: KatantDev Date: Sat, 13 Dec 2025 23:46:18 +1000 Subject: [PATCH 2/9] feat: update ci --- README.md | 2 +- .../.github/workflows/tests.yml | 18 +++++++++++++++--- .../{{cookiecutter.project_name}}/Dockerfile | 8 +++++--- .../{{cookiecutter.project_name}}/README.md | 16 +++++----------- .../deploy/docker-compose.dev.yml | 9 ++++++++- .../docker-compose.yml | 4 ++++ .../{{cookiecutter.project_name}}/__main__.py | 1 + 7 files changed, 39 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 71b2de9..bd5f8e4 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ python3 -m fastapi_template # Answer all the questions # 🍪 Enjoy your new project 🍪 cd new_project -docker-compose up --build +docker compose up --build ``` If you want to install it from sources, try this: 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 b0afa17..799cecf 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml @@ -41,6 +41,18 @@ jobs: - name: Update docker-compose uses: docker/setup-compose-action@v1 - - name: run tests - run: docker compose run --rm api pytest -vv - + - name: Build api image (dev target) + run: | + docker compose \ + -f docker-compose.yml \ + -f deploy/docker-compose.dev.yml \ + --project-directory . \ + build api + + - name: Run pytest + run: | + docker compose \ + -f docker-compose.yml \ + -f deploy/docker-compose.dev.yml \ + --project-directory . \ + run --rm api pytest -vv . diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile b/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile index ba7bdaf..2f3439c 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile +++ b/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile @@ -25,10 +25,10 @@ ENV UV_COMPILE_BYTECODE=1 \ UV_PROJECT_ENVIRONMENT=/opt/.venv \ VIRTUAL_ENV="/opt/.venv" \ PATH="/opt/.venv/bin:$PATH" \ - UV_NO_DEV=1 \ {%- if cookiecutter.orm == 'piccolo' %} PICCOLO_CONF="{{cookiecutter.project_name}}.piccolo_conf" \ {%- endif %} + UV_NO_DEV=1 WORKDIR /app/src @@ -52,10 +52,10 @@ RUN groupadd --system --gid 999 nonroot \ && useradd --system --gid 999 --uid 999 --create-home nonroot ENV VIRTUAL_ENV="/opt/.venv" \ - PATH="/opt/.venv/bin:$PATH" \ {%- if cookiecutter.orm == 'piccolo' %} PICCOLO_CONF="{{cookiecutter.project_name}}.piccolo_conf" \ {%- endif %} + PATH="/opt/.venv/bin:$PATH" \ COPY --from=builder --chown=nonroot:nonroot /app/src /app/src COPY --from=builder --chown=nonroot:nonroot /opt/.venv /opt/.venv @@ -70,5 +70,7 @@ WORKDIR /app/src # ----------------------------------- FROM builder AS dev +ENV UV_NO_DEV=0 + RUN --mount=type=cache,target=/root/.cache/uv \ - uv sync --locked --all-groups --dev + uv sync --locked --all-groups diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/README.md b/fastapi_template/template/{{cookiecutter.project_name}}/README.md index 205276c..8fafc5e 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/README.md +++ b/fastapi_template/template/{{cookiecutter.project_name}}/README.md @@ -25,24 +25,18 @@ You can read more about uv here: https://docs.astral.sh/ruff/ You can start the project with docker using this command: ```bash -docker-compose up --build +docker compose up --build ``` If you want to develop in docker with autoreload and exposed ports add `-f deploy/docker-compose.dev.yml` to your docker command. Like this: ```bash -docker-compose -f docker-compose.yml -f deploy/docker-compose.dev.yml --project-directory . up --build +docker compose -f docker-compose.yml -f deploy/docker-compose.dev.yml --project-directory . up --build --watch ``` This command exposes the web application on port 8000, mounts current directory and enables autoreload. -But you have to rebuild image every time you modify `uv.lock` or `pyproject.toml` with this command: - -```bash -docker-compose build -``` - ## Project structure ```bash @@ -98,7 +92,7 @@ you can add `-f ./deploy/docker-compose.otlp.yml` to your docker command. Like this: ```bash -docker-compose -f docker-compose.yml -f deploy/docker-compose.otlp.yml --project-directory . up +docker compose -f docker-compose.yml -f deploy/docker-compose.otlp.yml --project-directory . up ``` This command will start OpenTelemetry collector and jaeger. @@ -189,8 +183,8 @@ aerich migrate If you want to run it in docker, simply run: ```bash -docker-compose run --build --rm api pytest -vv . -docker-compose down +docker compose run --build --rm api pytest -vv . +docker compose down ``` For running tests on your local machine. diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.dev.yml b/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.dev.yml index fc88a97..50c1321 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.dev.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/deploy/docker-compose.dev.yml @@ -3,8 +3,9 @@ services: ports: # Exposes application port. - "8000:8000" - build: + build: &build context: . + dockerfile: ./Dockerfile target: dev volumes: # Adds current directory as volume. @@ -12,10 +13,16 @@ services: environment: # Enables autoreload. {{cookiecutter.project_name | upper}}_RELOAD: "True" + develop: + watch: + - action: rebuild + path: uv.lock {%- if cookiecutter.enable_taskiq == "True" %} taskiq-worker: + build: + <<: *build volumes: # Adds current directory as volume. - .:/app/src/ diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/docker-compose.yml b/fastapi_template/template/{{cookiecutter.project_name}}/docker-compose.yml index dac5b4b..9c95268 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/docker-compose.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/docker-compose.yml @@ -79,6 +79,10 @@ services: volumes: - {{cookiecutter.project_name}}-db-data:/db_data/ {%- endif %} + command: + - python + - -m + - music_backend {%- if cookiecutter.enable_taskiq == "True" %} diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/__main__.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/__main__.py index 5c0449a..b484a94 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/__main__.py +++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/__main__.py @@ -52,6 +52,7 @@ def main() -> None: host=settings.host, port=settings.port, reload=settings.reload, + reload_excludes=[".venv/*"], log_level=settings.log_level.value.lower(), factory=True, ) From 1a43d0ee6db689d8e2f1f1a7fb2d52b85ead4694 Mon Sep 17 00:00:00 2001 From: KatantDev Date: Sat, 13 Dec 2025 23:55:26 +1000 Subject: [PATCH 3/9] chore: change `README.md` --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bd5f8e4..639824b 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,12 @@

Templator in action

-You can install it directly from pypi with pip. -```bash -python3 -m pip install fastapi_template -python3 -m fastapi_template -# or fastapi_template -# Answer all the questions -# 🍪 Enjoy your new project 🍪 +You can install and run it directly from pypi with uvx. +```shell +uvx fastapi_template +``` +### 🍪 Enjoy your new project 🍪 +```shell cd new_project docker compose up --build ``` @@ -70,7 +69,7 @@ Generator features: This project can handle arguments passed through command line. ```shell -$ python -m fastapi_template --help +$ uvx fastapi_template --help Usage: fastapi_template [OPTIONS] From 920ae3d93fa8ff407dfffe3347ba41c7b8c5263b Mon Sep 17 00:00:00 2001 From: KatantDev Date: Sat, 13 Dec 2025 23:58:33 +1000 Subject: [PATCH 4/9] fix: dockerfile --- .../template/{{cookiecutter.project_name}}/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile b/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile index 2f3439c..db977e9 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile +++ b/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile @@ -55,7 +55,7 @@ ENV VIRTUAL_ENV="/opt/.venv" \ {%- if cookiecutter.orm == 'piccolo' %} PICCOLO_CONF="{{cookiecutter.project_name}}.piccolo_conf" \ {%- endif %} - PATH="/opt/.venv/bin:$PATH" \ + PATH="/opt/.venv/bin:$PATH" COPY --from=builder --chown=nonroot:nonroot /app/src /app/src COPY --from=builder --chown=nonroot:nonroot /opt/.venv /opt/.venv From 8e5debe8f60ce1c98f9a6742312197510450d01d Mon Sep 17 00:00:00 2001 From: KatantDev Date: Sun, 14 Dec 2025 00:30:26 +1000 Subject: [PATCH 5/9] fix: gitlab ci/cd with artifacts --- .../.github/workflows/tests.yml | 2 +- .../{{cookiecutter.project_name}}/.gitlab-ci.yml | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) 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 799cecf..58073ed 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml @@ -8,7 +8,7 @@ jobs: matrix: include: - name: Ruff format - cmd: ruff format + cmd: ruff format --diff - name: Ruff check cmd: ruff check {{cookiecutter.project_name}} tests - name: Mypy diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml b/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml index e818b5d..3fced74 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml @@ -16,23 +16,31 @@ variables: except: - tags before_script: + - cd $CI_PROJECT_DIR - uv sync --locked --all-extras --dev formatter: extends: - .test-template script: - - uv run ruff-format -a + - uv run ruff format --diff ruff: extends: - .test-template script: - - uv run ruff {{cookiecutter.project_name}} tests + - uv run ruff check {{cookiecutter.project_name}} tests --output-format=gitlab --output-file=code-quality-report.json + artifacts: + reports: + codequality: $CI_PROJECT_DIR/code-quality-report.json mypy: extends: - .test-template script: - - uv run mypy {{cookiecutter.project_name}} tests - + - uv run mypy {{cookiecutter.project_name}} tests --output=json > mypy-out.json || true + - uv run mypy-gitlab-code-quality < mypy-out.json > codequality.json + artifacts: + when: always + reports: + codequality: $CI_PROJECT_DIR/codequality.json From ce05b7e15060660a476d28ab0f2082fe05457c7d Mon Sep 17 00:00:00 2001 From: KatantDev Date: Sun, 14 Dec 2025 00:40:45 +1000 Subject: [PATCH 6/9] feat: add cache for uv --- .../{{cookiecutter.project_name}}/.gitlab-ci.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml b/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml index 3fced74..335511d 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml @@ -15,9 +15,19 @@ variables: - docker-runner except: - tags + variables: + UV_CACHE_DIR: .uv-cache + cache: + - key: + files: + - uv.lock + paths: + - $UV_CACHE_DIR before_script: - cd $CI_PROJECT_DIR - uv sync --locked --all-extras --dev + after_script: + - uv cache prune --ci formatter: extends: From 356a454cc674fd9ac78f52fde700cbf7a82eef8f Mon Sep 17 00:00:00 2001 From: KatantDev Date: Sun, 14 Dec 2025 01:26:58 +1000 Subject: [PATCH 7/9] fix --- .../template/{{cookiecutter.project_name}}/Dockerfile | 4 ++-- .../template/{{cookiecutter.project_name}}/README.md | 2 +- .../{{cookiecutter.project_name}}/docker-compose.yml | 2 +- .../{{cookiecutter.project_name}}/pyproject.toml | 1 + fastapi_template/tests/utils.py | 10 ++++++++-- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile b/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile index db977e9..6bc4630 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile +++ b/fastapi_template/template/{{cookiecutter.project_name}}/Dockerfile @@ -35,12 +35,12 @@ WORKDIR /app/src RUN --mount=type=cache,target=/root/.cache/uv \ --mount=type=bind,source=uv.lock,target=uv.lock \ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ - uv sync --locked --no-install-project --no-dev + uv sync --locked --no-install-project COPY . . RUN --mount=type=cache,target=/root/.cache/uv \ - uv sync --locked --no-dev + uv sync --locked # ----------------------------------- # STAGE PROD: Production image diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/README.md b/fastapi_template/template/{{cookiecutter.project_name}}/README.md index 8fafc5e..dc02f3e 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/README.md +++ b/fastapi_template/template/{{cookiecutter.project_name}}/README.md @@ -183,7 +183,7 @@ aerich migrate If you want to run it in docker, simply run: ```bash -docker compose run --build --rm api pytest -vv . +docker compose run -f docker-compose.yml -f deploy/docker-compose.dev.yml --build --rm api pytest -vv . docker compose down ``` diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/docker-compose.yml b/fastapi_template/template/{{cookiecutter.project_name}}/docker-compose.yml index 9c95268..580fe15 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/docker-compose.yml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/docker-compose.yml @@ -82,7 +82,7 @@ services: command: - python - -m - - music_backend + - {{cookiecutter.project_name}} {%- if cookiecutter.enable_taskiq == "True" %} diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml b/fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml index c3c0e87..ff52569 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml +++ b/fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml @@ -166,6 +166,7 @@ dev = [ "nest-asyncio >=1.6.0,<2", {%- endif %} "httpx >=0.28.1,<1", + "mypy-gitlab-code-quality>=1.3.0,<2", ] diff --git a/fastapi_template/tests/utils.py b/fastapi_template/tests/utils.py index 2f1060e..16a168c 100644 --- a/fastapi_template/tests/utils.py +++ b/fastapi_template/tests/utils.py @@ -40,9 +40,15 @@ def run_default_check(context: BuilderContext, worker_id: str, without_pytest=Fa if without_pytest: return - build = run_docker_compose_command("--progress=plain build") + build = run_docker_compose_command( + "-f docker-compose.yml -f deploy/docker-compose.dev.yml " + "--project-directory . --progress=plain build" + ) assert build == 0 - tests = run_docker_compose_command("--progress=plain run --rm api pytest -vv .") + tests = run_docker_compose_command( + "-f docker-compose.yml -f deploy/docker-compose.dev.yml " + "--project-directory . --progress=plain run --rm api pytest -vv ." + ) assert tests == 0 From 6dd2e2a06042d9a3ed82d204161971a5462ca568 Mon Sep 17 00:00:00 2001 From: KatantDev Date: Sun, 14 Dec 2025 01:33:54 +1000 Subject: [PATCH 8/9] fix --- fastapi_template/tests/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastapi_template/tests/utils.py b/fastapi_template/tests/utils.py index 16a168c..df51fc0 100644 --- a/fastapi_template/tests/utils.py +++ b/fastapi_template/tests/utils.py @@ -47,7 +47,7 @@ def run_default_check(context: BuilderContext, worker_id: str, without_pytest=Fa assert build == 0 tests = run_docker_compose_command( "-f docker-compose.yml -f deploy/docker-compose.dev.yml " - "--project-directory . --progress=plain run --rm api pytest -vv ." + "--project-directory . --progress=plain run --build --rm api pytest -vv ." ) assert tests == 0 From f2851437a9656cf9f44ac3f9afe69fc98bf5d3df Mon Sep 17 00:00:00 2001 From: KatantDev Date: Sun, 14 Dec 2025 01:35:50 +1000 Subject: [PATCH 9/9] chore: update `README.md` --- .../template/{{cookiecutter.project_name}}/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/README.md b/fastapi_template/template/{{cookiecutter.project_name}}/README.md index dc02f3e..7b3d560 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/README.md +++ b/fastapi_template/template/{{cookiecutter.project_name}}/README.md @@ -183,7 +183,7 @@ aerich migrate If you want to run it in docker, simply run: ```bash -docker compose run -f docker-compose.yml -f deploy/docker-compose.dev.yml --build --rm api pytest -vv . +docker compose -f docker-compose.yml -f deploy/docker-compose.dev.yml run --build --rm api pytest -vv . docker compose down ```