Skip to content

Instantly share code, notes, and snippets.

@zerda
Created April 12, 2017 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zerda/df577cf788ba74aad60147394eae4bba to your computer and use it in GitHub Desktop.
Save zerda/df577cf788ba74aad60147394eae4bba to your computer and use it in GitHub Desktop.
Merge environment variables to Docker container files
#!/bin/sh
if [[ -n "$CONFIG_PATH" ]]; then
printf "Merging environment variables to '$CONFIG_PATH'.\n"
if [[ -n "$BASE_URL" ]]; then
tmp=$(mktemp)
jq '.baseUrl = $value' $CONFIG_PATH --arg value $BASE_URL > $tmp && mv $tmp $CONFIG_PATH
printf "baseUrl = '$BASE_URL'\n"
fi
chmod 644 $CONFIG_PATH
printf "Merge operation has been done.\n"
fi
exec "$@"
FROM nginx:alpine
EXPOSE 80
RUN apk add --update --no-cache jq
ADD ./docker-entrypoint.sh /
ADD ./config.json ./index.html /usr/share/nginx/html/
ENV CONFIG_PATH=/usr/share/nginx/html/config.json
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment