In AWS ECS, when SECRET is defined in the ECS task definition, the $SECRET variable ends up in the container as a json string.
SECRET={"secret1":"value1","secret2":"value2"}
I'm able to parse out and export the json string to individual environment variables when I run this command directly in the container using this command:
eval export $(echo "$SECRET" | jq -r 'to_entries|map("\"\(.key)=\(.value|tostring)\"")|.[]' )
But, the variables don't get set properly when I run the same command from the 'entrypoint.sh' script, on container run, when the container starts.
["entrypoint.sh"]
["entrypoint.sh"]
#!/usr/bin/env bash
if [ $# -gt 0 ];then
## If we passed a command in docker run, run it
exec "$@"
else
eval export $(echo "$SECRET" | jq -r 'to_entries|map("\"\(.key)=\(.value|tostring)\"")|.[]' )
"${BUILD_DIR}"/run.sh
fi
Is it possible to parse the json string and export environment variables in an entrypoint script so that the show up in printenv
?
Any guidance would be appreciated.