Goal
Understand the variables a template service starts with and how your apps get the connection details they need.Prerequisites
- An application with a template service, or a template you are about to set up
Workflow
1
Before setting up, read the Settings list: each variable marked Generated when you set up is created for you once.
2
After setup, open the service from the canvas. Its variables are on the service like any other.
3
Choose Link an app on the service, pick the app, and check the variables it will get.
4
Save the link. The app picks the variables up on its next deploy.
Generated secrets
Templates write {{secret(32)}} where a password belongs. When you set the template up, StackShift replaces it once with a random 32-character value and stores it as a secret variable on the service. It is not generated again on later deploys. {{secret(16, “abcdef0123456789”)}} limits the characters used, and ${{randomInt(1000, 9999)}} picks a whole number in that range.Reference variables
A variable can point at another value instead of holding a copy. References are kept as written and filled in on every deploy, so they follow changes.- ${{ELASTIC_PASSWORD}} is the ELASTIC_PASSWORD variable of the same service.
- ${{elasticsearch.ELASTIC_PASSWORD}} is that variable on the service called elasticsearch in the same application.
- ${{STACKSHIFT_PRIVATE_DOMAIN}} is the service’s private address, for example elasticsearch.storefront-7c1e2a90.stackshift.internal.
- ${{STACKSHIFT_PRIVATE_URL}} is http://<private address>:<port>.
- ${{STACKSHIFT_PUBLIC_DOMAIN}} is the service’s main public domain, or empty when it has none.
- Any variable on any service in the application can use references, not only template services. A reference to a service or variable that does not exist, or a loop of references, stops the deploy with a message naming it.
What a link gives your app
- A template service can declare the variables an app gets when it links to it. Elasticsearch gives ELASTICSEARCH_URL, ELASTICSEARCH_USERNAME and ELASTICSEARCH_PASSWORD.
- The values follow the service. Change its password and linked apps get the new one on their next deploy.
- A variable you set yourself on the app with the same name keeps your value.
- Private services with link variables can be linked even when they do not answer web requests.
Expected result
Your app reads the service’s address and credentials from variables, and nobody had to copy a password.
Related guides
Set up a template in your application
Choose where it goes (an existing application, a new one, or next to one of your projects), where it runs, the size of each service and its public address, check what will run, then set it up.
Elasticsearch
Run Elasticsearch 9.5.6 as a private service in your application, connect your app with ELASTICSEARCH_URL, and back it up with the snapshot API.