This demo will walk you through the following steps:
- Starting a provider service (express API)
- Running a consumer application (node client)
- Publishing a contract by a consumer
- Exercising the contract against a provider
- The Provider builds a service
- The Consumer integrates with it and has now a dependency on part of the Provider service
- The Consumer specifies its dependency in a suite of Contract Tests, in a technology of their choosing
- The Consumer publishes the image
- The Provider picks up the image and runs it in a container, passing pre-defined variables (hostname, etc)
- The Provider subscribes to new versions of the image and runs it on every new version
- Docker
This is an animal service with a single endpoint GET \{animal} returning a JSON body. In this section we will start the service and exercise its endpoint.
Start the Provider service:
make provider
This will build a Docker image for the Provider and start a container.
At this point, the server is running. In order to simulate a real-life scenario of the server running in the cloud, a tunneling service (ngrok) has been used. The output will give you a publicly accessible endpoint for the service (e.g. https://c0587a05.ngrok.io)
You can exercise the endpoint in the following way:
curl https://c0587a05.ngrok.io/dog
You should see the following response:
{
"family": "mamal",
"sounds": "woof!",
"famousMember": "Odie"
}
The Consumer is an application relying on the Provider for it's functionality. In this section we will run the consumer client application, as well as run contract tests against the provider.
The consumer application needs the provider's endpoint. It'll be read from the Provider container and passed through an environment variable. Run the Consumer client:
make consumer
This command builds a consumer image and runs the container, passing in the endpoint as an environment variable. The variable is read from the Provider container.
You should see a similar output to this:
Duck is a bird and it makes quack quack!
In this section, we will do the following:
- (Consumer) Build and publish the contract test Docker image
- (Provider) Start the container and run the contract tests against the instance
Go to the contract folder:
make contract-build
This will build a Docker image with the contract tests in it.
Start a container to run the contract tests and pass the PROVIDER_URL variable:
make contract-run
Similar as before - the variable is read from the Provider container.
You should see an output similar to this:
PASS tests/duck.test.js
Animal service
✓ should describe a duck (569ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.986s
Ran all test suites.