pact-foundation/pact_broker-client

--tag-with-git-branch does only work for branches without "/"

schowave opened this issue · 6 comments

Currently the flag "--tag-with-git-branch" only works when the git branch name has no "/" included.
So "develop" works, but "feature/ABC" does not work.

Seems, that the "tag-with-git-branch" flag does work, but the broker will not accept it

Hi @schowave if you have a reverse proxy like ngnix in front of your Broker, sometimes there is an issue where it unescapes the slash, and that cause the tag to go to the wrong URL.

Hi @bethesque: Great hint! With our current reverse proxy configuration, I worked around this issue, by replacing the "/" with %2F and then the contract is published correctly. But actually I should adapt the nginx configuration somehow.

This is the scripts in the package json

"pact-env-git-branch": "echo BRANCH_NAME=> pact/.env.git.branch && git rev-parse --abbrev-ref HEAD >> pact/.env.git.branch && replace-in-files --string='/' --replacement='%2F' pact/.env.git.branch && replace-in-files --regex='\\r\\n' --replacement='' pact/.env.git.branch && replace-in-files --regex='\\n' --replacement='' pact/.env.git.branch",

And the publish script:

"pact-publish": "npm run pact-env-git-branch && dotenv -e pact/.env.git.branch -e .env.pact.local -e .env.pact -- cross-var pact-broker publish %PACT_DIRECTORY% --tag=%BRANCH_NAME% --consumer-app-version=%CONSUMER_VERSION% --broker-base-url=%PACT_BROKER_BASE_URL% --broker-username=%PACT_BROKER_USERNAME% --broker-password=%PACT_BROKER_PASSWORD%",

This works, but there is some other problem with the generated webhook and the bitbucket job in our jenkins machine. The webhook is generated e.g. ...feature%2Fmy-feature... in the URL, but the job name runs under ...feature%252Fmy-feature... . Is this maybe also a reverse proxy issue?

The Broker runs as docker container with the following docker-compose configuration:

version: "3"

services:
postgres:
image: postgres
healthcheck:
test: psql postgres --command "select 1" -U postgres
ports:
- "5433:5432"
environment:
POSTGRES_USER: XXX
POSTGRES_PASSWORD: XXX
POSTGRES_DB: postgres
volumes:
- pgdata:/var/lib/postgresql/data

broker_app:
image: pactfoundation/pact-broker:2.79.1.0
links:
- postgres
ports:
- 9292:9292
environment:
PACT_BROKER_BASIC_AUTH_USERNAME: XXX
PACT_BROKER_BASIC_AUTH_PASSWORD: XXX
PACT_BROKER_BASIC_AUTH_READ_ONLY_USERNAME: XXX
PACT_BROKER_BASIC_AUTH_READ_ONLY_PASSWORD: XXX
PACT_BROKER_DATABASE_USERNAME: XXX
PACT_BROKER_DATABASE_PASSWORD: XXX
PACT_BROKER_DATABASE_HOST: XXX
PACT_BROKER_DATABASE_NAME: XXX
PACT_BROKER_BASE_URL: "https://XXX/pact/"

volumes:
pgdata:


And the following nginx configuration:


server {
server_name XXXX;
listen 443 ssl;
ssl_certificate /etc/ssl/XXXX/XXXX.pem;
ssl_certificate_key /etc/ssl/XXXX.de/XXXX.key;
location ~ ^/pact(.*)$ {
proxy_pass http://127.0.0.1:9292$1;
proxy_set_header Host $host:9292;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Rewrite HTTPS requests from WAN to HTTP requests on LAN
proxy_redirect http:// https://;
}
}

Very soon, there will be a new all in one endpoint for publishing pacts that does not put the tag name in a URL. That will completely sidestep the issue. If you follow this feature, you'll get a notification when it's released.

https://pact.canny.io/feature-requests/p/create-an-all-in-one-endpoint-for-publishing-contracts

I"m not sure about the webhook issue. See if you can recreate it using this https://github.com/pact-foundation/pact_broker/blob/master/ISSUES.md

I solved the webhook issue, by correcting the jenkins nginx directive as described here:

https://www.jenkins.io/doc/book/system-administration/reverse-proxy-configuration-nginx/

Actually it was not an issue with the pact broker but with the reverse proxy configuration for jenkins build server.

And now the triggering of the webhooks works, thank you for your help!