Skip to main content

Secrets

Config

package main

import (
"stakpak.dev/devx/v1"
"stakpak.dev/devx/v1/traits"
)

stack: v1.#Stack & {
components: {
commonSecrets: {
traits.#Secret
secrets: apiKey: {
name: "apikey-a"
version: "4"
}
}
cowsay: {
traits.#Workload
traits.#Volume
containers: default: {
image: "docker/whalesay"
command: ["cowsay"]
args: ["Hello DevX!"]
env: {
// you can use secrets directly in an env var
API_KEY: commonSecrets.secrets.apiKey
SOMETHING: "bla"
}
mounts: [
{
// or you can mount secrets as files via volumes
volume: volumes.default
path: "secrets/file"
},
]
}
volumes: default: secret: commonSecrets.secrets.apiKey
}
}
}

Build

devx build dev
devx build prod

Result

docker-compose.yml
version: "3"
volumes:
apikey-a: null
services:
cowsay:
image: docker/whalesay
environment:
API_KEY: apikey-a-very-long-secure-secret
SOMETHING: bla
depends_on: []
command:
- cowsay
- Hello DevX!
restart: always
volumes:
- apikey-a:secrets/file:ro