- Hooks allow you to execute a custom command or script before or after specified command is executed.
- Example use cases:
- build, validate or lint your application before deployment
- run unit tests on your application before deployment
- execute database migration after deployment
- cleanup database before delete
Within hook, you can reference scripts specified in scripts section of your config.
Scripts can be referenced in a hook, but they can also be executed manually. Refer to scripts docs to learn more.
During execution the script will get the following environment variables:
STP_COMMAND- Stacktape command used
This is in addition to the environment variables specified on the script definition and the environment variables injected when using connectTo.
Copyscripts:buildWeb:type: local-scriptproperties:executeCommand: npx gatsby buildhooks:beforeDeploy:- scriptName: buildWeb
Using script in the hook
Before command hooks
- Executed before the command, but AFTER the configuration has been successfully loaded.
After command hooks
- Executed after the command has successfully finished.
- Most common use case for using after deploy hooks is migration/seeding of the database, or API/endpoint testing.
Copyscripts:migrateDb:type: local-script-with-bastion-tunnelingproperties:executeScript: migrate.tsconnectTo:- myDatabasehooks:afterDeploy:- scriptName: migrateDbresources:myBastion:type: bastionmyDatabase:type: relational-databaseproperties:# database is only accessible from withing VPCaccessibility:accessibilityMode: vpcengine:type: postgresproperties:primaryInstance:instanceSize: db.t3.microcredentials:masterUserName: my_user_namemasterUserPassword: my_secret_pass
Stacktape config using the migration script with tunneling