1
0
Fork 0
mirror of https://github.com/seejohnrun/haste-server.git synced 2024-11-24 13:31:21 +00:00

script for turning env-vars into config.js

This commit is contained in:
emil-lengman 2020-08-22 17:33:01 +02:00
parent 9b0a5ff0a3
commit 655f2af45a

83
docker-entrypoint.sh Normal file
View file

@ -0,0 +1,83 @@
#!/bin/bash
# We use this file to translate environmental variables to .env files used by the application
set -e
function create_document_string () {
IFS=',' read -ra doc_array <<< "$DOCUMENTS"
document_string="{"
for i in "${doc_array[@]}"
do
IFS='=' read -ra document <<< "$i"
document_string+="\"${document[0]}\": \"${document[1]}\","
done
# Remove trailing ","
[[ "$document_string" == *, ]] && document_string=${document_string::${#document_string}-1}
document_string+="}"
echo $document_string
}
document_string=$(create_document_string)
echo "
{
\"host\": \"$HOST\",
\"port\": ${PORT},
\"keyLength\": $KEY_LENGTH,
\"maxLength\": $MAX_LENGTH,
\"staticMaxAge\": $STATIC_MAX_AGE,
\"recompressStaticAssets\": $RECOMPRESS_STATIC_ASSETS,
\"logging\": [
{
\"level\": \"$LOGGING_LEVEL\",
\"type\": \"$LOGGING_TYPE\",
\"colorize\": $LOGGING_COLORIZE
}
],
\"keyGenerator\": {
\"type\": \"$KEYGENERATOR_TYPE\"
},
\"rateLimits\": {
\"categories\": {
\"normal\": {
\"totalRequests\": $RATELIMITS_NORMAL_TOTAL_REQUESTS,
\"every\": $RATELIMITS_NORMAL_EVERY_SECONDS
},
\"whitelist\": {
\"totalRequests\": $RATELIMITS_WHITELIST_TOTAL_REQUESTS,
\"every\": $RATELIMITS_WHITELIST_EVERY_SECONDS
},
\"blacklist\": {
\"totalRequests\": $RATELIMITS_BLACKLIST_TOTAL_REQUESTS,
\"every\": $RATELIMITS_BLACKLIST_EVERY_SECONDS
}
}
},
\"storage\": {
\"type\": \"$STORAGE_TYPE\",
\"host\": \"$STORAGE_HOST\",
\"port\": $STORAGE_PORT,
\"expire\": $STORAGE_EXPIRE_SECONDS,
\"db\": $STORAGE_DB
},
\"documents\": $document_string
}
" > config.js
exec "$@"