From 8e913479bc854386aae58deacce6eb946d823885 Mon Sep 17 00:00:00 2001 From: ITQ Date: Thu, 20 Nov 2025 07:34:26 +0300 Subject: [PATCH] chore: small improvements --- .gitignore | 2 +- .gitlab-ci.yml | 74 ++++++++++++++++++++++++--------------------- .justfile | 8 ++--- Containerfile | 2 +- config.example.toml | 2 +- 5 files changed, 45 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index 8a423ad..f855d16 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # Environment -./config.toml +config.toml docker-compose.yml .idea diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a9501a3..ab87529 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,7 +31,7 @@ cache: .trivy-fs-template: &trivy-fs-scan stage: security - image: + image: name: aquasec/trivy:latest entrypoint: [""] cache: @@ -61,7 +61,7 @@ cache: .trivy-image-template: &trivy-image-scan stage: security - image: + image: name: aquasec/trivy:latest entrypoint: [""] cache: @@ -138,37 +138,6 @@ cache: when: manual allow_failure: true -.test-template: &test-config - <<: *docker-job - stage: test - script: - - apk add --no-cache docker-compose - - | - REGISTRY_PREFIX=$CI_REGISTRY_IMAGE \ - docker compose -f compose.yaml -f compose.prod.yaml \ - --profile migrations --profile tests up -d -y --quiet-pull --quiet-build - - | - TEST_CONTAINER_ID=$(docker compose --profile migrations --profile tests ps -q tests -a) - timeout 600 docker wait $TEST_CONTAINER_ID - TEST_EXIT_CODE=$(docker inspect --format "{{.State.ExitCode}}" $TEST_CONTAINER_ID) - - if [ $TEST_EXIT_CODE -eq 0 ]; then - echo "Tests passed." - else - echo "Tests failed with exit code $TEST_EXIT_CODE." - exit 1 - fi - - | - docker compose -f compose.yaml -f compose.prod.yaml down - artifacts: - paths: - - ./.cov - expire_in: 1 week - when: always - rules: - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - - if: $CI_PIPELINE_SOURCE == 'merge_request_event' - sast-filesystem: <<: *trivy-fs-scan @@ -217,8 +186,43 @@ build-migrations: CONTAINERFILE: Containerfile BUILDTARGET: migrations -run-tests: - <<: *test-config +test-e2e: + <<: *docker-job + stage: test + variables: + COMPOSE_PROFILES: | + --profile migrations + --profile tests + script: + - export PROFILES="$(printf '%s ' $COMPOSE_PROFILES)" + - apk add --no-cache docker-compose + - | + REGISTRY_PREFIX=$CI_REGISTRY_IMAGE \ + docker compose -f compose.yaml -f compose.prod.yaml \ + $PROFILES up -d -y --quiet-pull --quiet-build + - | + TEST_CONTAINER_ID=$(docker compose $PROFILES ps -q tests -a) + timeout 600 docker wait $TEST_CONTAINER_ID + TEST_EXIT_CODE=$(docker inspect --format "{{.State.ExitCode}}" $TEST_CONTAINER_ID) + + if [ $TEST_EXIT_CODE -eq 0 ]; then + echo "Tests passed." + else + echo "Tests failed with exit code $TEST_EXIT_CODE." + exit 1 + fi + - docker compose $PROFILES logs --no-color > compose.log + - | + docker compose -f compose.yaml -f compose.prod.yaml down + artifacts: + paths: + - ./.cov + - ./compose.log + expire_in: 1 week + when: always + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' dependencies: - build-runtime - build-tests diff --git a/.justfile b/.justfile index b52864f..167df9b 100644 --- a/.justfile +++ b/.justfile @@ -74,12 +74,10 @@ lints-run: [group("Migrations")] [doc("Запуск миграции")] migrations-run tag="head": - docker compose run --remove-orphans migrations alembic upgrade {{tag}} - docker compose down postgresql + CONFIGURATION_PATH=config.toml alembic upgrade {{tag}} [no-cd] [group("Migrations")] [doc('Создание миграции')] -migrations-make message: - docker compose run migrations alembic revision --autogenerate -m "{{message}}" - docker compose down postgresql +migrations-make message="": + CONFIGURATION_PATH=config.toml alembic revision --autogenerate -m "{{message}}" diff --git a/Containerfile b/Containerfile index a7038aa..d272f3a 100644 --- a/Containerfile +++ b/Containerfile @@ -71,7 +71,7 @@ RUN uv sync --group tests --frozen --no-cache RUN mkdir -p /app/cov -CMD [ "sh", "-c", "coverage run --source=src -m pytest -v && coverage report && coverage xml -o /app/cov/coverage.xml" ] +CMD [ "sh", "-c", "coverage run --source=src -m pytest -v && coverage report > /app/cov/coverage.txt && coverage json -o /app/cov/coverage.xml && coverage html -o /app/cov/coverage.html" ] # Stage 4: Migrations diff --git a/config.example.toml b/config.example.toml index 0f41e0e..8a4eb03 100644 --- a/config.example.toml +++ b/config.example.toml @@ -4,7 +4,7 @@ port = 8080 access_log = true [database] -url = "postgresql+psycopg://username:password@host:post/database" +url = "postgresql+psycopg://username:password@host:port/database" [access_token] crypto_key = "..."