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..63280d3 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,50 @@ 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 + - | + ( + while true; do + docker compose -f compose.yaml $PROFILES logs -f 2>&1 + sleep 1 + done + ) | tee -a compose.log & + - LOGS_PID=$! + - | + REGISTRY_PREFIX=$CI_REGISTRY_IMAGE \ + docker compose -f compose.yaml -f compose.prod.yaml \ + $PROFILES up -d --quiet-pull --quiet-build 2>&1 | tee compose.log + - | + TEST_CONTAINER_ID=$(docker compose -f compose.yaml $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 -f compose.yaml -f compose.prod.yaml $PROFILES 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..dc8d697 100644 --- a/config.example.toml +++ b/config.example.toml @@ -4,8 +4,12 @@ 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 = "..." expires_in = 86400 + +[yandex_oauth] +client_id = "..." +client_secret = "..." diff --git a/infrastructure/configs/backend/config.toml b/infrastructure/configs/backend/config.toml index a647c4c..8128764 100644 --- a/infrastructure/configs/backend/config.toml +++ b/infrastructure/configs/backend/config.toml @@ -9,3 +9,7 @@ url = "postgresql+psycopg://postgres:postgres@postgres:5432/postgres" [access_token] crypto_key = "insecure_token" expires_in = 86400 + +[yandex_oauth] +client_id = "..." +client_secret = "..."