diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7b50cf2..c7be759 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,21 +17,18 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 - with: - python-version: '3.8' - architecture: 'x64' - - run: pip install -r requirements.txt - - name: Test + - uses: actions/checkout@v4 + - 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: 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 +38,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/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..945c2c7 100644 --- a/Makefile +++ b/Makefile @@ -42,8 +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 pact_verifier --exit-code-from pact_verifier + docker compose logs pact_verifier +test_native: .env + docker compose up pact_verifier_native --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..89a3418 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: @@ -29,5 +28,26 @@ services: --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 + --provider-version-branch ${GIT_BRANCH} + --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