Set variables and secrets
Add, edit and remove a service's variables, share them across an environment, and mark the secret ones.
All pages
- Open the service, press ⌘K and choose Go to › Variables.
The page lists the service's Own variables, then the Shared and provided ones.
- Choose Add variable, type the name and the value, and press Enter. To edit many at once, switch the view from List to .env, edit the
NAME=valuelines and choose Stage changes.Either way, the edit waits as a staged change.
- Press ⌘K, choose Review changes, then press ⌘↵ to apply it.
Applying it deploys each website the variable reaches.
Every variable reaches both the build and the running service, so there is nothing to choose.
With the CLI, vars set stages the variable too, and --apply applies it in the same run:
ghaym cloud vars set API_URL https://api.example.com --project shop --env production --service web --applyA shared variable reaches every service in the environment. On a service's page it reads From environment. A service's own variable of the same name wins over it, and the shared one then reads Overridden. With the CLI, leave out --service:
ghaym cloud vars set LOG_LEVEL info --project shop --env productionTurn on Secret as you add the variable, or choose Make secret in an existing variable's menu. Its value is never shown again, not even to you, and a Secret never turns plain again. A Secret reaches the build and the running service like any other variable.
- In build logs, Ghaym masks its value as
••••••••wherever it prints, once the value is 4 characters or more. - On the command lines Ghaym runs to build, it stands as a placeholder, never as its value.
- A variable whose value references a Secret, a database's password or a bucket's secret key is a Secret too.
- What your own build steps and code do with the value is yours: Ghaym masks no line your app writes to its logs.
ghaym cloud vars set STRIPE_KEY <value> --project shop --env production --service web --secretA service built with a Dockerfile gets each plain variable as a build arg, and each Secret as a build secret. Read a plain variable with ARG, and mount a Secret on the step that needs it:
ARG VITE_API_URL
RUN --mount=type=secret,id=STRIPE_KEY,env=STRIPE_KEY npm run buildA Secret is never a build arg, so ARG STRIPE_KEY reads nothing. A plain variable is never a build secret, so a mount of it finds none.
Changing a Secret's value rebuilds the service without the cache. Changing a plain variable keeps the layers above the first ARG that reads it.
A service built without a Dockerfile needs nothing extra: each step of its build gets every variable, and each Secret as a build secret.
Commit an .npmrc that names the token by its variable, and set NPM_TOKEN as a Secret:
@acme:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}A service built without a Dockerfile needs nothing more. In a Dockerfile, copy .npmrc with the package files and mount the Secret on the install:
COPY package.json package-lock.json .npmrc ./
RUN --mount=type=secret,id=NPM_TOKEN,env=NPM_TOKEN npm ciA database's values reach a service only through a variable you can see. Set the variable to a reference: ${{postgres.DATABASE_URL}} reads the DATABASE_URL of the database named postgres, and Ghaym fills it in at deploy. A reference such as ${{Service.VAR}} works only within one site. A web service in another site is reached by its public URL. Choose Copy as reference in a variable's menu on the database's page, and paste it as the value.
ghaym cloud vars set DATABASE_URL '${{postgres.DATABASE_URL}}' --project shop --env production --service webWhile a website references none of a database's variables, its variables page says postgres isn't wired to this service. Choose Add DATABASE_URL there to stage the reference, or Dismiss to hide the line.
Connecting a bucket stages six variables on the service, from S3_ENDPOINT to S3_REGION, each a reference to the bucket's own: ${{bucket:media.S3_BUCKET}} reads the S3_BUCKET of the bucket named media. You can rename or delete them, and disconnecting the bucket removes them.
Ghaym adds four values of its own. A variable you set with the same name replaces each one.
| Name | Value | Reaches |
|---|---|---|
GHAYM_COUNTRY | the country code the service runs in, such as JO | the build and the running service |
GHAYM_SITE | the site it runs in, such as amman-1 | the build and the running service |
PORT | App port | the running service |
NODE_OPTIONS | --max-old-space-size at 75% of the service's memory | the running service |
A build can't reach the project's private network, so a migration can't reach your database during it. Run migrations as the app starts instead, in Run command in build settings:
npx prisma migrate deploy && node server.js