-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
60 lines (50 loc) · 1.94 KB
/
docker-entrypoint.sh
File metadata and controls
60 lines (50 loc) · 1.94 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
#!/bin/bash
set -euo pipefail
WORKERS=${WORKERS:-1}
WORKER_CLASS=${WORKER_CLASS:-gevent}
ACCESS_LOG=${ACCESS_LOG:--}
ERROR_LOG=${ERROR_LOG:--}
WORKER_TEMP_DIR=${WORKER_TEMP_DIR:-/dev/shm}
SECRET_KEY=${SECRET_KEY:-}
SKIP_DB_PING=${SKIP_DB_PING:-false}
OTEL_SERVICE_NAME=${OTEL_SERVICE_NAME:-"ctfd"}
OTEL_EXPORTER_OTLP_ENDPOINT=${OTEL_EXPORTER_OTLP_ENDPOINT:-""}
OTEL_EXPORTER_OTLP_INSECURE=${OTEL_EXPORTER_OTLP_INSECURE:-"false"}
# Check that a .ctfd_secret_key file or SECRET_KEY envvar is set
if [ ! -f .ctfd_secret_key ] && [ -z "$SECRET_KEY" ]; then
if [ $WORKERS -gt 1 ]; then
echo "[ ERROR ] You are configured to use more than 1 worker."
echo "[ ERROR ] To do this, you must define the SECRET_KEY environment variable or create a .ctfd_secret_key file."
echo "[ ERROR ] Exiting..."
exit 1
fi
fi
# Skip db ping if SKIP_DB_PING is set to a value other than false or empty string
if [[ "$SKIP_DB_PING" == "false" ]]; then
# Ensures that the database is available
python ping.py
fi
# Initialize database
flask db upgrade
if [[ "$OTEL_EXPORTER_OTLP_ENDPOINT" != "" ]]; then
echo "Modifying CTFd for OTEL support..."
# This injects the monkey patch BEFORE auto-instrumentation, such there are no conflicts later
cat <<EOF > /tmp/__init__.py
from gevent import monkey
monkey.patch_all()
from opentelemetry.instrumentation import auto_instrumentation
auto_instrumentation.initialize()
EOF
cat /opt/CTFd/CTFd/__init__.py >> /tmp/__init__.py
mv /tmp/__init__.py /opt/CTFd/CTFd/__init__.py
export OTEL_SERVICE_NAME=$OTEL_SERVICE_NAME
export OTEL_EXPORTER_OTLP_ENDPOINT=$OTEL_EXPORTER_OTLP_ENDPOINT
export OTEL_EXPORTER_OTLP_INSECURE=$OTEL_EXPORTER_OTLP_INSECURE
fi
exec gunicorn 'CTFd:create_app()' \
--bind '0.0.0.0:8000' \
--workers $WORKERS \
--worker-tmp-dir "$WORKER_TEMP_DIR" \
--worker-class "$WORKER_CLASS" \
--access-logfile "$ACCESS_LOG" \
--error-logfile "$ERROR_LOG"