Skip to content
Closed

Test #89

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
42bb29d
Merge pull request #85 from SamWarden/dev
SamWarden Apr 14, 2025
dd07668
refactor(log): improve error logs
SamWarden Apr 14, 2025
3bf3ec9
refactor(api): remove `"/"` as path for an endpoint
SamWarden Apr 14, 2025
a9380da
feat(api): add the `wrap_factory` function
SamWarden Apr 14, 2025
cc98797
refactor(app): use the src-layout
SamWarden Apr 14, 2025
9df6d00
Merge pull request #86 from SamWarden/reafactor/79/src_layout
SamWarden Apr 14, 2025
ed4075c
feat(uv): use the `uv` tool instead of the `poetry`
SamWarden Apr 14, 2025
3c3919f
feat(uv): add the `uv.lock` file
SamWarden Apr 14, 2025
8b9c512
Merge pull request #87 from SamWarden/feature/67/use_uv
SamWarden Apr 14, 2025
3d039a9
refactor(pyproject): remove unused linter config
SamWarden Apr 14, 2025
e57c70d
fix(alembic): adopt the `alembic` tool to use src-layout
SamWarden Apr 14, 2025
5c430a8
feat(app): add the domain service and imperative mapping
SamWarden Apr 14, 2025
c400e52
feat(app): add the domain service and imperative mapping
SamWarden Apr 14, 2025
20809ea
refactor(db): remove `exception_mapper`
SamWarden Apr 14, 2025
5ebfc46
refactor(di): add the `main` dir for di container and mediator config…
SamWarden Apr 14, 2025
6d9147b
fix(justfile): use `uv` instead of `poetry`
SamWarden Apr 14, 2025
b552058
refactor(uow): move uow factory to the `di` dir
SamWarden Apr 22, 2025
acbd4b8
refactor(monitoring): move monitoring configs to the `monitoring` dir
SamWarden Apr 22, 2025
5b4f97f
Merge pull request #88 from SamWarden/refactor/monitoring
SamWarden Apr 22, 2025
fd1c5af
fix(app): fix typehints
SamWarden Apr 22, 2025
ae47d73
feat(tests): add using Postgres templates to tests
SamWarden May 19, 2025
2ad4654
refactor(app): use sync `main` to launch the api
SamWarden May 19, 2025
3802bb3
fix(env): make `FULL_URL` default if file not exists
SamWarden May 19, 2025
9122dba
fix!(postgres): change storage dir for postgres
SamWarden Jun 4, 2025
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
80 changes: 43 additions & 37 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# This workflow will install Python dependencies, run tests and linters
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: UserServiceTest
name: CI

on:
workflow_call:

pull_request:
branches: [ master, dev ]
push:
branches: [ master, dev ]
pull_request:
branches: [ master, dev ]

jobs:
build:
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.11
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.5.29"
enable-cache: true
- name: Install project dependencies
run: uv sync --all-groups --all-extras
- name: Cache venv
uses: actions/cache@v4
with:
python-version: "3.11"
cache: "poetry"
cache-dependency-path: poetry.lock
- name: Install dependencies
run: poetry install --with dev,test,lint
path: |
./.venv
~/.local/share/uv
key: venv-${{ runner.os }}-${{ hashFiles('**/uv.lock') }}
lint:
needs: build
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.11
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.5.29"
enable-cache: true
- name: Restore cached venv
uses: actions/cache@v4
with:
python-version: "3.11"
cache: "poetry"
cache-dependency-path: poetry.lock
path: |
./.venv
~/.local/share/uv
key: venv-${{ runner.os }}-${{ hashFiles('**/uv.lock') }}
- name: Lint with pre-commit
run: poetry run pre-commit run --all-files
run: ./.venv/bin/pre-commit run --all-files
test:
needs: build
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.11
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Restore cached venv
uses: actions/cache@v4
with:
python-version: "3.11"
cache: "poetry"
cache-dependency-path: poetry.lock
- name: Test with pytest
run: poetry run pytest
path: |
./.venv
~/.local/share/uv
key: venv-${{ runner.os }}-${{ hashFiles('**/uv.lock') }}
- name: Run tests with pytest
run: ./.venv/bin/pytest
1 change: 0 additions & 1 deletion .hadolint.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ignored:
- DL3008
- DL3059
trustedRegistries:
- docker.io
48 changes: 23 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
FROM python:3.11-slim-buster AS python-base
FROM python:3.13-slim-bookworm AS python-base

ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PYTHONOPTIMIZE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1 \
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv"
APP_PATH="/app" \
UV_VERSION="0.6.14"

ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
ENV VIRTUAL_ENV="$APP_PATH/.venv"
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

WORKDIR $APP_PATH

FROM python-base AS builder

FROM python-base AS builder-base
RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc git
&& apt-get install -y --no-install-recommends gcc git \
&& rm -rf /var/lib/apt/lists/

