Skip to content

Commit f36a564

Browse files
fix: resolve Docker Compose deployment issues with SSL redirect and pg healthcheck
Make force_ssl opt-in (FORCE_SSL=true) so plain-HTTP deployments work out of the box, fix the misplaced exclude option, match URL scheme/port to the SSL setting, remove hardcoded PHX_HOST=localhost, and silence noisy pg_isready logs by targeting the correct database. Closes #4
1 parent 95ed727 commit f36a564

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

config/prod.exs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ config :zentinel_cp, Oban, engine: Oban.Engines.Basic
1414
config :zentinel_cp, ZentinelCpWeb.Endpoint,
1515
cache_static_manifest: "priv/static/cache_manifest.json"
1616

17-
# Force using SSL in production. This also sets the "strict-security-transport" header,
18-
# known as HSTS. If you have a health check endpoint, you may want to exclude it below.
19-
# Note `:force_ssl` is required to be set at compile-time.
20-
config :zentinel_cp, ZentinelCpWeb.Endpoint,
21-
force_ssl: [rewrite_on: [:x_forwarded_proto]],
22-
exclude: [
23-
# paths: ["/health"],
24-
hosts: ["localhost", "127.0.0.1"]
25-
]
17+
# Force SSL in production (opt-in via FORCE_SSL=true at build time).
18+
# Sets the "strict-transport-security" header (HSTS) and redirects HTTP → HTTPS.
19+
# Note: `force_ssl` must be set at compile-time.
20+
if System.get_env("FORCE_SSL") in ["true", "1"] do
21+
config :zentinel_cp, ZentinelCpWeb.Endpoint,
22+
force_ssl: [
23+
rewrite_on: [:x_forwarded_proto],
24+
exclude: ["localhost", "127.0.0.1"]
25+
]
26+
end
2627

2728
# Configure Swoosh API Client
2829
config :swoosh, api_client: Swoosh.ApiClient.Req

config/runtime.exs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,15 @@ if config_env() == :prod do
9090

9191
config :zentinel_cp, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
9292

93+
port = String.to_integer(System.get_env("PORT") || "4000")
94+
95+
{url_scheme, url_port} =
96+
if System.get_env("FORCE_SSL") in ["true", "1"],
97+
do: {"https", 443},
98+
else: {"http", port}
99+
93100
config :zentinel_cp, ZentinelCpWeb.Endpoint,
94-
url: [host: host, port: 443, scheme: "https"],
101+
url: [host: host, port: url_port, scheme: url_scheme],
95102
http: [
96103
# Enable IPv6 and bind on all interfaces.
97104
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
environment:
77
DATABASE_URL: "ecto://zentinel:zentinel@postgres:5432/zentinel_cp"
88
SECRET_KEY_BASE: "change-me-in-production-use-mix-phx-gen-secret-to-generate"
9-
PHX_HOST: "localhost"
9+
# PHX_HOST: "your-domain.com" # Set to your server's domain or IP
1010
PORT: "4000"
1111
S3_ENDPOINT: "http://minio:9000"
1212
S3_BUCKET: "zentinel-bundles"
@@ -37,7 +37,7 @@ services:
3737
volumes:
3838
- pgdata:/var/lib/postgresql/data
3939
healthcheck:
40-
test: ["CMD-SHELL", "pg_isready -U zentinel"]
40+
test: ["CMD-SHELL", "pg_isready -U zentinel -d zentinel_cp"]
4141
interval: 5s
4242
timeout: 5s
4343
retries: 5

0 commit comments

Comments
 (0)