forked from OpenSlides/openslides-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·179 lines (151 loc) · 4.93 KB
/
entrypoint.sh
File metadata and controls
executable file
·179 lines (151 loc) · 4.93 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/sh
# Co-authored-by: Claude <noreply@anthropic.com>
set -ae
# Define variables and set defaults where applicable
TRAEFIK_CONFIG="${TRAEFIK_CONFIG:-/etc/traefik/traefik.yml}"
TRAEFIK_LOG_LEVEL="${TRAEFIK_LOG_LEVEL:-INFO}"
ENABLE_DASHBOARD="${ENABLE_DASHBOARD:-}"
DYNAMIC_DIR="${DYNAMIC_DIR:-/etc/traefik/dynamic}"
DYNAMIC_CONFIG="${DYNAMIC_DIR}/dynamic.yml"
SERVICES_DIR="${SERVICES_DIR:-/services}"
ENABLE_LOCAL_HTTPS="${ENABLE_LOCAL_HTTPS:-}"
HTTPS_CERT_FILE="${HTTPS_CERT_FILE:-/certs/cert.pem}"
HTTPS_KEY_FILE="${HTTPS_KEY_FILE:-/certs/key.pem}"
ENABLE_AUTO_HTTPS="${ENABLE_AUTO_HTTPS:-}"
EXTERNAL_ADDRESS="${EXTERNAL_ADDRESS:-openslides.example.com}"
ACME_ENDPOINT="${ACME_ENDPOINT:-}"
ACME_EMAIL="${ACME_EMAIL:-}"
# Set default values for service endpoints
ACTION_HOST="${ACTION_HOST:-backend}"
ACTION_PORT="${ACTION_PORT:-9002}"
PRESENTER_HOST="${PRESENTER_HOST:-backend}"
PRESENTER_PORT="${PRESENTER_PORT:-9003}"
AUTOUPDATE_HOST="${AUTOUPDATE_HOST:-autoupdate}"
AUTOUPDATE_PORT="${AUTOUPDATE_PORT:-9012}"
ICC_HOST="${ICC_HOST:-icc}"
ICC_PORT="${ICC_PORT:-9007}"
AUTH_HOST="${AUTH_HOST:-auth}"
AUTH_PORT="${AUTH_PORT:-9004}"
SEARCH_HOST="${SEARCH_HOST:-search}"
SEARCH_PORT="${SEARCH_PORT:-9050}"
PROJECTOR_HOST="${PROJECTOR_HOST:-projector}"
PROJECTOR_PORT="${PROJECTOR_PORT:-9051}"
MEDIA_HOST="${MEDIA_HOST:-media}"
MEDIA_PORT="${MEDIA_PORT:-9006}"
MANAGE_HOST="${MANAGE_HOST:-manage}"
MANAGE_PORT="${MANAGE_PORT:-9008}"
VOTE_HOST="${VOTE_HOST:-vote}"
VOTE_PORT="${VOTE_PORT:-9013}"
CLIENT_HOST="${CLIENT_HOST:-client}"
CLIENT_PORT="${CLIENT_PORT:-9001}"
# =================================
# = Build static / install config =
# =================================
# Generate base config from template
envsubst < /templates/traefik.yml > "$TRAEFIK_CONFIG"
# Add dashboard if enabled
if [ -n "$ENABLE_DASHBOARD" ]; then
echo "Enabling dashboard. 'debug: true' for now. NOT FOR PRODUCTION"
cat >> "$TRAEFIK_CONFIG" << 'EOF'
api:
dashboard: true
debug: true
EOF
fi
# Add entryPoints in accordance to HTTPS related variables
cat >> "$TRAEFIK_CONFIG" << 'EOF'
entryPoints:
main:
address: ":8000"
http:
EOF
if [ -n "$ENABLE_LOCAL_HTTPS" ]; then
# Define tls property, which will cause all routers to terminate TLS and
# foward decrypted traffic.
cat >> "$TRAEFIK_CONFIG" << 'EOF'
tls: {}
EOF
elif [ -n "$ENABLE_AUTO_HTTPS" ]; then
# Also needs tls property, but with additional information for cert retrieval
cat >> "$TRAEFIK_CONFIG" << EOF
tls:
domains:
- main: ${EXTERNAL_ADDRESS}
certResolver: acmeResolver
EOF
# Additionally a plain HTTP endpoint to answer ACME challenges on must be
# configured
cat >> "$TRAEFIK_CONFIG" << 'EOF'
acme:
address: ":8001"
EOF
# Add the certificates resolver providing information for automatic ACME
# based cert retrieval.
cat >> "$TRAEFIK_CONFIG" << EOF
certificatesResolvers:
acmeResolver:
acme:
email: ${ACME_EMAIL}
storage: acme.json
httpChallenge:
entryPoint: acme
EOF
if [ -n "$ACME_ENDPOINT" ]; then
cat >> "$TRAEFIK_CONFIG" << EOF
caServer: ${ACME_ENDPOINT}
EOF
fi
echo "traefik was configured to automatically retrieve a TLS certificates via acme."
echo "Make sure incoming challange requests (to HOST:80/.well-known/acme-challenge/) reach this container on port 8001"
echo "In most cases forwarding the hosts port 80 to containers port 8001 is enough."
fi
# ==================================
# = Build dynamic / routing config =
# ==================================
# Start with empty file
echo "" > "$DYNAMIC_CONFIG"
if [ -n "$ENABLE_LOCAL_HTTPS" ]; then
if [ -f "$HTTPS_CERT_FILE" ] && [ -f "$HTTPS_KEY_FILE" ]; then
envsubst < /templates/tls.yml >> "$DYNAMIC_CONFIG"
else
echo "ERROR: no local cert-files provided. Did you run make-localhost-cert.sh?"
exit 1
fi
fi
# First build SERVICES list (space separated) based on files present in
# services directory
SERVICES=
for service_file in $SERVICES_DIR/*.service; do
service=$(basename $service_file .service)
service_upper=$(echo "$service" | tr '[:lower:]' '[:upper:]')
host_var="${service_upper}_HOST"
if [[ ! -f "$SERVICES_DIR/$service.service" ]] || [[ ! -f "$SERVICES_DIR/$service.router" ]]; then
echo "Skipping, config incomplete: $service"
continue
fi
if eval [[ -n "\$${host_var}" ]]; then
eval "echo \"Adding config: $service (host: \$${host_var})\"" >&2
SERVICES="$SERVICES $service"
else
echo "Skipping, disabled in environment: $service"
fi
done
# Write to config file
cat >> "$DYNAMIC_CONFIG" << 'EOF'
http:
routers:
EOF
# Concatenate all enabled .router files
for service in $SERVICES; do
envsubst < "$SERVICES_DIR/${service}.router" >> "$DYNAMIC_CONFIG"
done
# Add services section
cat >> "$DYNAMIC_CONFIG" << 'EOF'
services:
EOF
# Concatenate all enabled .service files
for service in $SERVICES; do
envsubst < "$SERVICES_DIR/${service}.service" >> "$DYNAMIC_CONFIG"
done
# Finally start CMD
exec "$@"