Before you start
You finished the first code template tutorial or know the basics of the manifest and the CLI.
A plan with room for the app and the databases. This template needs at least 512 MB for the app, 1,024 MB for Postgres and 512 MB for Redis, so 2,048 MB in the biggest case. The memory of every service comes out of the plan total, see Plans and limits.
Only the owner of a workspace can deploy a template into it. A member sees the templates and uses the stacks that already exist.
Step by step
1
Decide what each answer changes
Write down the questions first and what each answer switches on. This table is the design of the manifest:
There is no expression language in the manifest. You get two tools:
sets on an option, which flips several things at once, and when, which is one equality on one earlier question. Use sets when one choice changes more than one service or variable, as storage does, and when for a single yes/no.2
Write the code that reads the environment
The app never builds an address: it reads variables and the certificate files that the manifest points to. Create Add
src/storage.js (the rest of the app is yours):src/storage.js
pg, ioredis and better-sqlite3 to src/package.json, and a small src/server.js that listens on PORT and answers /healthz. Because a database that is off leaves its variables empty (the platform does not write them), the code can tell which services exist by checking the variable.3
Write the manifest
vertracloud.template.yaml
setson the options.services: { db: "off" }removes the database for the SQLite choice;env: { app: ... }adds variables to the service whose id isapp. The last option chosen wins when several set the same thing, andsetscan also add memory withram_extra.whenon a question.cache_ttlis only asked, and only validated, whencacheistrue. Awhencan only point to a question that comes before it, andequalsmust match the type of that question (truefor a boolean, one of the option values for a choice).whenon a service. Thecacheservice is only created whencacheistrue.dbhas nowhenbecause thesetsofstoragealready controls it: a service accepts only one condition, so pick one mechanism per service.- Placeholders.
{{services.db.host}}and the others read from the service whose id isdb. A placeholder that points to a service that is off resolves to empty and the variable is not written, so the app never sees a half-filled configuration.
4
Know what the platform fills in
For a database service, these placeholders are available:
The certificate files live in
/app/.vertra/certs/<database_id>/, written by the platform before the app’s first boot and kept in sync when you reset a password or a certificate. Databases on the platform always require TLS and a client certificate; a password alone never connects, which is why the manifest passes the three paths. The placeholders of an app service are {{services.<id>.url}} and .domain, and {{app.url}} and {{app.domain}} give the address of the service that is reading them. See Connect the app to the stack’s databases for the same information from the user’s side, with code for other languages and drivers.An output can use placeholders too, but
{{secret:<n>}} is not allowed there. To show a generated secret once, declare it in secrets and print {{secrets.<name>}} with secret: true and once: true.5
Validate
db service id in one place only and you get unknown_service; point cache_ttl to a question that is declared after it and you get invalid_when; set equals: "yes" on a boolean and you get invalid_when (“must be true or false”). Fix them back and run it again.6
Create the template and deploy both variants
/healthz. Each deploy is a job with an idempotency key, and a failure undoes everything it created.Open the address of each app and reload: the counter goes up in both. Then run vertra stack list and vertra stack get <id> to see the members, the connections between them and the template the stack came from.7
Live with the stack
The stack page lists how each variable of the app is connected to each database, and the How to connect panel shows code for the user’s language. When a database password or certificate is reset, the variables and the certificate files of the app are recalculated and the app needs a restart, which the panel and the API announce. When you publish a new version of the template,
vertra stack update <id> --check shows what would change before you commit to it. See Stacks and Updates and rollback.Troubleshooting
Next steps
- Stacks for template authors: services and connections.
- Placeholders and questions: every placeholder and every question type.
- Requirements and plan: how the sum of the services decides the plan.
- Manifest reference:
sets,when,ram_extraand the database fields. - Deploy settings: why software that migrates its database needs rollback with data.
- Next tutorial: a closed template for a client.