Configure environment
Now that we’ve created and deployed our first Lifecycle environment, let’s learn how to customize it by configuring services and dependencies.
Understanding Configuration
First, let’s take a look at the lifecycle.yaml configuration file at the root dir of lifecycle-examples repository:
Default and Optional Services
We have our dependencies defined in defaultServices and optionalServices:
defaultServices– These services are always built and deployed with the environment. They form the core foundation of the environment and are required for it to function correctly.optionalServices– These services can be built on demand, only when explicitly needed. If they are not selected during a PR, they default to using a static environment (e.g.,dev-0).
Template Variables
Notice how there are template variables defined in service named frontend > github.docker.env:
This API_URL and CACHE_URL variables are dynamically templated by Lifecycle and provided during the build and deploy steps for the frontend service.
Read more about supported template variables here
Static Environment as a Fallback
Since cache is an optional service, this service defaulted to using a static environment(dev-0) as a fallback. This allows us to reuse existing environments instead of rebuilding everything from scratch when there are no changes.
Check Template Variables
To view how the fallback URL works,
- Open your Tasks App(frontend) from the deployed environment.
- Navigate to the
Variablespage. - Search for
_URLand check its value.- It should look like:
- Notice how
CACHE_URLdefaults to thedev-0(static) environment for the optional cache.
Configuring Services
Now, let’s say you also want to the cache component to test, build and deploy it in your environment.
Enable Cache Deployment
- Navigate to the Lifecycle PR comment on GitHub.
- Select the
cachecheckbox in the comment. That’s it! - Lifecycle will now start building and deploying the cache service for your specific environment.
- Wait for the build to complete. You can monitor the progress in the status comment.
Confirm the New Cache URL
- Once the cache is deployed, go back to your frontend app’s Variables page.
- Check the
CACHE_URLvalue.- It should now look like:
- Now, you’re running your cache from your own environment instead of an existing static deploy!
- Check the application’s Tasks page while you’re here and observe the completely different data, as this environment uses a freshly built and seeded database.
Build Flexible Environments
With this approach, you can:
- Build any combination of frontend and backend services.
- Use custom branches for different services.
- Test different versions of your app.
Check how to use Mission Control comments for configuring your environment here
This gives you a custom, isolated testing environment that mirrors your production setup while allowing flexibility in development and validation.
Summary
- Services marked as optional in
lifecycle.yamlwill default to static environments unless explicitly built. - You can enable/disable any service directly from the Lifecycle PR comment.
- Lifecycle automates dependency management, ensuring your services deploy in the correct order.
Now you’re ready to customize your Lifecycle environments like a pro! 👩💻