Skip to content

Commit

Permalink
Various changes
Browse files Browse the repository at this point in the history
Move env vars to new env file
Parse whitelisted origins better
Exit web config script early if file exists
Echo commands executed in entrypoint
  • Loading branch information
RoblKyogre committed Feb 19, 2024
1 parent 141dd89 commit eed1f88
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
7 changes: 2 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ version: '3'
services:
viaaas:
image: roblkyogre/docker-viaaas:latest
environment:
AZURE_CLIENT_ID: my-client-id # See https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-spa-app-registration
WHITELISTED_ORIGINS: https://viaaas.example.com # Change to your Web UI domain
CORS_PROXY: cors.example.com # OPTIONAL
INSTANCE_SUFFIX: viaaas.example.com[:25565] # OPTIONAL
build: .
env_file: ./docker.env
ports:
- 25543:25543 # Web UI port
- 25565:25565 # Minecraft port
Expand Down
22 changes: 22 additions & 0 deletions docker.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#####################
### DOCKER-VIAAAS ###
#####################

################
## WEB CONFIG ##
################

# See https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-spa-app-registration
AZURE_CLIENT_ID="my-client-id"

# Change to your Web UI domain(s)
WHITELISTED_ORIGINS="
https://viaaas.example.com
https://anotherone.com
"

# OPTIONAL
#CORS_PROXY="cors.example.com"

# OPTIONAL
#INSTANCE_SUFFIX="viaaas.example.com[:25565]"
2 changes: 1 addition & 1 deletion root/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

for SCRIPT_FILE in $(find /scripts -type f -print)
do
Expand Down
28 changes: 27 additions & 1 deletion root/scripts/parse-web-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
WEB_CONFIG_DIR=/app/config/web/js
WEB_CONFIG_FILE=${WEB_CONFIG_DIR}/config.js

{
if [ -f ${WEB_CONFIG_FILE} ]; then
echo "${WEB_CONFIG_FILE} exists, skipping parse..."
exit 0
fi
}

set -e

echo "Parsing environment for ${WEB_CONFIG_FILE}"
mkdir -p ${WEB_CONFIG_DIR}
touch ${WEB_CONFIG_FILE}
cat /dev/null >| ${WEB_CONFIG_FILE}
Expand All @@ -15,6 +25,22 @@ cat /dev/null >| ${WEB_CONFIG_FILE}

# write to config file
echo "const azureClientId = \"${parsedClientId}\";" >> ${WEB_CONFIG_FILE}
echo "const whitelistedOrigin = [ \"${parsedOrigins}\" ];" >> ${WEB_CONFIG_FILE} # TODO: Support multiple origins

echo -n "const whitelistedOrigin = [" >> ${WEB_CONFIG_FILE}

IFS='
'
count=0
for origin in ${parsedOrigins}
do
if [ ${count} -ne 0 ]; then
echo -n "," >> ${WEB_CONFIG_FILE}
fi
echo -n "\"$(echo ${origin} | xargs echo -n)\"" >> ${WEB_CONFIG_FILE}
count=$((count+1))
done

echo "];" >> ${WEB_CONFIG_FILE}

echo "var defaultCorsProxy = \"${parsedProxy}\";" >> ${WEB_CONFIG_FILE}
echo "var defaultInstanceSuffix = ${parsedSuffix};" >> ${WEB_CONFIG_FILE}

0 comments on commit eed1f88

Please sign in to comment.