From d105234d7aa50f85ad58b8f43220c660b139e4c0 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Wed, 13 Nov 2024 22:41:45 +0000 Subject: [PATCH 1/6] chore(deps): update app deps + native verifier --- Dockerfile | 11 +++++++++++ Makefile | 30 +++++++++++++++++++++++++++++- docker-compose.yml | 30 ++++++++++++++++++++++++------ requirements.txt | 4 ++-- 4 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f9f70fd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.11 + +WORKDIR /code + +COPY ./requirements.txt /code/requirements.txt + +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt + +COPY ./app /code/app + +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/Makefile b/Makefile index cdf6bbd..5997983 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,9 @@ fake_ci_webhook: test: .env docker-compose up --abort-on-container-exit --exit-code-from pact_verifier docker-compose logs pact_verifier +test_native: .env + docker-compose up --abort-on-container-exit --exit-code-from pact_verifier_native + docker-compose logs pact_verifier_native ## ===================== ## Deploy tasks @@ -108,6 +111,31 @@ test_pact_changed_webhook: ## ====================== ## Misc ## ====================== - +PROJECT := example-provider-python +PYTHON_MAJOR_VERSION := 3.11 +sgr0 := $(shell tput sgr0) +red := $(shell tput setaf 1) +green := $(shell tput setaf 2) .env: touch .env + + +venv: + @if [ -d "./.venv" ]; then echo "$(red).venv already exists, not continuing!$(sgr0)"; exit 1; fi + @type pyenv >/dev/null 2>&1 || (echo "$(red)pyenv not found$(sgr0)"; exit 1) + + @echo "\n$(green)Try to find the most recent minor version of the major version specified$(sgr0)" + $(eval PYENV_VERSION=$(shell pyenv install -l | grep "\s\s$(PYTHON_MAJOR_VERSION)\.*" | tail -1 | xargs)) + @echo "$(PYTHON_MAJOR_VERSION) -> $(PYENV_VERSION)" + + @echo "\n$(green)Install the Python pyenv version if not already available$(sgr0)" + pyenv install $(PYENV_VERSION) -s + + @echo "\n$(green)Make a .venv dir$(sgr0)" + ~/.pyenv/versions/${PYENV_VERSION}/bin/python3 -m venv ${CURDIR}/.venv + + @echo "\n$(green)Make it 'available' to pyenv$(sgr0)" + ln -sf ${CURDIR}/.venv ~/.pyenv/versions/${PROJECT} + + @echo "\n$(green)Use it! (populate .python-version)$(sgr0)" + pyenv local ${PROJECT} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9bc7762..36d3031 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,7 @@ -version: "3" - services: api: - image: tiangolo/uvicorn-gunicorn-fastapi:python3.7 + build: + context: . volumes: - ./app:/app expose: @@ -28,6 +27,25 @@ services: ${PACT_URL} --provider-base-url http://api:8000 --provider pactflow-example-provider-python - --provider-app-version ${GIT_COMMIT} - --provider-version-tag ${GIT_BRANCH} - --wait 10 \ No newline at end of file + --wait 10 + + pact_verifier_native: + image: pactfoundation/pact-ref-verifier:latest + depends_on: + - api + environment: + - PACT_BROKER_BASE_URL + - PACT_BROKER_TOKEN + - PACT_BROKER_USERNAME + - PACT_BROKER_PASSWORD + - PACT_BROKER_PUBLISH_VERIFICATION_RESULTS + - PACT_WEBHOOK_CALLBACK_URL=${PACT_URL} + - GIT_COMMIT + - GIT_BRANCH + command: > + --hostname api + --port 8000 + --provider-name pactflow-example-provider-python + --loglevel info + --provider-version $GIT_COMMIT + --provider-branch $GIT_BRANCH \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 0885e56..87c06ac 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -fastapi==0.61.1 -uvicorn==0.11.8 +fastapi==0.115.5 +uvicorn==0.32.0 From 76bc50cb7b5edc5c8cf83747273b7adfe33bc2f0 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Wed, 13 Nov 2024 22:43:19 +0000 Subject: [PATCH 2/6] chore: update docker-compose to docker compose (v2 deprecation) --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 5997983..784df81 100644 --- a/Makefile +++ b/Makefile @@ -42,11 +42,11 @@ fake_ci_webhook: ## ===================== test: .env - docker-compose up --abort-on-container-exit --exit-code-from pact_verifier - docker-compose logs pact_verifier + docker compose up --abort-on-container-exit --exit-code-from pact_verifier + docker compose logs pact_verifier test_native: .env - docker-compose up --abort-on-container-exit --exit-code-from pact_verifier_native - docker-compose logs pact_verifier_native + docker compose up --abort-on-container-exit --exit-code-from pact_verifier_native + docker compose logs pact_verifier_native ## ===================== ## Deploy tasks From efb1908b375f38ba770a44864f9a47afd6c81a12 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Wed, 13 Nov 2024 22:47:50 +0000 Subject: [PATCH 3/6] ci: verify provider by consumer version selectors --- .github/workflows/build.yml | 8 ++++---- .github/workflows/verify_changed_pact.yml | 4 ++-- docker-compose.yml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7b50cf2..a23497e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,8 +17,8 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '3.8' architecture: 'x64' @@ -31,7 +31,7 @@ jobs: runs-on: ubuntu-latest needs: test steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: docker pull pactfoundation/pact-cli:latest - name: Can I deploy? run: GIT_BRANCH=${GITHUB_REF:11} make can_i_deploy @@ -41,7 +41,7 @@ jobs: runs-on: ubuntu-latest needs: can-i-deploy steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: docker pull pactfoundation/pact-cli:latest - name: Deploy run: GIT_BRANCH=${GITHUB_REF:11} make deploy diff --git a/.github/workflows/verify_changed_pact.yml b/.github/workflows/verify_changed_pact.yml index 946fea2..8dc58c8 100644 --- a/.github/workflows/verify_changed_pact.yml +++ b/.github/workflows/verify_changed_pact.yml @@ -17,8 +17,8 @@ jobs: verify-changed-pact: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '3.8' architecture: 'x64' diff --git a/docker-compose.yml b/docker-compose.yml index 36d3031..15ea1c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,7 +39,7 @@ services: - PACT_BROKER_USERNAME - PACT_BROKER_PASSWORD - PACT_BROKER_PUBLISH_VERIFICATION_RESULTS - - PACT_WEBHOOK_CALLBACK_URL=${PACT_URL} + # - PACT_WEBHOOK_CALLBACK_URL=${PACT_URL} - GIT_COMMIT - GIT_BRANCH command: > From 4e43d7ec89ff88cf190e48fc1932373dbd060e16 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Wed, 13 Nov 2024 23:05:39 +0000 Subject: [PATCH 4/6] ci: test --- .github/workflows/build.yml | 5 ----- Makefile | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a23497e..608b9f3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,11 +18,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: '3.8' - architecture: 'x64' - - run: pip install -r requirements.txt - name: Test run: GIT_BRANCH=${GITHUB_REF:11} make test diff --git a/Makefile b/Makefile index 784df81..aaeb9f2 100644 --- a/Makefile +++ b/Makefile @@ -42,10 +42,10 @@ fake_ci_webhook: ## ===================== test: .env - docker compose up --abort-on-container-exit --exit-code-from pact_verifier + docker compose up --exit-code-from pact_verifier docker compose logs pact_verifier test_native: .env - docker compose up --abort-on-container-exit --exit-code-from pact_verifier_native + docker compose up --exit-code-from pact_verifier_native docker compose logs pact_verifier_native ## ===================== From 43288df8a727b332dc90b05447de05e97591d7bf Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Wed, 13 Nov 2024 23:19:39 +0000 Subject: [PATCH 5/6] ci: only run one verifier at a time --- .github/workflows/build.yml | 4 +++- Makefile | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 608b9f3..c7be759 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,8 +18,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Test + - name: Test (ruby standalone - docker) run: GIT_BRANCH=${GITHUB_REF:11} make test + - name: Test (native standalone - docker) + run: GIT_BRANCH=${GITHUB_REF:11} make test_native # Runs on branches as well, so we know the status of our PRs can-i-deploy: diff --git a/Makefile b/Makefile index aaeb9f2..945c2c7 100644 --- a/Makefile +++ b/Makefile @@ -42,10 +42,10 @@ fake_ci_webhook: ## ===================== test: .env - docker compose up --exit-code-from pact_verifier + docker compose up pact_verifier --exit-code-from pact_verifier docker compose logs pact_verifier test_native: .env - docker compose up --exit-code-from pact_verifier_native + docker compose up pact_verifier_native --exit-code-from pact_verifier_native docker compose logs pact_verifier_native ## ===================== From e16adbb92c13645115e5b73ac7de6aa66b4364c7 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Wed, 13 Nov 2024 23:23:50 +0000 Subject: [PATCH 6/6] ci: restore version/branch ruby cli --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 15ea1c5..89a3418 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,6 +27,8 @@ services: ${PACT_URL} --provider-base-url http://api:8000 --provider pactflow-example-provider-python + --provider-app-version ${GIT_COMMIT} + --provider-version-branch ${GIT_BRANCH} --wait 10 pact_verifier_native: