Configure consumer and provider pipelines
Setup deployment environment
This step should only be required if you have a legacy PactFlow account. New users should automatically have a production account created and can move onto the Configure consumer pipeline step
Create a new production environment to record deployments against
- Log in to your PactFlow account (
https://<your-subdomain>.pactflow.io
), and go to Settings > Environments. - Click Add Environment
- Enter
production
for the name and display name - Check the "this is a production environment" checkbox
- Select the default team
- Click "Create"
Configure consumer pipeline
The source repositories are configured to use the the public broker at test.pactflow.io. You will need to update the credentials to point to your own PactFlow account. To do this, we need to update the PACT_BROKER_BASE_URL
environment variable in the Github workflow file, and create a Github Secret to store the PactFlow API token in.
- Create a Github Secret to store your PactFlow API token in.
- In PactFlow:
- Log in to your PactFlow account (
https://<your-subdomain>.pactflow.io
), and go to Settings > API Tokens. - Click the Copy button for the read/write CI token (make sure it's the read write one, not the read only one).
- Log in to your PactFlow account (
- In Github:
- Open your forked
example-consumer
project (https://github.com/<your-username>/example-consumer
) - Click on the
Settings
tab. - Open the
Secrets and variables
dropdown in the side menu. - Select Actions from the dropdown
- Click the
New repository secret
button - Set the name of the secret to
PACTFLOW_TOKEN_FOR_CI_CD_WORKSHOP
- Paste in the PactFlow API token value you copied in the previous step.
- Open your forked
- In PactFlow:
- Update your workflow files in GitHub to point at your PactFlow Broker
- In PactFlow:
- Go to Settings > API Tokens.
- Click the
COPY PACTFLOW BASE URL
button
- In Github:
- Open your forked
example-consumer
project (https://github.com/<your-username>/example-consumer
)- Open
.github/workflows/build.yml
- In the upper right corner of the file view, click 🖊️ to open the file editor.
- Update the value of
PACT_BROKER_BASE_URL
to the base URL of your own PactFlow account. You can easily get this by clicking the COPY PACTFLOW BASE URL button on the API Tokens page in PactFlow. - Press the green
Commit changes
button
- Open
- Open your forked
- In PactFlow:
- View the build:
- In Github:
- Select the most recent build, this will have been triggered when you committed the changes in the last page
- In Github:
This build should now successfully publish the pact, but it will fail on the can-i-deploy
step before it tries to deploy.
This is because the provider has not published a successful verification result for the pact.
Configure provider pipeline
🔁 Repeat the above instructions to configure the PactFlow account for your provider project.
⚠️ There are TWO workflow files to be updated in the provider project - .github/workflows/build.yml
, .github/workflows/contract_requiring_verification_published.yml
.
After you have pushed your changes to the workflow files, the provider pipeline will run, fetching and verifying the configured pacts from your PactFlow account, and publishing the results back. The can-i-deploy
command will pass, and allow the provider to be deployed. ✅
Back to the consumer
✅ To make both your builds go green, we are going to retry can-i-deploy, now that the consumer is deployed to production.
- Find the latest failing
example-consumer
workflow in the Github Actions page (Actions
-> UnderWorkflows
, selectBuild
->failing build
). - In the top right on of the failing job page, select to Re-run the failed jobs (can-i-deploy) (
Actions
-> UnderRe-run jobs
, selectRe-run failed jobs
). - The test run should be pre-passing
- The
can-i-deploy
step should now pass - our consumer is safe to deploy, now that our provider published a verification result, and is deployed to production- If you click on the step you should see a successful verification result, and
Computer says yes \o/
- If you click on the step you should see a successful verification result, and
- The
deploy
step should pass too - our consumer is deployed to production, and we record this with therecord-deployment
command, marking this application version of our consumer as deployed toproduction
Expected state by the end of this step
- Both consumer and provider builds passing ✅