Refactor SSL configuration script to improve error handling and certificate generation logic
taylorwalton committed
Nov 30, 2025 at 10:36 UTC
5784bcdfb181a865345ebe78c51cf07c9949307f
1 file changed
+20
-9
customer_portal/build/docker-entrypoint.d/90-copilot-ssl.sh
+20
-9
@@ -1,14 +1,25 @@
1
#!/bin/sh
2
-set -e
2
4
-# This script can be used to configure SSL certificates at runtime
5
-# Only runs if certificates are mounted/available
6
-
7
-if [ -f "/etc/nginx/ssl/cert.pem" ] && [ -f "/etc/nginx/ssl/key.pem" ]; then
8
- echo "SSL certificates found, enabling HTTPS..."
3
+if [[ -z "${SERVER_HOST}" ]]; then
4
+ echo "No SERVER_HOST set!"
5
+ echo "Please set the SERVER_HOST environment variable to use CoPilot"
6
+ exit 1;
7
+else
8
+ echo "Host is now https://${SERVER_HOST}:${SERVER_PORT}"
9
+fi
10
10
- # Update nginx config to enable SSL
11
- # This is a placeholder - adjust based on your SSL needs
11
+if [[ ! -f "${TLS_CERT_PATH}" || ! -f "${TLS_KEY_PATH}" ]]; then
12
+ echo "No TLS certs found. Generating...."
13
+ mkdir -p $(dirname "${TLS_CERT_PATH}")
14
+ openssl req -x509 -subj "/CN=${SERVER_HOST}" -nodes -newkey rsa:4096 -keyout "${TLS_KEY_PATH}" -out "${TLS_CERT_PATH}" -days 365
15
+else
16
+ echo "TLS certificates found"
17
fi
18
14
-exit 0
19
+if [[ ! -f /etc/nginx/certs/dhparams.pem ]]; then
20
+ echo "Generating new DH parameters - this may take a while..."
21
+ mkdir -p /etc/nginx/certs/
22
+ openssl dhparam -out /etc/nginx/certs/dhparams.pem 2048
23
+else
24
+ echo "... DH parameters found"
25
+fi