-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·68 lines (57 loc) · 2.39 KB
/
docker-entrypoint.sh
File metadata and controls
executable file
·68 lines (57 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
set -e
# Escape replacement text for sed ("&" has special meaning)
escape_sed_replacement() {
printf '%s' "$1" | sed 's/&/\\&/g'
}
replace_placeholder_in_js() {
placeholder="$1"
replacement="$2"
js_files=$(find "$WWW_ROOT" -type f -name "*.js" 2>/dev/null)
[ -z "$js_files" ] && return 0
escaped_replacement=$(escape_sed_replacement "$replacement")
printf '%s\n' "$js_files" | while IFS= read -r file; do
sed -i "s^${placeholder}^${escaped_replacement}^g" "$file"
done
}
# Set document root based on LEGACY_MODE (run with -e LEGACY_MODE=true for legacy UI)
if [ "$LEGACY_MODE" = "true" ] || [ "$LEGACY_MODE" = "1" ] || [ "$LEGACY_MODE" = "yes" ]; then
export NGINX_ROOT=/var/www/legacy
WWW_ROOT=/var/www/legacy
echo "Serving legacy UI from $WWW_ROOT"
else
export NGINX_ROOT=/var/www
WWW_ROOT=/var/www
echo "Serving default UI from $WWW_ROOT"
fi
# Copy build output to /var/www if present (Dockerfile.cross flow)
if [ -d /opt/ui/dist ]; then
cp -rv /opt/ui/dist/* "$WWW_ROOT"
fi
# Replace placeholders in all .js files (including assets/*.js)
if [ -n "$BASE_URL_OVERRIDE" ]; then
echo "running with BASE_URL=${BASE_URL_OVERRIDE}"
replace_placeholder_in_js "{PLACEHOLDER_BASE_URL}" "$BASE_URL_OVERRIDE"
else
echo "running with BASE_URL=${BASE_URL}"
replace_placeholder_in_js "{PLACEHOLDER_BASE_URL}" "$BASE_URL"
fi
if [ -n "$OPENCOST_FOOTER_CONTENT" ]; then
replace_placeholder_in_js "PLACEHOLDER_FOOTER_CONTENT" "$OPENCOST_FOOTER_CONTENT"
else
replace_placeholder_in_js "PLACEHOLDER_FOOTER_CONTENT" "OpenCost version: $VERSION ($HEAD)"
fi
# Custom aggregation options: JSON object (map string:string), e.g. {"Label: team":"label:team"}
if [ -n "$CUSTOM_AGGREGATION_OPTIONS" ]; then
echo "injecting CUSTOM_AGGREGATION_OPTIONS"
esc=$(printf '%s' "$CUSTOM_AGGREGATION_OPTIONS" | sed 's/\\/\\\\/g; s/"/\\"/g')
replace_placeholder_in_js "PLACEHOLDER_CUSTOM_AGGREGATIONS" "$esc"
fi
if [ ! -e /etc/nginx/conf.d/default.nginx.conf ]; then
envsubst '$API_PORT $API_SERVER $UI_PORT $NGINX_ROOT $UI_PATH $BASE_URL $PROXY_CONNECT_TIMEOUT $PROXY_SEND_TIMEOUT $PROXY_READ_TIMEOUT' \
< /etc/nginx/conf.d/default.nginx.conf.template \
> /etc/nginx/conf.d/default.nginx.conf
fi
echo "Starting OpenCost UI version $VERSION ($HEAD)"
# Run the parent (nginx) container's entrypoint script
exec /docker-entrypoint.sh "$@"