Define and execute hooks at specific phases of module deployment.
The module hooks are supported from major schema version 3 onwards. If they are specified but schema version is below 3, they are ignored.
You can use hooks to change the typical deployment process, in this case to enable tasks to be executed during a specific moment of the application deployment. For example, you can set hooks to be executed before or after the actual deployment steps for a module, depending on the applications' need.
Currently, module hooks are only Cloud Foundry app tasks. Therefore, the timeout of a hook is the task execution timeout defined for the respective module. For more information, see Application-Specific Timeouts.
When added to the deployment descriptor, module hooks are modeled as follows:
_schema-version: "3.3" ID: foo version: 3.0.0 modules: - name: foo type: javascript.nodejs hooks: - name: hook type: task phases: - blue-green.application.before-stop.live - blue-green.application.before-stop.idle parameters: name: foo-task command: 'sleep 5m'
In the example above, the hook attributes are:
-
name– defines the name of the hook. -
type– defines the type of the hook. Currently, the only supported type istask. -
phases– defines the specific moment when a hook is executed. Thephaseselement denotes that the hook is executed before the application is stopped. The suffixesliveandidleare used during blue-green deployments and indicate when thebefore-stopphase is executed.In the example above, the
blue-green.application.before-stop.idlephase executes the hook when the new idle applications are redirected to the new live routes, and theblue-green.application.before-stop.liveis used just before the deletion of the live application. -
parameters– defines the parameters of the hook. For the hooks of typetask, the parameters must define a one-off task.
Depending on the deployment strategy you use, the phases values are:
-
For regular deployment
Phase
Supported for types
Description
deploy.application.before-stoptaskExecuted before the application corresponding to the module is stopped.
deploy.application.after-stoptaskExecuted after the application corresponding to the module is stopped.
deploy.application.before-starttaskExecuted before the application corresponding to the module is started.
-
For blue-green deployment
Phase
Supported for types
Description
blue-green.application.before-stop.idletaskExecuted before the idle application corresponding to the module is stopped. Idle applications are created as part of blue-green deployments and are restarted (stopped and started again) after the deployment validation phase of their productization. That is after the live routes are mapped to them and their environments are rebuilt to contain only live routes.
blue-green.application.before-stop.livetaskExecuted before the live application corresponding to the module is stopped. Live applications are the ones that are already up and running before the deployment starts.
blue-green.application.after-stop.idletaskExecuted after the idle application corresponding to the module is stopped.
blue-green.application.after-stop.livetaskExecuted after the live application corresponding to the module is stopped.
blue-green.application.before-unmap-routes.livetaskExecuted before unmapping the route of the live application that corresponds to the module.
blue-green.application.before-start.idletaskExecuted before the idle application corresponding to the module is started.
blue-green.application.before-start.livetaskExecuted before the live application corresponding to the module is started.
The table below contains the parameters of the supported module hook types:
Module-Hooks-Specific Parameters
|
Parameter |
Scope |
Read-Only / Write |
Description |
Default Value |
Example |
|---|---|---|---|---|---|
|
|
Module Hook |
Write |
Defines the name of the Cloud Foundry task that should be executed |
The name of the hook |
|
|
|
Module Hook |
Write |
Defines the actual command that is executed as a Cloud Foundry task |
|
|
|
|
Module Hook |
Write |
Defines the memory that is available to the Cloud Foundry task |
Landscape-specific value that is equal to the default application memory
|
|
|
|
Module Hook |
Write |
Defines the disk space that is available to the Cloud Foundry task |
Landscape-specific value that is equal to the default application disk quota
|
|
You can also extend module hooks through the extension descriptor. To do so, add the code with your specific parameters, similarly to the following example:
_schema-version: "3.3" ID: foo-change-command extends: foo modules: - name: foo hooks: - name: hook parameters: command: 'sleep 1m'
Related Information
MTA Deployment Descriptor Examples
Defining Multitarget Application Deployment Descriptors for Cloud Foundry