Skip to main content

Environments and deployments

Can-i-deploy answers "is it safe to deploy this version to production?" To answer, Apiome has to know what runs in production now. You tell it with environments and deployment records: create each environment once, then have your deploy job record every deployment or release. The pact-broker CLI does this against Apiome unchanged, and the Environments page does it in the app.

The Environments pages show what is recorded — which version runs where, each environment's deployment history — and simulate a deployment before you make it. What is recorded here is also used by the deployed, released and environment consumer-version selectors, so a provider verifies the pacts of the consumer versions that are really in production.

Before you start​

  • Your pacts are published to Apiome, so the versions you record exist. A deployment can only be recorded for a version Apiome already has.
  • Set PACT_BROKER_BASE_URL to your workspace's broker base URL (https://api.apiome.dev/v1/tenants/<workspace>/pact-broker) and PACT_BROKER_TOKEN to an API key. Create the key on API keys for a member with the Editor role: it can create environments and record deployments.

Create your environments​

In the app​

You need Pacts → Create.

  1. In the rail, under Ship, click Contracts, then the Environments tab.
  2. Click New environment.
  3. In Display name, type the name people read, such as Production EU. Name fills in as you type (production-eu); change it if your deploy jobs use another. It is one word, with no spaces.
  4. Turn on Production for a production environment. It is marked red everywhere, and verification never sends requests that change data there.
  5. Turn on Contracts required to make can-i-deploy refuse a version that has no verified contract here.
  6. Optional: in Contact and Contact email, say who looks after it (Platform team, platform@acme.dev).
  7. Click Create environment.
The New environment dialog: Display name Production EU, Name production-eu, the Production and Contracts required switches on, Contact Platform team with platform@acme.dev, and The same, from anywhere showing apiome pact create-environment --name production-eu --display-name 'Production EU' --production --contract-required.The New environment dialog: Display name Production EU, Name production-eu, the Production and Contracts required switches on, Contact Platform team with platform@acme.dev, and The same, from anywhere showing apiome pact create-environment --name production-eu --display-name 'Production EU' --production --contract-required.
Route/ade/dashboard/pacts/environments

A field the workspace would refuse says so under it before anything is sent — a name with a space, or one another environment already has. The same, from anywhere shows the apiome pact create-environment command for what you filled in; the Pact CLI pill leaves out --contract-required, which only Apiome has.

To change an environment, click ⋯ on its row in Environments, then Edit environment. Saving replaces every field. Contacts the dialog does not show (a second contact, say) are kept as they are, and the dialog says so. Renaming keeps every deployment. No apiome pact command changes an environment yet, so The same, from anywhere shows the REST request. You need Pacts → Edit.

To delete one, click ⋯ → Delete environment (Pacts → Delete). While any version is deployed or released there, the dialog says so — “Production still has 9 versions running.” — and offers no delete. Record their undeployment or end their support first.

From a script​

Create each environment once, for example from a setup script:

pact-broker create-environment --name test --display-name Test
pact-broker create-environment --name production --display-name Production --production
FieldWhat it is
nameThe name your deploy jobs use (production). One word, no spaces, unique in the workspace.
displayNameThe name people read (Production). The name is used when you leave it out.
productionWhether this is a production environment. Defaults to false.
contractRequiredApiome only. When true, can-i-deploy to this environment refuses a version that has no contract. Defaults to false.
contactsWho to contact about the environment: [{"name": "Team Ledger", "details": {"emailAddress": "…"}}].

pact-broker list-environments lists them with their uuid. Use the uuid with describe-environment, update-environment and delete-environment. Renaming an environment keeps its deployments, because they refer to it by uuid. Deleting an environment deletes every deployment and release recorded to it, and cannot be undone.

Set contractRequired with the API, since the CLI has no flag for it:

curl -X PUT "$PACT_BROKER_BASE_URL/environments/<uuid>" \
-H "Authorization: Bearer $PACT_BROKER_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "production", "displayName": "Production", "production": true, "contractRequired": true}'

A PUT replaces every field, so send the ones you want to keep.

Record a deployment​

Add this to your deploy job, after the deployment succeeds:

