What is an Environment?
An environment is effectively a set of cloud mock APIs that represent an environment likedev
or staging
. Locally,
environments are represented by YAML config files which are overlaid on the base environment file and are activated via
the --profile
CLI parameter for supported operations.
Creating an Environment
You can create a new environment using theenvironments create
command specifying the profile name.
wiremock.yaml
) containing the following:
environments create
command will first check to see if an environment file exists (wiremock-<profile-name>.yaml
)
for the given profile. If one does not exist, it will create a new mock API in WireMock Cloud for each service defined in
the base environment file. The type of the new mock API will match the type defined in the base environment file. The
names of those mock APIs will be the same as the service names with the addition of a suffix of [<profile-name>]
. A new
environment profile file will be created alongside the base environment file - wiremock-<profile-name>.yaml
.
The contents of the new environment profile file will contain the same list of services with the cloud_id
of the
new mock APIs created in WireMock Cloud:
Using an Environment
Using an environment is as simple as specifying the profile name when running any commands that support environments. Doing so will read the profile file (wiremock-<profile-name>.yaml
) and overlay it onto the configuration from
wiremock.yaml
, overriding any matching attributes.
For example, given the following wiremock.yaml
file:
wiremock-staging.yaml
file:
wiremock-staging.yaml
being overlaid onto the main wiremock.yaml
file and the following
configuration being used:
staging
environment will be imported to the staging
mock APIs.
Pulling Mock APIs from an Environment
The CLI provides the ability to pull mock APIs from WireMock Cloud into your local environment. The pull mock APIs command also supports environments allowing you to specify the profile parameter to pull from a specific environment, but the pull command works in a slightly different way when a profile is specified. When pulling a mock API without specifying a profile, the CLI will pull the mock API from the base environment file and download any stubs and API definition files to a directory named after the mock API. The base environment file is updated to include the information about the mock API (e.g.cloud_id
, name
, path
, etc.).
When pulling a mock API with a profile specified, the CLI will pull the environment mock API but will only pull the data (stubs,
API definition files, etc.) and it will be pulled into the same path
directory as specified in the base environment file.The base environment file will not be updated with the information about the environment mock API, effectively pulling the mock API content but not the mock API metadata. This feature supports the ability to manage ongoing changes to sets of mock APIs via a git-based workflow, using environments and merge requests to control change to mock API configuration in the following way:
- Your main environment file (
wiremock.yaml
) is checked into source control and defines yourproduction
environment and mock APIs. - You
pull
your production environment into your local environment using thepull
command. - You create a new environment (
development
) using theenvironments create
command. This will also create the mock APIs for the new environment. - You make changes to the environment mock APIs using WireMock Cloud or using the CLI
record-many
command and specifying thedevelopment
profile. - When you are happy with the changes, you
pull
thedevelopment
environment into your local environment using thepull
command specifying thedevelopment
profile. This will update your local environment with the changes from thedevelopment
environment but only overwrite the content of the mock APIs as described above. - You create a merge request to merge the changes from the
development
environment into theproduction
environment. - Your team members review the merge request and approve it.
- The merge request is merged effectively updating the
production
environment with the changes from thedevelopment
environment.
Restrictions
The following restrictions apply when using environments:- The
wiremock-<profile-name>.yaml
file must not exist when creating a new environment. - No services can be added or removed via the environment profile file. The same services with the same service keys must be present in the environment profile file as in the base environment file.
- Certain information cannot be changed via the environment profile file. The following attributes cannot be changed:
type