Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions .env.example

This file was deleted.

23 changes: 14 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,42 @@ ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy

COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev --no-install-project
RUN uv sync --frozen --no-install-project

COPY app/ ./app/
COPY tests/ ./tests/

# ── Stage 2: runtime ──────────────────────────────────────────────────────────
# Same base as builder so .venv Python symlinks resolve correctly.
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS runtime

RUN apt-get update \
&& apt-get install -y --no-install-recommends ffmpeg \
&& rm -rf /var/lib/apt/lists/*

RUN useradd --system --create-home --uid 1001 appuser
RUN useradd --system --create-home --uid 1001 appuser \
&& mkdir -p /weights \
&& chown -R appuser:appuser /weights /home/appuser

WORKDIR /app

COPY --from=builder /app/.venv /app/.venv
COPY --from=builder /app/app /app/app
COPY scripts/ /app/scripts/
COPY --from=builder /app/.venv /app/.venv
COPY --from=builder /app/app /app/app
COPY --from=builder /app/pyproject.toml /app/pyproject.toml
COPY scripts/entrypoint.sh /app/scripts/entrypoint.sh

RUN chmod +x /app/scripts/entrypoint.sh \
&& mkdir -p /app/assets/weights /app/assets/voices \
&& chown -R appuser:appuser /app

ENV PATH="/app/.venv/bin:$PATH"
# HF_HOME=/weights — pocket-tts downloads models here (persisted via named volume)
ENV PATH="/app/.venv/bin:$PATH" \
HF_HOME=/weights

USER appuser

EXPOSE 8000

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
# start_period covers first-run model downloads (~240 MB per language)
HEALTHCHECK --interval=30s --timeout=5s --start-period=300s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/healthz')"

ENTRYPOINT ["/app/scripts/entrypoint.sh"]
74 changes: 54 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,65 @@
.PHONY: dev sync test test-integration lint fmt typecheck ci build run stop clean
DC = docker compose -f docker-compose.yml -f docker-compose.dev.yml
DC_RUN = $(DC) run --rm --no-deps app

dev:
uv run uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
.PHONY: build dev-docker dev-docker-build test-docker lint-docker fmt-docker typecheck-docker ci-docker \
logs start run stop clean configure \
sync test lint fmt typecheck ci

# ── Docker (primary workflow) ─────────────────────────────────────────────────
build:
docker compose build

dev-docker:
$(DC) up

dev-docker-build:
$(DC) up --build

test-docker:
$(DC_RUN) pytest -m 'not integration and not slow' -v

test-integration-docker:
$(DC_RUN) pytest -m integration -v

lint-docker:
$(DC_RUN) ruff check app/ tests/

fmt-docker:
$(DC_RUN) ruff format app/ tests/

fmt-check-docker:
$(DC_RUN) ruff format --check app/ tests/

typecheck-docker:
$(DC_RUN) mypy app/

ci-docker: lint-docker fmt-check-docker typecheck-docker test-docker

logs:
docker compose logs -f app

start:
docker compose up -d

run: start

stop:
docker compose down

configure:
bash scripts/configure.sh

clean:
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
find . -name '*.pyc' -delete 2>/dev/null || true

# ── Local fallback (requires uv + dev deps installed locally) ─────────────────
sync:
uv sync --dev

test:
uv run pytest -m 'not integration and not slow' -v

test-integration:
uv run pytest -m 'integration' -v

lint:
uv run ruff check app/ tests/

Expand All @@ -22,17 +70,3 @@ typecheck:
uv run mypy app/

ci: lint fmt typecheck test

build:
docker build -t speech-server .

run:
docker compose up

stop:
docker compose down 2>/dev/null || true
-pkill -f "uvicorn app.main:app" 2>/dev/null || true

clean:
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
find . -name '*.pyc' -delete 2>/dev/null || true
Loading
Loading