Skip to content

Commit 7f6c202

Browse files
author
Matthew Fisher
committed
fix(builder): properly parse config vars
Previously, the entire export from `jq` was considered one string, so when we printed the output it would be like "-e HELLO=foo GOODBYE=bar". This fixes it to "-e HELLO=foo -e GOODBYE=bar". I also removed the for loop in favour of a list as bash invokes a subshell in for loops, losing any data you set (such as BUILD_OPTS).
1 parent d63aa6d commit 7f6c202

1 file changed

Lines changed: 13 additions & 20 deletions

File tree

builder/templates/builder

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ RESPONSE=$(curl -s -XPOST \
9292
--data "{\"receive_user\":\"$USER\",\"receive_repo\":\"$APP_NAME\"}" \
9393
$URL)
9494

95-
# massage response for the environment variables in form HELLO=world
96-
CONFIG=$(echo $RESPONSE | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["values"]' | jq -c -M "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" 2> /dev/null || echo $RESPONSE)
95+
# massage response for the environment variables in the form "-e HELLO=world"
96+
CONFIG=$(echo $RESPONSE | jq -r ".values|to_entries|map(\"-e \(.key)=\(.value|tostring)\")|.[]" | sed -e 's/^"//' -e 's/"$//' 2> /dev/null || echo $RESPONSE)
9797

9898
if [ "$CONFIG" == "$RESPONSE" ];
9999
then
@@ -102,32 +102,25 @@ then
102102
exit 1
103103
fi
104104

105-
# build option string to send to slugbuilder
106-
BUILD_OPTS=""
107-
echo $CONFIG > tmp
108-
while read envvar; do
109-
if [ "$envvar" != "" ]; then
110-
BUILD_OPTS+="-e $envvar "
111-
fi
112-
done < tmp
113-
rm tmp
114-
115105
# if no Dockerfile is present, use slugbuilder to compile a heroku slug
116106
# and write out a Dockerfile to use that slug
117107
if [ ! -f Dockerfile ]; then
118-
if [ -f /buildpacks ]; then
119-
BUILD_OPTS+="-v /buildpacks:/tmp/buildpacks:rw "
120-
# give non-root slubuilder user R/W perms for docker volumes
121-
chown -R 2000:2000 /buildpacks
122-
fi
108+
# build option string to send to slugbuilder
109+
BUILD_OPTS=("$CONFIG")
123110

124111
# run in the background, we'll attach to it to retrieve logs
125-
BUILD_OPTS+="-d "
126-
BUILD_OPTS+="-v $TMP_DIR:/tmp/app "
127-
BUILD_OPTS+="-v $CACHE_DIR:/tmp/cache:rw "
112+
BUILD_OPTS+=" -d"
113+
BUILD_OPTS+=" -v $TMP_DIR:/tmp/app"
114+
BUILD_OPTS+=" -v $CACHE_DIR:/tmp/cache:rw"
128115
# give non-root slubuilder user R/W perms for docker volumes
129116
chown -R 2000:2000 $TMP_DIR $CACHE_DIR
130117

118+
if [ -f /buildpacks ]; then
119+
BUILD_OPTS+=" -v /buildpacks:/tmp/buildpacks:rw"
120+
# give non-root slubuilder user R/W perms for docker volumes
121+
chown -R 2000:2000 /buildpacks
122+
fi
123+
131124
# build the application and attach to the process
132125
JOB=$(docker run $BUILD_OPTS deis/slugbuilder)
133126
docker attach $JOB

0 commit comments

Comments
 (0)