yq
yq copied to clipboard
eval of environment variables not working in docker image
Eval of environment variables using docker image is not working: docker run -e pgdata="abc" --rm -v "${PWD}":/workdir mikefarah/yq '.volumes.pgdata += {"driver":"local", "driver_opts":{"type":"none", "o":"bind", " device":eval(pgdata)}}' test.yml Error: 1:95: invalid input text "pgdata)}}"
Note that any how to questions should be posted in the discussion board and not raised as an issue.
Version of yq: 4.34.1 Operating system: linux="Ubuntu 23.04" Installed via: docker + ( on my ubuntu 23 it works
Input Yaml test.yml:
volumes:
pgdata:
Command The command you ran:
docker run -e pgdata="abc" --rm -v "${PWD}":/workdir mikefarah/yq '.volumes.pgdata += {"driver":"local", "driver_opts":{"type":"none", "o":"bind", "
device":eval(pgdata)}}' test.yml
pgdata="/b/c/" yq --inplace '.volumes.pgdata += {"driver":"local", "driver_opts":{"type":"none", "o":"bind", "device":env(pgdata)}}' test.yml
Actual behavior
Error: 1:95: invalid input text "pgdata)}}"
Expected behavior
volumes:
pgdata:
driver: local
driver_opts:
type: none
o: bind
device: /b/c/
Additional context I ran this on my local ubuntu and it worked. My colleagues' boxes dont work nor does the docker image so I am forced to modify my script as follows:
junk=".volumes.pgdata" += {\"driver\":\"local\", \"driver_opts\":{\"type\":\"none\", \"o\":\"bind\", \"device\":\"$pgdata\"}}"
yq --inplace "$junk" test.yml
I'm not quite sure what you are trying to do - but perhaps you are getting confused with eval
and env
- eval is passed an expression string (e.g. ".a.b.c") and evaluates that, whereas env|strenv
will read an environment variable.
The error you seem to be getting is that it's trying to evaluate "pgdata" as a expression - which it is not.
See https://mikefarah.gitbook.io/yq/operators/eval and https://mikefarah.gitbook.io/yq/operators/env-variable-operators