Hi all, i am wondering about how to properly use c...
# pact-broker
b
Hi all, i am wondering about how to properly use can-i-deploy and would like to hear your take on this_._ This question is for the Consumer side. Context: Contract is between • 2 mobile consumer • 1 web consumer • 1 provider • the mobile apps need to be back wards compatible for N amount of app releases • The Broker is set-up per feature, this means we will have multiple brokers in our cluster Pact tools to use • Can-I-Deploy • Publish • Recordings Currently we are implementing everything in the pipeline. The plan is to make sure all contracts are verified when we want to do a merge. We think we need to use Can-I-Deploy for this, but it feels like that is not how it should work. The reason we think that is because Can-I-Deploy seems to only work for 1 single pacticipant at the time, we know you can give multiple pacticipants like this.
Copy code
pact-broker \
can-i-deploy \
--pacticipant=IOSConsumer \
--latest
--pacticipant=AndroidConsumer \
--latest
--broker-base-url=<https://pact-broker.com/feature> \
--to-environment=PROD
But it feels like a lot of maintenance to always have all your pacticipants up to date. So in short, which answer applies most 1. We are mis-using Can-I-Deploy. 2. We are doing it right and should take care of managing all the pacticipants on multiple brokers. 3. We Should run all pacticipants of one broker at once, and we missed some pact functionality
m
There are multiple things I think wrong here
> • The Broker is set-up per feature, this means we will have multiple brokers in our cluster what does this mean? Generally you just want one broker to model it all. What problem are you trying to solve by having many?
pact-broker \
can-i-deploy \
--pacticipant=IOSConsumer \
--latest
--pacticipant=AndroidConsumer \
--latest
--broker-base-url=https://pact-broker.com/feature \
--to-environment=PROD
you should never use the
--latest
really, because that makes things non-deterministic (how do you know “latest” is the thing you want to deploy? Maybe the latest thing published was some branch for a WIP thing which passes, but not the latest for
main
branch which just happened to be published a few minutes before).
In your case, for the mobile applications you need to use record-release (not deployment): https://docs.pact.io/pact_broker/recording_deployments_and_releases. This will allow you to track the last n versions of any dependencies for your consumers
The plan is to make sure all contracts are verified when we want to do a merge.
You seem to be implying you merge all of the applications (and therefore, contracts) at the same time? If not, you should only consider the application you are merging with
can-i-deploy
(or
can-i-merge
if you want to use that).
The reason we think that is because Can-I-Deploy seems to only work for 1 single pacticipant at the time, we know you can give multiple pacticipants like this.
that’s not true. It can take multiple, but for the reasons you d escribe most people don’t use it that way. You give it the thing you want to deploy, and it checks in the target environment all dependencies will continue to work
b
Hi Matt, tnx for your responses and explanations. We are indeed moving away from --latests, so that was a poor example, we are now also looking into record release, since using tags is not advised. But i can't figure out a way to either, check all the pacts, always, which i think is not common. or "give it the thing we want to deploy" how to check if we can deploy in a CI/CD way without any manual intervention. Just to be sure and clear, we are talking about native mobile apps, not mobile web apps. This is why we want to check everything for everything and the release of all feature will have the same upcoming version. That is why i was saying it feels like we are not using can-i-deploy correctly. because now we require a script to ensure we have a list of all our pacts in all our broker so we can use can-i-deploy for all of them, instead of saying check all for this broker. But yeah, new to pact so perhaps we just have it completely wrong 😅
👍 1
m
For each mobile app you wish to release, you should
pact-broker record-release
. Each one of these are now considered “in production”. When any dependency of that changes (e.g. the
provider
) and wants to release, when it calls
can-i-deploy
it will check all released versions of the mobile app. i.e.
can-i-deploy
figures out what’s in the target environment, and if the app being deployed into it will be compatible
That is why i was saying it feels like we are not using can-i-deploy correctly. because now we require a script to ensure we have a list of all our pacts in all our broker so we can use can-i-deploy for all of them, instead of saying check all for this broker.
yes, definitely you don’t need to do anything like this, unless you have some strange setup. It sounds like a typical mobile use case to me
When you remove a version of the mobile app from the app store, you just need to call
pact-broker record-support-ended
(see https://docs.pact.io/pact_broker/recording_deployments_and_releases#recording-support-ended-for-a-release)
b
okay, but then in my mind, my challenge shifts from testing all pacts, to finding out which pacts changed and put those through can-i-deploy. because one app will have multiple pacts and it's pacticipants. is that correct 🤔 Or is this just a manual task and should not be integrated into CI
m
okay, but then in my mind, my challenge shifts from testing all pacts, to finding out which pacts changed and put those through can-i-deploy. because one app will have multiple pacts and it’s pacticipants. is that correct
I don’t understand why you need to work out which pacts changed? If you’re deploying Application A, simply ask
can-i-deploy
if you can deploy it. Whether or not the contracts have changed is orthogonal to that problem. It will say “OK, you want to deploy
A
into
prod
, let me go and look at all of the dependencies of that in prod and check that you won’t break them and/or they won’t break you” (plus all released versions, in the case of mobile app and the provider is the one asking the question)
b
Well, we are working consumer driven, so we are planning to run
can-i-deploy
from the consumer side (the mobile apps). When you say
Deploying application A
, this means multiple pacts associated to that application right? Therefor the assumption remains that you need to run
can-i-deploy
for all your separate pacts that you have. How else do you make certain all is well?
I think i finally see the light buld appearing over my head. We should use the provider pacticipants when we do
Can-I-Deploy
, not the consumer pacticipants. now indeed it will pick up all the pacticipants and it's versions
b
I mean, you can run
can-i-deploy
(or
can-i-release
) for you deploy/release either side. You should do both, really.
And just to clarify some vocab, a pact is a contract between 2 participants (a single version on each side only). The broker knows all the history it's ever been sent, and that's where all tge reasoning power comes from.
When you say "multiple pacts associated to that application", every version of every pact that has the application as a participant is a potential candidate for checking against. So recording releases, deployments, replacements, and end-of-support all help reducing the candidates to a sensible set.
m
We should use the provider pacticipants when we do
Can-I-Deploy
, not the consumer pacticipants.
yes! or rather, in the consumer build pipeline you add the consumer app that you are deploying. In the provider build pipeline you add the provider app that you are deploying. in general - you specify the pacticipant you are deploying in can I deploy. Think of saying it in English to your team mate “That work on ApplicationX is done, can I deploy it to production?” That’s effectively what can-i-deploy is for
b
Cool, sorry it took me that long to figure out. I will look into how to record-release to all pacts in CI I might be back with some more questions 🤭
🙏 2
m
No worries!
If you haven’t run https://docs.pactflow.io/docs/workshops/ci-cd/ before, I’d suggest doing so. The only difference, essentially, is that you need to using releases instead of deployments, and you need to
record-support-ended
when you deprecate a mobile version.