Hey team, I have a question on how to approach `en...
# pact-broker
v
Hey team, I have a question on how to approach
environment
in Pactflow. So at our company, we have a quite a few different environments like dev, staging and production and within each of these, we have sub-env like a few dev farms used by devs, production us production eu. When adding
can-i-deploy
and
record-deployment
we are wondering whether which of these is a better approach: • Create seperate environment that replicates all the envs that we have and ensure that we run
can-i-deploy
and
record-deployment
for each of them • Only check
can-i-deploy
to
production
and
record-deployment
for
production
with the reason being
production
is the final destination in our deployment process so as long it is safe to deploy the changes to
production
that it algood. What are your thoughts on these two. I am leaning more towards the second options since it is simpler and can give us same amount of safety. Thank you 👍
t
Is it really simpler to have custom config for production only? I would have thought that your pipeline would know which environment it is deploying to, and so it would be “simpler” to have only one pathway (which did the appropriate
can-i-deploy
,
record-deployment
etc)
It’s much easier to reason about your deployment process if there are no branches in your deployment scripts
v
your pipeline would know which environment it is deploying to
yes it does know which environment it is deploying to. So on branch, we deploy only to development and on master we deploy to development, staging and production
Is it really simpler to have custom config for production only?
so it is simpler in the sense that we would only need to check can-i-deploy once for production cause as long as it works for production, it should give us enough confidence. Otherwise we would need to do can-i-deploy and record-deployment for every single environment when we mainly care about production
t
Right, but in terms of risk reduction: 1) if you set up the use of can-i-deploy etc incorrectly, then you’d catch it before production. 2) your pipeline will be simpler and safer as it won’t have branches for
if( env == "production")
v
I am not sure if I get your point on the above but here is how we are setting it up in our pipeline
for non-main branch
pact publish
=>
can-i-deploy
to
production
=> if yes,
deploy to development env
(we dont record deployment here)
t
The point generally is that a pipeline should be a pipeline of steps. Like A -> B -> C -> D. It shouldn’t be A -> B -> if (some condition) then -> C otherwise -> D
👍 1
v
for main branch
pact publish
=>
can-i-deploy
to
production
=> if yes,
deploy to all envs
=> once production deployment is done =>
record deployment for production
t
Yep. I understand. My thoughts are - try not to do it that way if you can avoid it
In this pipeline-oriented model, you might have
if( condition ) then fail
but ideally no / few other branches.
shouldn’t
deploy to all envs
be
deploy to production
in your example?
v
deploy to all envs
covers our production deployment as well since any merge to master, we would want to keep all envs (dev, staging, and production) up to date
t
hmmmmm
v
on branch we only want to deploy our apps to development
t
This sounds unnecessarily complicated
if you deploy to all envs, then you’d lose the ability to reason about what’s in there (since presumably there are other ways to deploy to each env)
so a production deploy might actually break some of the other envs
Usually, dev and staging are newer than production
v
Usually, dev and staging are newer than production
yeap I get your point. For us though, we got a thing called branch preview so any commit on branch is deployed and any deployed from master to development does not overwrite any of the branch preview - devs can still continue to check their changes on branch preview without getting affected by merge to master
t
hmm. Is the master deploy the only way to get a main deploy in dev / staging?
v
yeap same for production
t
Right, so, from Pact’s perspective dev(main) and staging(main) and production are all “production”
So you would be using
can-i-deploy
in that case
but not for the branch deploys
I would say that is fine
I think you’ll have problems if you start having other ways to deploy
dev(main)
or
staging(main)
👍 1
and probably if you’re doing branch deploys, people are manually testing as part of their workflow. You might want to have
can-i-deploy
give them a warning, but not stop deployment, maybe
👍 1
v
yeah we are still adding
can-i-deploy
to branch to check if it is safe to deploy to
production
- mainly as a sanity check before we merge the branch to master because we don’t want a scenario that pipeline only breaks because can-i-deploy fails in production
You might want to have
can-i-deploy
give them a warning, but not stop deployment, maybe
yeap fully agree 👍 I was typing the above reply so didnt see yours
we are just going hardcore to fail the build completely cause warning can be missed easily 😄
t
What I don’t like about this workflow is that it’s surprising that
dev(main)
and
staging(main)
are actually
production
. But if this is what everyone expects, then I guess it’s fine
With branch deploys, it’s common to know that you’re not compatible with production, but still want to deploy
v
dev(main)
and
staging(main)
are
productionish
but no real production traffic is hitting it
t
eg, front ends, where you know the API isn’t available yet, but you want to get someone to look at it
Or where you’ve written a between service client, and are mocking the data while you wait for the next service’s provider to be built
v
eg, front ends, where you know the API isn’t available yet, but you want to get someone to look at it
yeah good point thinking2
t
Personally, in your case (and assuming I’m going for minimal changes to the pipeline), I would: •
can-i-deploy
on main •
can-i-deploy
on PRs to main • no checks on branch deploys
If you go this route I think you must use a merge queue
otherwise you might have a race condition allowing you to land failing
can-i-deploy
in main
v
merge queue
you mean only once merge at once and next merge can be done only when deployment of previous is finished?
No. I mean a feature where PRs added to the merge queue build assuming that everything in front of them has landed
(although your strategy would achieve the same thing but slightly slower)
v
ah right so we have something similar that there is only one deployment being done at the same time for the same branch
👍 1
t
that’s normal
v
I will check out that merge queue thing
t
it’s pretty cool
👍 1
This is an interesting setup. If you get it working well, I reckon it would be worth blogging about.
👍 1
My gut is there will still be problems with the way you’ve got the environments set up, but I can’t actually see any, so I think it’s just a feel-opinion 😂 . What you’ve described sounds fine to me.
😁 1
(at least logically, if not emotionally)
v
haha yeah I was quite skeptical at first too 😄 so wanted to ask the community to see how others who are more experienced with pact like yourself think
we are starting our journey with Pactflow so definitely will have something to share once it is working well 😅
thanks for sharing your knowledge 👍 really appreciate it
t
You’re very welcome!
b
@Viet Anh Tran I don’t have time to read through the whole conversation, but a quick browse of your initial question makes me think that this might be relevant for you https://docs.pact.io/pact_broker/recording_deployments_and_releases#handling-conflicting-views-of-what-an-environment-is
v
thanks for sharing this Beth 👍. I read through this document and listed it as option 1 above. It feels a bit overkill for our set up so will test out option 2 first and see how that goes