Skip to content

Commit a2087a2

Browse files
authored
chore: enable tls connection to postgres on newer otp versions (#5)
1 parent 279a795 commit a2087a2

File tree

6 files changed

+68
-28
lines changed

6 files changed

+68
-28
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ on:
1010

1111
env:
1212
NODE_VERSION: "18.12.1"
13-
OTP_VERSION: "26.0.2"
14-
ELIXIR_VERSION: "1.15.2"
13+
OTP_VERSION: "26.2.1"
14+
ELIXIR_VERSION: "1.15.7"
1515

1616
jobs:
1717
build_deps:

.github/workflows/release.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ name: Create and publish a Docker image
1414
on:
1515
release:
1616
types: [published]
17-
17+
push:
18+
branches: ["main"]
19+
pull_request_target:
20+
types:
21+
- opened
22+
branches:
23+
- main
24+
1825
env:
1926
REGISTRY: ghcr.io
2027
IMAGE_NAME: ${{ github.repository }}

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# - https://pkgs.org/ - resource for finding needed packages
1313
# - Ex: hexpm/elixir:1.14.0-erlang-24.3.4-debian-bullseye-20210902-slim
1414
#
15-
ARG ELIXIR_VERSION=1.15.2
16-
ARG OTP_VERSION=26.0.2
17-
ARG DEBIAN_VERSION=bullseye-20230612-slim
15+
ARG ELIXIR_VERSION=1.15.7
16+
ARG OTP_VERSION=26.2.1
17+
ARG DEBIAN_VERSION=bullseye-20231009-slim
1818

1919
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
2020
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
@@ -116,9 +116,9 @@ RUN mix release
116116

117117
# start a new build stage so that the final image will only contain
118118
# the compiled release and other runtime necessities
119-
FROM production_builder as production
119+
FROM ${RUNNER_IMAGE} as production
120120

121-
RUN apt-get update -y && apt-get install -y libstdc++6 postgresql-client openssl libncurses5 locales \
121+
RUN apt-get update -y && apt-get install -y ca-certificates libstdc++6 postgresql-client openssl libncurses5 locales \
122122
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
123123

124124
# Set the locale

config/runtime.exs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ if config_env() != :test do
3030
end
3131

3232
if config_env() == :prod do
33+
unless System.get_env("DATABASE_HOST") do
34+
Logger.warn(
35+
"Environment variable DATABASE_HOST is missing, e.g. DATABASE_HOST=localhost or DATABASE_HOST=postgres"
36+
)
37+
end
38+
39+
unless System.get_env("DATABASE_NAME") do
40+
Logger.warn("Environment variable DATABASE_NAME is missing, e.g. DATABASE_NAME=wordcharts")
41+
end
42+
43+
unless System.get_env("DATABASE_USER") do
44+
Logger.warn(
45+
"Environment variable DATABASE_USER is missing, e.g. DATABASE_USER=wordcharts_user"
46+
)
47+
end
48+
49+
unless System.get_env("DATABASE_USER_PASSWORD") do
50+
Logger.warn(
51+
"Environment variable DATABASE_USER_PASSWORD is missing, e.g. DATABASE_USER_PASSWORD=wordcharts_user_password"
52+
)
53+
end
54+
3355
database_url =
3456
System.get_env("DATABASE_URL") ||
3557
raise """
@@ -40,10 +62,23 @@ if config_env() == :prod do
4062
maybe_ipv6 = if System.get_env("ECTO_IPV6"), do: [:inet6], else: []
4163

4264
config :wordcharts, Wordcharts.Repo,
43-
# ssl: true,
44-
url: database_url,
45-
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
46-
socket_options: maybe_ipv6
65+
database: System.get_env("DATABASE_NAME"),
66+
hostname: System.get_env("DATABASE_HOST"),
67+
password: System.get_env("DATABASE_USER_PASSWORD"),
68+
username: System.get_env("DATABASE_USER"),
69+
pool_size: String.to_integer(System.get_env("POOL_SIZE", "10")),
70+
port: String.to_integer(System.get_env("DATABASE_PORT", "5432")),
71+
ssl: System.get_env("DATABASE_SSL", "true") == "true",
72+
socket_options: maybe_ipv6,
73+
ssl_opts: [verify: :verify_peer,
74+
cacerts: :public_key.cacerts_get(),
75+
versions: [:"tlsv1.3"],
76+
depth: 3,
77+
server_name_indication: String.to_charlist(System.get_env("DATABASE_HOST")),
78+
customize_hostname_check: [
79+
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
80+
]
81+
]
4782

4883
# The secret key base is used to sign/encrypt cookies and other secrets.
4984
# A default value is used in config/dev.exs and config/test.exs but you

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ defmodule Wordcharts.MixProject do
3535
{:phoenix, "1.7.7"},
3636
{:phoenix_ecto, "4.4.2"},
3737
{:ecto_sql, "3.10.1"},
38-
{:postgrex, "0.17.1"},
38+
{:postgrex, "0.17.4"},
3939
{:phoenix_html, "3.3.1"},
4040
{:phoenix_view, "2.0.2"},
4141
{:phoenix_live_reload, "1.4.1", only: :dev},
4242
{:phoenix_live_view, "0.19.3"},
4343
{:floki, "0.34.3", only: :test},
4444
{:phoenix_live_dashboard, "0.8.0"},
45-
{:esbuild, "~> 0.4", runtime: Mix.env() == :dev},
45+
{:esbuild, "0.8.1", runtime: Mix.env() == :dev},
4646
{:swoosh, "1.11.2"},
4747
{:telemetry_metrics, "0.6.1"},
4848
{:telemetry_poller, "1.0.0"},

0 commit comments

Comments
 (0)