diff --git a/.github/workflows/cron-main-e2e.yml b/.github/workflows/cron-main-e2e.yml index 8a9edea3..21b2c94b 100644 --- a/.github/workflows/cron-main-e2e.yml +++ b/.github/workflows/cron-main-e2e.yml @@ -14,13 +14,11 @@ jobs: ref: main - name: "Build test containers" - run: docker compose build e2e + run: make build - name: "Create environment file" run: env | grep -E '^MPT_' > .env env: - RP_ENDPOINT: ${{ secrets.RP_ENDPOINT }} - RP_API_KEY: ${{ secrets.RP_API_KEY }} MPT_API_BASE_URL: ${{ secrets.MPT_API_BASE_URL }} MPT_API_TOKEN: ${{ secrets.MPT_API_TOKEN }} MPT_API_TOKEN_CLIENT: ${{ secrets.MPT_API_TOKEN_CLIENT }} @@ -28,7 +26,7 @@ jobs: MPT_API_TOKEN_VENDOR: ${{ secrets.MPT_API_TOKEN_VENDOR }} - name: "Run E2E test" - run: docker compose run --service-ports e2e bash -c "pytest -v -p no:randomly --no-cov --reportportal --rp-launch=$RP_LAUNCH --rp-api-key=$RP_API_KEY --rp-endpoint=$RP_ENDPOINT --junitxml=e2e-report.xml tests/e2e" + run: make e2e args="--reportportal --rp-launch=$RP_LAUNCH --rp-api-key=$RP_API_KEY --rp-endpoint=$RP_ENDPOINT" env: RP_LAUNCH: github-e2e-cron-${{ github.ref_name }} RP_ENDPOINT: ${{ secrets.RP_ENDPOINT }} @@ -36,4 +34,4 @@ jobs: - name: "Stop containers" if: always() - run: docker compose down + run: make down diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 56be4bd6..c5ba3a66 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -20,7 +20,7 @@ jobs: fetch-depth: 0 - name: "Build test containers" - run: docker compose build app_test e2e + run: make build - name: "Create environment file" run: env | grep -E '^MPT_' > .env @@ -34,16 +34,15 @@ jobs: MPT_API_TOKEN_VENDOR: ${{ secrets.MPT_API_TOKEN_VENDOR }} - name: "Run validation & test" - run: docker compose run --service-ports app_test + run: make check-all # - name: "Run E2E test" -# run: docker compose run --service-ports e2e bash -c "pytest -v -p no:randomly --no-cov --reportportal --rp-launch=$RP_LAUNCH --rp-api-key=$RP_API_KEY --rp-endpoint=$RP_ENDPOINT --junitxml=e2e-report.xml tests/e2e" +# run: make e2e args="--reportportal --rp-launch=$RP_LAUNCH --rp-api-key=$RP_API_KEY --rp-endpoint=$RP_ENDPOINT" # env: # RP_LAUNCH: github-e2e-${{ github.event_name }}-${{ github.event.pull_request.number || github.run_number }} # RP_ENDPOINT: ${{ secrets.RP_ENDPOINT }} # RP_API_KEY: ${{ secrets.RP_API_KEY }} - - name: "Run SonarCloud Scan" uses: SonarSource/sonarqube-scan-action@master env: @@ -52,4 +51,4 @@ jobs: - name: "Stop containers" if: always() - run: docker compose down + run: make down diff --git a/.github/workflows/push-release-branch.yml b/.github/workflows/push-release-branch.yml index 91e1b290..ff91bbfb 100644 --- a/.github/workflows/push-release-branch.yml +++ b/.github/workflows/push-release-branch.yml @@ -22,7 +22,7 @@ jobs: fetch-depth: 0 - name: "Build test containers" - run: docker compose build app_test e2e + run: make build - name: "Create environment file" run: env | grep -E '^MPT_' > .env @@ -36,16 +36,15 @@ jobs: MPT_API_TOKEN_VENDOR: ${{ secrets.MPT_API_TOKEN_VENDOR }} - name: "Run validation & test" - run: docker compose run --service-ports app_test + run: make check-all - name: "Run E2E test" - run: docker compose run --service-ports e2e bash -c "pytest -v -p no:randomly --no-cov --reportportal --rp-launch=$RP_LAUNCH --rp-api-key=$RP_API_KEY --rp-endpoint=$RP_ENDPOINT --junitxml=e2e-report.xml tests/e2e" + run: make e2e args="--reportportal --rp-launch=$RP_LAUNCH --rp-api-key=$RP_API_KEY --rp-endpoint=$RP_ENDPOINT" env: RP_LAUNCH: github-e2e-${{ github.event_name }}-${{ github.event.pull_request.number || github.run_number }} RP_ENDPOINT: ${{ secrets.RP_ENDPOINT }} RP_API_KEY: ${{ secrets.RP_API_KEY }} - - name: "Run SonarCloud Scan" uses: SonarSource/sonarqube-scan-action@master env: @@ -54,4 +53,4 @@ jobs: - name: "Stop containers" if: always() - run: docker compose down + run: make down diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a938e17d..20d1d2ac 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,7 @@ jobs: fetch-depth: 0 - name: "Build test containers" - run: docker compose build e2e + run: make build - name: "Create environment file" run: env | grep -E '^MPT_' > .env @@ -35,9 +35,9 @@ jobs: MPT_API_TOKEN_VENDOR: ${{ secrets.MPT_API_TOKEN_VENDOR }} - name: "Run E2E test" - run: docker compose run --service-ports e2e bash -c "pytest -v -p no:randomly --no-cov --reportportal --rp-launch=$RP_LAUNCH --rp-api-key=$RP_API_KEY --rp-endpoint=$RP_ENDPOINT --junitxml=e2e-report.xml tests/e2e" + run: make e2e args="--reportportal --rp-launch=$RP_LAUNCH --rp-api-key=$RP_API_KEY --rp-endpoint=$RP_ENDPOINT" env: - RP_LAUNCH: github-e2e-cron-main + RP_LAUNCH: github-e2e-release-${{ github.ref_name }} RP_ENDPOINT: ${{ secrets.RP_ENDPOINT }} RP_API_KEY: ${{ secrets.RP_API_KEY }} diff --git a/dev.Dockerfile b/Dockerfile similarity index 52% rename from dev.Dockerfile rename to Dockerfile index 4166009a..034285b4 100644 --- a/dev.Dockerfile +++ b/Dockerfile @@ -1,13 +1,18 @@ -FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim +FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS base -COPY . /mpt_api_client -WORKDIR /mpt_api_client +WORKDIR /extension RUN uv venv /opt/venv ENV VIRTUAL_ENV=/opt/venv ENV PATH=/opt/venv/bin:$PATH +FROM base AS build + +COPY . /extension + RUN uv sync --frozen --no-cache --all-groups --active +FROM build AS dev + CMD ["bash"] diff --git a/README.md b/README.md index 48d911c6..8d9f275c 100644 --- a/README.md +++ b/README.md @@ -53,15 +53,13 @@ uv add -r requirements.txt Run all validations with: ```bash -docker compose run --rm app_test +make test-all ``` Run pytest with: ```bash -pytest tests/unit -pytest tests/e2e -pytest tests/seed +make test-all ``` ## License diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 00000000..f4220a94 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,12 @@ +services: + app: + container_name: mtp_api_client + build: + context: . + target: dev + dockerfile: Dockerfile + working_dir: /mpt_api_client + volumes: + - .:/mpt_api_client + env_file: + - .env diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 95a96d77..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,38 +0,0 @@ -services: - app: - container_name: mpt_api_client - build: - context: . - dockerfile: prod.Dockerfile - working_dir: /mpt_api_client - stdin_open: true - tty: true - volumes: - - .:/mpt_api_client - env_file: - - .env - - bash: &dev_base - image: mpt_api_client_dev - build: - context: . - dockerfile: dev.Dockerfile - working_dir: /mpt_api_client - stdin_open: true - tty: true - volumes: - - .:/mpt_api_client - env_file: - - .env - - app_test: - <<: *dev_base - command: bash -c "ruff format --check . && ruff check . && flake8 . && mypy . && uv lock --check && pytest tests/unit" - - format: - <<: *dev_base - command: bash -c "ruff check . --select I --fix && ruff format ." - - e2e: - <<: *dev_base - command: bash -c "pytest -p no:randomly --junitxml=e2e-report.xml tests/e2e" diff --git a/makefile b/makefile new file mode 100644 index 00000000..a30016b4 --- /dev/null +++ b/makefile @@ -0,0 +1,48 @@ +.PHONY: bash build check check-all down format review test help + +DC = docker compose -f compose.yaml + +help: + @echo "Available commands:" + @echo " make bash - Open a bash shell in the app container." + @echo " make build - Build images." + @echo " make check - Check code quality with ruff." + @echo " make check-all - Run check and tests." + @echo " make down - Stop and remove containers." + @echo " make e2e - Run e2e test." + @echo " make format - Format code." + @echo " make review - Check the code in the cli by running CodeRabbit." + @echo " make test - Run tests." + @echo " make help - Display this help message." + +bash: + $(DC) run --rm -it app bash + +build: + $(DC) build + +check: + $(DC) run --rm app bash -c "ruff format --check . && ruff check . && flake8 . && mypy . && uv lock --check" + +check-all: + make check + make test + +down: + $(DC) down + +format: + $(DC) run --rm app bash -c "ruff check --select I --fix . && ruff format ." + +review: + coderabbit review --prompt-only + +test: + $(DC) run --rm app pytest $(args) tests/unit + +test-all: + make test + make e2e + +e2e: + $(DC) run --rm app pytest -p no:randomly --junitxml=e2e-report.xml $(args) tests/e2e