-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: enhance etcd configuration and validation
- Expand etcd storage configuration with timeout, auth and TLS options - Add caddy-etcd module build in Dockerfile - Implement environment variable validation for clustering - Remove conditional block structure for cleaner config
- Loading branch information
Showing
4 changed files
with
75 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,33 @@ | ||
{ | ||
# Enable admin API for clustering | ||
admin off | ||
|
||
# Configure storage if clustering is enabled | ||
{$PORTAL_CORE_CLUSTERED_ENABLED:false} { | ||
storage etcd { | ||
endpoints {$PORTAL_CORE_CLUSTERED_ETCD_ENDPOINTS} | ||
namespace {$PORTAL_CORE_CLUSTERED_ETCD_PREFIX}/caddy | ||
} | ||
} | ||
# Enable admin API for clustering | ||
admin off | ||
|
||
# Configure storage for clustering | ||
storage etcd { | ||
prefix "{$PORTAL_CORE_CLUSTERED_ETCD_PREFIX}" | ||
endpoints { | ||
{$PORTAL_CORE_CLUSTERED_ETCD_ENDPOINTS} | ||
} | ||
timeout {$PORTAL_CORE_CLUSTERED_ETCD_TIMEOUT:5m} | ||
auth { | ||
username "{$PORTAL_CORE_CLUSTERED_ETCD_USERNAME}" | ||
password "{$PORTAL_CORE_CLUSTERED_ETCD_PASSWORD}" | ||
} | ||
tls { | ||
cert "{$PORTAL_CORE_CLUSTERED_ETCD_TLS_CERT}" | ||
key "{$PORTAL_CORE_CLUSTERED_ETCD_TLS_KEY}" | ||
ca "{$PORTAL_CORE_CLUSTERED_ETCD_TLS_CA}" | ||
server_name "{$PORTAL_CORE_CLUSTERED_ETCD_TLS_SERVER_NAME}" | ||
} | ||
} | ||
} | ||
|
||
# Handle all domains matching the PORTAL_CORE_DOMAIN | ||
*.{$PORTAL_CORE_DOMAIN} { | ||
reverse_proxy localhost:{$PORTAL_CORE_PORT} | ||
reverse_proxy localhost:{$PORTAL_CORE_PORT} | ||
} | ||
|
||
# Handle direct domain access | ||
:{80, 443} { | ||
reverse_proxy localhost:{$PORTAL_CORE_PORT} | ||
:80, :443 { | ||
reverse_proxy localhost:{$PORTAL_CORE_PORT} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
admin off | ||
} | ||
|
||
# Handle all domains matching the PORTAL_CORE_DOMAIN | ||
*.{$PORTAL_CORE_DOMAIN} { | ||
reverse_proxy localhost:{$PORTAL_CORE_PORT} | ||
} | ||
|
||
# Handle direct domain access | ||
:80, :443 { | ||
reverse_proxy localhost:{$PORTAL_CORE_PORT} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,34 @@ | ||
#!/bin/bash | ||
|
||
# Start portal in background | ||
/usr/local/bin/portal & | ||
# Validate required env vars when clustering is enabled | ||
if [ "${PORTAL_CORE_CLUSTERED_ENABLED}" = "true" ]; then | ||
required_vars=( | ||
"PORTAL_CORE_CLUSTERED_ETCD_ENDPOINTS" | ||
"PORTAL_CORE_CLUSTERED_ETCD_PREFIX" | ||
) | ||
|
||
for var in "${required_vars[@]}"; do | ||
if [ -z "${!var}" ]; then | ||
echo "Error: $var is required when clustering is enabled" | ||
exit 1 | ||
fi | ||
done | ||
|
||
# Start Caddy in foreground | ||
/usr/bin/caddy run --config /etc/caddy/Caddyfile | ||
# Remove TLS block from Caddyfile if TLS env vars are empty | ||
if [ -z "${PORTAL_CORE_CLUSTERED_ETCD_TLS_CERT}" ] || [ -z "${PORTAL_CORE_CLUSTERED_ETCD_TLS_KEY}" ]; then | ||
sed -i '/tls/,/}/d' /etc/caddy/Caddyfile | ||
sed -i '/^$/d' /etc/caddy/Caddyfile | ||
fi | ||
|
||
# Start portal in background | ||
/usr/local/bin/portal & | ||
|
||
# Start Caddy with etcd storage in foreground | ||
/usr/bin/caddy run --config /etc/caddy/Caddyfile | ||
else | ||
# Start portal in background | ||
/usr/local/bin/portal & | ||
|
||
# Start Caddy without etcd storage in foreground | ||
/usr/bin/caddy run --config /etc/caddy/Caddyfile.nocluster | ||
fi |