NOTE: If you're new to Pact and have landed here, it's probably not what you want. If you simply want a Dockerized version of the verifier, the official Docker container for all Pact libraries is: https://github.com/pact-foundation/pact-ruby-cli.
This setup simplifies Pact Provider verification process in any language, by running the Pact Rake tasks in a separate Docker container.
Features:
- Verify Pacts against Pacts published to a Pact Broker
- Verify local
*.json
Pacts for testing in a development environment - Pre-configured Docker image with Ruby installed and a sane, default
src/Rakefile
keeping things DRY - Works with Pact provider states should you need them
- Docker
- Docker Compose
- Working Dockerfile for your API
Steps:
- Create an API and a corresponding Docker image for it
- Publish Pacts to the Pact broker (or create local ones)
- Create a
docker-compose.yml
file connecting your API to the Pact Verifier - Set the following required environment variables:
pact_urls
- a comma delimited list of pact file urlsprovider_base_url
- the base url of the pact provider (i.e. your API)
- Run
docker-compose build
and thendocker-compose up
api:
build: .
command: npm start
ports:
- "4000:4000"
pactverifier:
image: dius/pact-provider-verifier-docker
links:
- api:api
volumes:
- ./pact/pacts:/tmp/pacts # If you have local Pacts
environment:
- pact_urls=http://pact-host:9292/pacts/provider/MyAPI/consumer/MyConsumer/latest
#- pact_urls=/tmp/pacts/foo-consumer.json # If you have local Pacts
- provider_base_url=http://api:4000
Execute pact provider verification against a provider which implements the following:
-
an http get endpoint which returns pact provider_states by consumer
{ "myConsumer": [ "customer is logged in", "customer has a million dollars" ] }
-
an http post endpoint which sets the active pact consumer and provider state
consumer=web&state=customer%20is%20logged%20in
The following environment variables required:
pact_urls
- a comma delimited list of pact file urlsprovider_base_url
- the base url of the pact providerprovider_states_url
- the full url of the endpoint which returns provider states by consumerprovider_states_active_url
- the full url of the endpoint which sets the active pact consumer and provider state
$ bundle install
$ bundle exec rake verify_pacts
api:
build: .
command: npm run-script pact-provider
ports:
- "4000"
pactverifier:
image: dius/pact-provider-verifier-docker
links:
- api
environment:
- pact_urls=http://pact-host:9292/pacts/provider/MyProvider/consumer/myConsumer/latest
- provider_base_url=http://api4000:
- provider_states_url=http://api:4000/provider-states
- provider_states_active_url=http://api:4000/provider-states/active