JetBrains CodeCanvas 2024.1 Help

Lifecycle Scripts

CodeCanvas lets you run your custom scripts at different stages of a dev environment's lifecycle. This can be helpful in various automation scenarios like work time tracking, personalized environment setup, project configuration, or any other custom actions.

To configure lifecycle scripts, use the Lifecycle scripts section of a dev environment template. You can add your custom scripts to the following stages:

  • On initialization – run your script when a dev environment is initialized. This event is triggered only once when the environment is created for the first time. This stage is the earliest in the lifecycle – it happens before any actions in the environment like mounting a warm-up snapshot or user assignment (personal user parameters aren't available at this stage). Use this event to install IDE plugins or adjust project configuration, e.g., create or .env files.

  • On activation – run your script every time a dev environment is activated. This event is triggered every time a user activates the environment, for example, by creating it, taking it from the standby pool, or re-activating it after it is stopped. Personal user parameters are available at this stage. You can use this event to run update automation or to initialize services that require authentication. For example, this is a perfect stage to run docker-compose up that starts external services like databases, cache servers, etc.

For each stage, you can add a script that will be run in the environment's container and a timeout for the script execution. Note that running scripts affects the environment's start and stop times, so use this feature with caution.

Lifecycle scripts and warm-up

When CodeCanvas runs a warm-up, it creates a dev environment that is equal to the one that a user will get. This means that lifecycle scripts are also executed during warm-up.

When a user creates a dev environment, CodeCanvas checks if a warm-up snapshot contains the actual lifecycle scripts. If the snapshot doesn't have or has outdated scripts, CodeCanvas runs the scripts again in the user's environment. Otherwise, CodeCanvas skips the lifecycle script execution. This allows avoiding unnecessary script execution and speeding up the environment creation process.

Last modified: 17 May 2024