pact-broker record-deployment \
--pacticipant "Ledger API" \
--version "$GIT_COMMIT" \
--environment production
  • The deployment replaces the one before it. The version deployed to that environment before is marked as no longer deployed. It stays in the history, with the time it was replaced.
  • Recording the same version again changes nothing. The answer is 200 with the existing deployment instead of 201.
  • The version must already be recorded, by publishing a pact or verifying one. Otherwise the CLI reports <pacticipant> version <version> not found.

Application instances​

Some environments run more than one copy of an application at once: one per region, or one per customer. Name the copy with --application-instance:

pact-broker record-deployment --pacticipant "Ledger API" --version 4f1e2d0 \
--environment production --application-instance eu-1

A deployment then only replaces the previous deployment to the same instance. Deploying to eu-1 leaves us-1 running its own version, and both count as deployed. Leave the instance out when the environment has one copy.

Record an undeployment​

When you take an application out of an environment without deploying another version, record it:

pact-broker record-undeployment --pacticipant "Ledger API" --environment production

Add --application-instance eu-1 to take only that copy out. You do not need to record an undeployment when you deploy a new version: record-deployment does that for you. apiome pact record-undeployment takes the same flags, and the Environments board's column menu has Record an undeployment (in the app).

Record a release​

Use a release instead of a deployment for an application where several versions are in use at once, such as a mobile app or a library: releasing 2.0 does not replace 1.0.

pact-broker record-release --pacticipant "Billing App" --version 2.0.0 --environment app-store

Every released version stays supported until you record that support has ended:

pact-broker record-support-ended --pacticipant "Billing App" --version 1.0.0 --environment app-store

Recording a release of the same version again starts supporting it again. apiome pact record-support-ended takes the same flags; in the app, use End support on the board (End support for a release).

Record from the app​

A deployment or a release that happened outside a pipeline — a hotfix, a manual rollout, an app store release — can be recorded on the Environments page. See Record a deployment in the app and Record a release in the app. The page asks can-i-deploy first, and recording over a “no” needs an explicit tick that is written to the audit trail.

What the provider verifies​

A provider's verifier picks up what you recorded with these selectors (see Choose pacts to verify with selectors):

SelectorWhat it selects
{"deployed": true, "environment": "production"}Every consumer version currently deployed to production, on every instance.
{"released": true}Every consumer version released and still supported, in any environment.
{"deployedOrReleased": true}Both of the above.
{"environment": "production"}Every consumer version deployed or supported in production.

The reasons in the verifier's output name the environment: deployed to production.

Read what is recorded​

To readRequest
Every environmentGET …/pact-broker/environments (?name=production for one)
What is deployed to an environment nowGET …/environments/<uuid>/deployed-versions/currently-deployed?pacticipant=Ledger%20API
What is supported in an environment nowGET …/environments/<uuid>/released-versions/currently-supported
Every deployment of one version to an environment, current or notGET …/pacticipants/ledger-api/versions/4f1e2d0/deployed-versions/environment/<uuid>
One deployment or releaseGET …/deployed-versions/<uuid>, GET …/released-versions/<uuid>

A version's document (GET …/pacticipants/ledger-api/versions/4f1e2d0) lists one pb:record-deployment and one pb:record-release link per environment, each named after its environment. This is how the CLI finds where to post.

When a request is refused​

StatusCodeWhat to do
404pacticipant-version-not-foundThe version is not recorded yet. Publish its pacts or record it first.
404pact-environment-not-foundNo environment with that uuid in this workspace. List them with list-environments.
409pact-environment-name-takenAnother environment already has the name.
422pact-environment-invalidThe environment is malformed. pointer names the field: /name with a space in it, /production not true or false.
422pact-deployment-invalidcurrentlyDeployed or currentlySupported was set to true. Record the deployment or release again instead.
401 / 403—The token is not a valid API key for this workspace, or its member lacks the Pacts permission below.

Who can do what​

ActionNeedsViewerEditorAdminOwner
List environments and read deploymentspacts:view✓✓✓✓
Create an environment, record a deployment or a releasepacts:create—✓✓✓
Change an environment, record an undeployment or the end of supportpacts:edit—✓✓✓
Delete an environmentpacts:delete——✓✓