WORKDIR $PYSETUP_PATH
COPY ./pyproject.toml ./poetry.lock ./
RUN pip install --no-cache-dir --upgrade pip==24.0 \
&& pip install --no-cache-dir setuptools==69.5.1 wheel==0.43.0 \
&& pip install --no-cache-dir poetry==1.8.2
RUN pip install --no-cache-dir "uv==$UV_VERSION"

RUN poetry install --no-dev
COPY ./pyproject.toml ./uv.lock ./
RUN uv venv -p 3.13 \
&& uv sync --all-extras --no-install-project
COPY ./src ./src
RUN uv sync --all-extras --no-editable

FROM python-base AS production
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*
FROM python-base AS runner

COPY --from=builder $VIRTUAL_ENV $VIRTUAL_ENV

WORKDIR /app
COPY ./src /app/src
CMD ["python", "-Om", "src"]
CMD ["user_service"]
2 changes: 1 addition & 1 deletion alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# sqlalchemy.url = driver://user:pass@localhost/dbname

# path to migration scripts
script_location = ./src/infrastructure/db/migrations
script_location = user_service:infrastructure/db/migrations
# Format for migration versions filenames
file_template = %%(year)d%%(month).2d%%(day).2d-%%(hour).2d%%(minute).2d%%(second).2d_%%(rev)s_%%(slug)s
# sys.path path, will be prepended to sys.path if present.
Expand Down
37 changes: 20 additions & 17 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.9"

services:
api:
profiles: [ "api" ]
Expand All @@ -23,8 +21,7 @@ services:
volumes:
- ./config:/app/config:ro
environment:
- CONFIG_PATH=${CONFIG_PATH:-./config/prod_config.toml}
command: ["python", "-Om", "src"]
- CONFIG_PATH=${CONFIG_PATH:-/app/config/prod_config.toml}
healthcheck:
test: ["CMD-SHELL", "curl -fsSL http://localhost:5000/healthcheck"]
interval: 10s
Expand All @@ -47,15 +44,14 @@ services:
volumes:
- ./config:/app/config:ro
- ./alembic.ini:/app/alembic.ini:ro
- ./src/infrastructure/db/migrations:/app/src/infrastructure/db/migrations:ro
environment:
- CONFIG_PATH=${CONFIG_PATH:-./config/prod_config.toml}
command: ["python", "-m", "alembic", "upgrade", "head"]

postgres:
profiles: [ "api", "migration" ]
container_name: user_service.postgres
image: "postgres:16-alpine"
image: "postgres:17-alpine"
hostname: user_service.postgres
restart: unless-stopped
expose:
Expand All @@ -69,7 +65,7 @@ services:
POSTGRES_USER: ${POSTGRES_USER:-$USER}
POSTGRES_DB: ${POSTGRES_DB:-$USER}
volumes:
- user_service.postgres.data:/var/lib/postgresql/users:rw
- user_service.postgres.data:/var/lib/postgresql/data:rw
healthcheck:
test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
interval: 10s
Expand Down Expand Up @@ -137,7 +133,7 @@ services:
- user_service.grafana.network
volumes:
- user_service.grafana.data:/var/lib/grafana:rw
- ./grafana/provisioning:/etc/grafana/provisioning:rw
- ./monitoring/grafana/provisioning:/etc/grafana/provisioning:rw
environment:
- GF_SECURITY_ADMIN_USER=${GRAFANA_USER:-admin}
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-admin}
Expand All @@ -154,7 +150,7 @@ services:
expose:
- "3100"
volumes:
- ./loki/config.yaml:/etc/loki/config.yaml:ro
- ./monitoring/loki/config.yaml:/etc/loki/config.yaml:ro
- user_service.loki.data:/tmp/:rw
command: -config.file=/etc/loki/config.yaml
restart: unless-stopped
Expand All @@ -173,19 +169,26 @@ services:
- user_service.grafana.network
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./vector/vector.toml:/etc/vector/vector.toml:ro
- ./monitoring/vector/vector.toml:/etc/vector/vector.toml:ro
logging:
driver: "json-file"
options:
max-size: "10m"

volumes:
user_service.postgres.data: {}
user_service.rabbitmq.data: {}
user_service.grafana.data: {}
user_service.loki.data: {}
user_service.postgres.data:
name: user_service.postgres.data
user_service.rabbitmq.data:
name: user_service.rabbitmq.data
user_service.grafana.data:
name: user_service.grafana.data
user_service.loki.data:
name: user_service.loki.data

networks:
user_service.postgres.network: {}
user_service.rabbitmq.network: {}
user_service.grafana.network: {}
user_service.postgres.network:
name: user_service.postgres.network
user_service.rabbitmq.network:
name: user_service.rabbitmq.network
user_service.grafana.network:
name: user_service.grafana.network
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ help:

# Install package with dependencies
install:
poetry install --with dev,test,lint
uv sync --all-extras --all-groups

# Run pre-commit
lint:
Expand Down Expand Up @@ -37,4 +37,4 @@ migrate:
docker compose --profile migration up --build

_py *args:
poetry run {{args}}
uv run {{args}}
File renamed without changes.
File renamed without changes.
Loading