LaunchDarkly integration
The functionality of Release's LaunchDarkly integration and how to set it up
Last updated
The functionality of Release's LaunchDarkly integration and how to set it up
Last updated
Release's LaunchDarkly integration allows you to have a pristine, isolated LaunchDarkly environment to use for testing.
Sharing feature flags between multiple environments can cause testing and reliability issues. Release solves this problem by creating a new LaunchDarkly environment each time you deploy a new Release environment and storing the SDK key, mobile key, and client key as environment variables your application can access.
Release handles creating and deleting LaunchDarkly environments with little configuration needed.
Navigate to the Integrations tab for your account.
Each field in the set-up form is required. Except for the Access Token field, you can use the defaults provided.
Project Key: This is the key for the project you want your environments created under. The default value is default
, as LaunchDarkly always has a project with the key default
.
Access Token: This is the token for the account you would like to create environments under in LaunchDarkly. You can create or find the access token under Account Settings -> Authorization. All access tokens start with api-
.
Environment Variables: The remaining fields define the names of the environment variables Release will use to store the various API keys from LaunchDarkly. You can change these names to anything you like. Keys are stored as encrypted K8s secrets.
You will need the LaunchDarkly access token to set up your SDK client so that you can choose variations of flags in your application.
Once you have saved these configurations, Release will attempt to use your access token to connect to your LaunchDarkly account. If that works, the integration is ready to go! If not, you'll see errors and can correct any mistakes you have made.
The integration consists of two parts, both of which are automated and handled by Release.
Pre-deployment step: The LaunchDarkly integration will add a task to each of your deployments to create the feature flag environment.
Pre-delete step: When you delete an environment, a step will be injected that cleans up by deleting the environment in LaunchDarkly.
The pre-deployment step will create an environment in LaunchDarkly the first time you deploy a space or new configuration.
The environment variables you specified during set up will be populated and exposed to your containers via K8s secrets.
You can then use these environment variables in your code to access your feature flags as you normally would.
The pre-delete step is invoked when a Release environment is removed, whether manually through the UI or when a pull request is merged or closed. The LaunchDarkly integration will remove the corresponding LaunchDarkly environment automatically when the Release environment is removed.
Below are some examples of how to consume the environment variables to use the LaunchDarkly integration.
In this example, we will configure the LaunchDarkly SDK client with the specific API key for your environment. This example is based on the Ruby SDK reference.
When running locally, you can use the dotenv gem (https://github.com/bkeepers/dotenv) to set your LaunchDarkly environment variables to test values.
Install the Ruby SDK gem.
Create a file in config/initializers/launchdarkly_client.rb
.
Copy the code below into config/initializers/launchdarkly_client.rb
.
Example of using the LDClient
you defined above in your Rails application