What's the best way to roll out a new pacticipant?...
# general
j
What's the best way to roll out a new pacticipant? I've started building our automation around our pact broker, and I've reached the point where our pipeline will fail pull-request builds if
can-i-deploy
for the given service to deploy to
master
fails... But now I've discovered that when build a new pact provider, it fails
can-i-deploy
because it doesn't exist yet as a pacticipant, and when I add new contract tests to a service, it fails because the contract can't yet be verified, so I'm in a bit of a dependency loop. Is the only way out of this dependency loop to do a one-time suspension of my checks to get my provider merged? Am I maybe doing something wrong? (To be clear, currently my script currently checks to see if the pact provider logic has been implemented in the service and if it has, it runs verifications and then the
can-i-deplay
. It doesn't run any pact stuff if it doesn't see the pact provider logic or a pact file in the service)
Actually, as I write this, it occurs to me that maybe the solution lies in just checking if a given service is a pacticipant in the pact broker. Is there an easy way to check that for a given service name?
t
You should always be able to deploy a provider that has no consumers
1
m
You can definitely check if your provider exists -
:host/pacticipants/:name/
will give you the resource of the application if it exists
Tim is right, however with the caveat that can-i-deploy will fail if the application you’re querying doesn’t exist. To create the application, you don’t need a contract - the simplest option is to simply create the application in advance:
curl -X POST <host>/pacticipants -d {"name": "some provider"}
👍 1
j
Perfect, thank you
I'm just changing my verifier job so if you pass it a provider name, the first thing it does is check if that provider already exists, and if it doesn't, it creates it (unless you also passed it a pactfile url, which it interprets as an error, because, honestly I'm not even sure how that would happen, but it was probably a mistake)
👍 1
b
it should just work… so it sounds like something got messed up
👍 1
j
I think it's just as Matt says: I think it's just can-i-deploy pointing out that my pacticipant doesn't exist in the pact broker yet
I just need to improve my pipeline a bit to add the provider as a pacticipant when it's new
I reference that pact_nirvana page often, it's very helpful, haha 👍
🙌 1
b
Great to hear.
Usually, the consumer adds the pacts for the provider first, and that creates the provider.
j
That makes sense, but since the provider should be able to be developed independently if no consumer depends on it, I wanted to create a path in our pipeline for that as well
b
Cool. Yeah, that page I sent will cover your scenario.
👍 2
j
Oh I hadn't thought of just adding every service-version to the pact broker even without contracts, but that's real smart. Thanks for the tip!
👍 1
👍🏼 1
Copy code
docker run --network host pactfoundation/pact-cli broker can-i-deploy --retry-while-unknown=60 --retry-interval=10 --pacticipant=test-service --version=430ff0f --to-environment=master

Computer says no ¯_(ツ)_/¯

No pacts or verifications have been published for version 430ff0f of test-service
Bummer... I thought if a provider had no pacts, it should be safe to deploy? Do I need to specify some other option?
b
If you’re not publishing any pacts or verifications, you need to make the pacticipant version explicitly using
Copy code
pact-broker create-or-update-version --pacticipant ${APPLICATION_NAME} --version ${GIT_SHA} --branch ${GIT_BRANCH}
It knows about the pacticipant, but not the version.
j
Oh, I have to publish the version for the provider too, so it can see that it exists and knows that there is no consumer to connect it to?
Sorry if you said this already, but do I have to do it as two separate commands, or will
create-or-update-version
also create the pacticipant if it doesn't exist?
1
From that pact_nirvana page you linked above, it looks like the one command may be enough, but I may be mis-reading it
m
yep, it should do both
thank you 1
👍 1