Skip to content

Commit ddcc78e

Browse files
committed
docs: Improve documentation about deploy checks
1 parent d72f2a0 commit ddcc78e

1 file changed

Lines changed: 63 additions & 6 deletions

File tree

packages/documentation/docs/deployment-checks.md

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,73 @@ sidebar_position: 5.5
44

55
# Deployment checks
66

7-
Currently, deployment checks are performed using the [Pact Broker CLI](https://docs.pact.io/pact_broker/client_cli/readme). For example:
7+
Once you've defined and verified your contracts, you can use the verification status to determine if it is safe to deploy. This is the main value of contract testing - deployment checks prevent you from deploying a broken or untested combination.
8+
9+
You can use the ContractCase CLI to determine if it is safe to deploy:
810

911
```bash
10-
pact-broker can-i-deploy --pacticipant $YOUR_SERVICE_NAME --version $YOUR_SERVICE_VERSION --to-environment $YOUR_ENVIRONMENT
12+
npx @contract-case/cli can-deploy $YOUR_SERVICE_VERSION \
13+
--environment $TARGET_ENVIRONMENT
1114
```
1215

13-
On successful deployment, you will need to tell the broker that you deployed:
16+
This will use the inferred current version in the repository. If you are deploying something that isn't the current head of the repository, you can override the version:
1417

18+
you can provide an explicit version:
19+
20+
```bash
21+
npx @contract-case/cli can-deploy $YOUR_SERVICE_VERSION \
22+
--environment $TARGET_ENVIRONMENT \
23+
--override-version $YOUR_SERVICE_VERSION
1524
```
16-
pact-broker record-deployment --environment=$YOUR_ENVIRONMENT --pacticipant=$YOUR_SERVICE_NAME --version=$YOUR_SERVICE_VERSION
17-
```
1825

19-
In the future, ContractCase will have its own way of contacting the Broker for deployment checks and to record deployments.
26+
## How the check works
27+
28+
A deploy check looks at the version(s) of any services already deployed, and
29+
checks whether they have been verified against the service you're deploying.
30+
31+
For the purposes of deploy checks, a failed verification is the same as an
32+
unverified contract. However, they're reported differently, because an
33+
unverified contract might potentially pass if you run the verification.
34+
35+
- If the deploying service is a consumer, the check confirms that the deploying service's providers are all deployed; and that the deploying service's contract(s) have all been verified successfully by the already deployed providers
36+
- If the deploying service is a provider, the check confirms that it is compatible with all the contracts from any already deployed consumers
37+
38+
Your service may be both a consumer and a provider; in this case, it must pass both checks.
39+
40+
Some services are their own consumer and provider - one easy example is a
41+
service that defers work for itself via a queue. The checks are unchanged for
42+
this case - it must have successfully verified the contract for itself.
43+
44+
## Making dramatic changes
45+
46+
Sometimes, you'll want to make a dramatic change to a service, such as renaming an HTTP endpoint.
47+
The safe approach here is to either:
48+
49+
- First deploy a client that can speak to both the old and the new server, or
50+
- First deploy a server that can speak to both the old and the new client
51+
52+
Then, the old version of the other side can be retired in favour of the new.
53+
54+
This approach lets you safely make drastic changes
55+
safely, without breaking the rules of the check.
56+
57+
## Circular dependencies
58+
59+
Circular dependencies aren't a problem for contract testing (although they're often recommended against for other reasons). The approach above for making dramatic changes can help resolve any complexities as you introduce contract testing.
60+
61+
## Initial deployments
62+
63+
From the rules above, you can infer that:
64+
65+
- A consumer can't deploy if its provider has never deployed - because the services it relies on are not there.
66+
- A provider may deploy if its consumer has never deployed, because nothing is relying on it.
67+
68+
For accurate, safe deployment from scratch, you can just deploy the service(s) that nothing relies on first. If your initial design already has a circular dependency, it's safest to evolve your system so that you're not introducing the full cycle at once.
69+
70+
Of course, during initial development (where your service isn't receiving real traffic, and any API designs may be fluid), you could just disable deploy checks.
71+
72+
## Contract testing only exposes these issues
73+
74+
Note that the challenges with initial states and any circular dependencies already exist whether or not you have contract testing. Contract testing just puts a spotlight on incompatible changes.
75+
76+
Many teams are happy with a minute or two of incompatibility in deployment - especially when a service isn't receiving real traffic yet.

0 commit comments

Comments
 (0)