Podman equivalent to Docker Compose environment variable substitution
In your example, you can use bash shell expansion:
IMAGE_TAG="v0.0.0"
printf "
version: '2.2'
services:
example-service:
image: busybox:${IMAGE_TAG:-latest}
scale: ${REPLICAS:-1}
command: ls
"
Yields:
version: '2.2'
services:
example-service:
image: busybox:v0.0.0
scale: 1
command: ls
kubectl
(!) supports piping stdin directly (and podman
may too), so you can in theory (though it's nearly always better to persist the output to a file so that you can commit a record of what you apply):
IMAGE_TAG="v0.0.0"
printf "
version: '2.2'
services:
example-service:
image: busybox:${IMAGE_TAG:-latest}
scale: ${REPLICAS:-1}
command: ls
" \
| kubectl apply --filename=-
I have begun using yq
to template my YAML files but previous simply used sed
. Using the former, you can use a YAML query syntax to path to values that you want to replace and, with sed
, of course, regular expressions.
Helm and other (Kubernetes) tools use Go templating to solve a similar problem and it remains something of an outstanding issue (unless you're happy to adopt *nix's philosophy of having tools that do one thing well)