Skip to content

Commit

Permalink
Fix run args env var extraction logic, with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
badsyntax committed Dec 18, 2020
1 parent 8af15b1 commit 417e8d1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal-functions
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,15 @@ fn-configure-app() {

MAC_ADDRESS=$(echo "$RUN_ARGS" | sed -r 's/.*--mac-address(=| )([^ ]+).*/\2/')
SHM_SIZE=$(echo "$RUN_ARGS" | sed -r 's/.*--shm-size(=| )([^ ]+).*/\2/')
ENV_VARS=$(echo "$RUN_ARGS" | grep -Po '[[:space:]]-e[[:space:]]*[^[:space:]]+' | tr "\n" "\t" | sed -r "s/([\"']?\s*\-e\s*[\"']?)|(\s+)/ /g" | sed -r 's/^\s*|\s*$//g')

# RUN_ARGS will be a string in form "+ true run --shm-size=512m -d --restart=always -e LANG=en_US.UTF-8 -e RAILS_ENV=production" etc
# We want to extract the env vars from the string and produce a new string in form "ENV=var ENV2=var"
# 1. We use grep to extract the "-e ENV=var" strings
# 2. grep will give us newlines, so we convert those to spaces using tr
# 3. Next we use sed to remove "-e" flags as well as multple consecutive whitespace chars
# 4. Finally we use sed to trim leading and trailing spaces

ENV_VARS=$(echo "$RUN_ARGS" | grep -Po '[[:space:]]-e[[:space:]]*[^[:space:]]+' | tr "\n" "\t" | sed -r "s/\s+\-e\s+|\s+/ /g" | sed -r 's/^\s*|\s*$//g')

echo "# ENV_VARS: $ENV_VARS"

Expand Down

0 comments on commit 417e8d1

Please sign in to comment.