Skip to content

Commit eb19bf8

Browse files
authored
refactor: Move version to runtime config (#3533)
1 parent d8bc5ba commit eb19bf8

6 files changed

Lines changed: 13 additions & 14 deletions

File tree

‎config/config.exs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ config :dotcom, :search_service, Dotcom.SearchService
5858

5959
config :dotcom, :upcoming_departures_module, Dotcom.UpcomingDepartures
6060

61-
config :dotcom, :version, System.get_env("SENTRY_RELEASE", "missing-version")
62-
6361
config :dotcom, :service_rollover_time, ~T[03:00:00]
6462

6563
config :dotcom, :timezone, "America/New_York"

‎config/runtime.exs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ config :dotcom,
197197
env: config_env(),
198198
env_name: System.get_env("SENTRY_ENVIRONMENT"),
199199
# soon: use a better env var name
200-
is_prod_env?: System.get_env("SENTRY_ENVIRONMENT") == "prod"
200+
is_prod_env?: System.get_env("SENTRY_ENVIRONMENT") == "prod",
201+
version: System.get_env("SENTRY_RELEASE", "missing-version")
201202

202203
if System.get_env("LOGGER_LEVEL") in ~w(emergency alert critical error warning notice info debug all none) &&
203204
config_env() != :test do

‎deploy/dotcom/prod/Dockerfile‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ FROM hexpm/elixir:1.20.4-erlang-29.0.6-alpine-3.23.5 AS builder
44
ENV LANG="C.UTF-8" MIX_ENV="prod"
55
ENV CYPRESS_INSTALL_BINARY=0
66
ARG SENTRY_DSN=""
7-
ARG SENTRY_RELEASE
8-
ENV SENTRY_RELEASE=${SENTRY_RELEASE}
97

108
WORKDIR /home
119

@@ -50,5 +48,8 @@ RUN apk add libssl3
5048
COPY --from=builder /home/_build /home/_build
5149

5250
# RUN
51+
ARG SENTRY_RELEASE
52+
ENV SENTRY_RELEASE=${SENTRY_RELEASE}
53+
5354
EXPOSE 4000
5455
CMD ["/home/_build/prod/rel/dotcom/bin/dotcom", "start"]

‎lib/dotcom/cache/key_generator.ex‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ defmodule Dotcom.Cache.KeyGenerator do
33
Generate a readable cache key based on the module, function, and arguments.
44
"""
55

6-
@version Application.compile_env(:dotcom, :version)
7-
86
@behaviour Nebulex.Caching.KeyGenerator
97

108
@impl Nebulex.Caching.KeyGenerator
119
def generate(mod, fun, args) do
10+
version = Application.get_env(:dotcom, :version)
1211
unique_id = args |> inspect() |> Base.encode64()
1312

1413
module_name =
1514
Util.get_or_save_persistent_term({:key_generator, mod}, fn -> clean_mod(mod) end)
1615

17-
"#{module_name}|#{fun}|#{unique_id}|#{@version}"
16+
"#{module_name}|#{fun}|#{unique_id}|#{version}"
1817
end
1918

2019
defp clean_mod(mod) do

‎lib/dotcom_web/controllers/version_controller.ex‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ defmodule DotcomWeb.VersionController do
44
"""
55
use DotcomWeb, :controller
66

7-
@version Application.compile_env(:dotcom, :version)
8-
97
def version(conn, _params) do
8+
version = Application.get_env(:dotcom, :version)
9+
1010
conn
1111
|> put_resp_content_type("text/plain")
12-
|> send_resp(:ok, @version)
12+
|> send_resp(:ok, version)
1313
end
1414
end

‎test/dotcom_web/controllers/version_controller_test.exs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ defmodule DotcomWeb.VersionControllerTest do
22
@moduledoc false
33
use DotcomWeb.ConnCase
44

5-
@version Application.compile_env(:dotcom, :version)
6-
75
describe "version/2" do
86
test "returns 200 with the configured version", %{conn: conn} do
7+
version = Application.get_env(:dotcom, :version)
8+
99
response = get(conn, version_path(conn, :version))
1010
assert response.status == 200
11-
assert response.resp_body == @version
11+
assert response.resp_body == version
1212
assert get_resp_header(response, "content-type") == ["text/plain; charset=utf-8"]
1313
end
1414
end

0 commit comments

Comments
 (0)