Fix environment variables who contains spaces in their value

If you have a `.env` file with some environment variables who contains spaces, like this:

DB_INITIALIZE="cd /app && RAILS_ENV=production bin/setup"
DB_MIGRATE="cd /app && RAILS_ENV=production bin/update"
This commit is contained in:
Tortue Torche 2019-05-29 09:57:10 +02:00 committed by GitHub
parent 79d3b5e775
commit 0828e59bc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

4
psu
View File

@ -393,7 +393,7 @@ deploy() {
if [ -n "$ENVIRONMENT_VARIABLES_FILE" ]; then
local new_stack_envvars
new_stack_envvars=$(env_file_to_json)
stack_envvars="$(echo -n "${new_stack_envvars}${stack_envvars}" | jq -sjc 'add | unique_by(.name)')"
stack_envvars="$(echo "${new_stack_envvars}${stack_envvars}" | jq -sjc 'add | unique_by(.name)')"
fi
local data_prefix="{\"Id\":\"$stack_id\",\"StackFileContent\":\""
local data_suffix="\",\"Env\":"$stack_envvars",\"Prune\":$PORTAINER_PRUNE}"
@ -470,7 +470,7 @@ undeploy() {
# JSON string #
###################################################
env_file_to_json() {
echo "$(env -i $(cat $ENVIRONMENT_VARIABLES_FILE) jq -n 'env | to_entries | map({name: .key, value: .value})')"
echo "$(env -i sh -c "(unset \$(env | sed 's/=.*//'); set -a; . $ENVIRONMENT_VARIABLES_FILE; set +a; jq -njc 'env | to_entries | map({name: .key, value: .value})')")"
}
main "$@"