Skip to content

Commit 05b2b05

Browse files
committed
reuse from gamend core
upd
1 parent 9c931a3 commit 05b2b05

9 files changed

Lines changed: 111 additions & 94 deletions

File tree

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ SECRET_KEY_BASE=your_secret_key_base_here
3434
# -----END PRIVATE KEY-----"
3535

3636
# PostgreSQL Database Configuration (optional)
37-
# If not set, the app will use SQLite for development
37+
# If not set, the app will use SQLite for development.
38+
# NOTE: the database adapter is chosen at COMPILE time. After changing these,
39+
# run: mix deps.clean game_server_core game_server_web --build
40+
# and recompile (the app refuses to start on a stale build and says the same).
3841
# POSTGRES_HOST=localhost
3942
# POSTGRES_PORT=5432
4043
# POSTGRES_USER=postgres

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# July 2026
2+
3+
- [fixed] Broken `db.setup` seeds step (`--if-present` isn't real).
4+
- [changed] `db.*` aliases and `host.*` tasks come from `game_server_core`.
5+
- [added] `.env` loads in dev, including compile time.
6+
17
# March 2026
28

39
- [added] Updated the starter

config/config.exs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
# General application configuration
88
import Config
99

10+
# In dev, load .env into the environment before anything reads System.get_env.
11+
# This file runs at compile time, so .env can drive compile-time settings —
12+
# most importantly the database adapter (see the Repo config in dev.exs).
13+
if config_env() == :dev do
14+
Code.require_file("dotenv.exs", __DIR__)
15+
GameServer.Dotenv.load(Path.expand("../.env", __DIR__))
16+
end
17+
1018
config :game_server_web, :scopes,
1119
user: [
1220
default: true,
@@ -38,7 +46,10 @@ config :game_server_web,
3846
host_static_paths: ~w(images game fonts audio favicon.ico robots.txt .well-known theme.css)
3947

4048
# Adapter selection (compile-time). Override with DATABASE_ADAPTER=postgres
41-
# at build time for production Postgres deployments.
49+
# at build time for production Postgres deployments. In dev, setting
50+
# POSTGRES_*/DATABASE_URL (shell or .env) makes dev.exs override this with
51+
# Postgres; after changing them, recompile:
52+
# mix deps.clean game_server_core game_server_web --build && mix compile
4253
default_adapter =
4354
if System.get_env("DATABASE_ADAPTER") == "postgres",
4455
do: Ecto.Adapters.Postgres,

config/dotenv.exs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Shared .env loader, used both at compile time (host_config.exs, so .env can
2+
# select compile-time settings like the database adapter) and at runtime
3+
# (host_runtime.exs). Loaded via Code.require_file — requiring the same path
4+
# twice is a no-op, so the module is defined once per VM.
5+
defmodule GameServer.Dotenv do
6+
@moduledoc false
7+
8+
# Parses KEY=VALUE lines — comments, "quoted values", multiline quoted
9+
# values, and \n escapes — and puts them into the System environment.
10+
# Real environment variables always win over .env entries.
11+
def load(env_path) do
12+
if File.exists?(env_path) do
13+
env_path
14+
|> File.read!()
15+
|> parse()
16+
|> Enum.each(fn {key, value} ->
17+
if is_nil(System.get_env(key)) do
18+
System.put_env(key, value)
19+
end
20+
end)
21+
end
22+
23+
:ok
24+
end
25+
26+
defp parse(contents) do
27+
contents
28+
|> String.split("\n")
29+
|> Enum.reduce({nil, []}, &parse_line/2)
30+
|> elem(1)
31+
|> Enum.reverse()
32+
end
33+
34+
# Inside a multiline quoted value: accumulate until a line ends with a quote.
35+
defp parse_line(line, {{key, value_lines}, entries}) do
36+
trimmed = String.trim_trailing(line)
37+
38+
if String.ends_with?(trimmed, "\"") do
39+
value =
40+
[String.trim_trailing(trimmed, "\"") | value_lines]
41+
|> Enum.reverse()
42+
|> Enum.join("\n")
43+
44+
{nil, [{key, value} | entries]}
45+
else
46+
{{key, [line | value_lines]}, entries}
47+
end
48+
end
49+
50+
defp parse_line(line, {nil, entries}) do
51+
if String.trim(line) == "" or String.starts_with?(String.trim_leading(line), "#") do
52+
{nil, entries}
53+
else
54+
case String.split(line, "=", parts: 2) do
55+
[key, value] -> parse_entry(String.trim(key), String.trim(value), entries)
56+
_ -> {nil, entries}
57+
end
58+
end
59+
end
60+
61+
defp parse_entry("", _value, entries), do: {nil, entries}
62+
63+
defp parse_entry(key, value, entries) do
64+
if String.starts_with?(value, "\"") and not String.ends_with?(value, "\"") do
65+
# Opening quote without a closing one — start of a multiline value.
66+
{{key, [String.trim_leading(value, "\"")]}, entries}
67+
else
68+
value =
69+
value
70+
|> String.trim_leading("\"")
71+
|> String.trim_trailing("\"")
72+
|> String.replace("\\n", "\n")
73+
74+
{nil, [{key, value} | entries]}
75+
end
76+
end
77+
end

config/runtime.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import Config
22

3+
# .env is already loaded by config.exs during config evaluation; this is
4+
# kept as a safety net. (Code.require_file is a no-op when the file was
5+
# already required.)
6+
if config_env() == :dev do
7+
Code.require_file("dotenv.exs", __DIR__)
8+
GameServer.Dotenv.load(Path.expand("../.env", __DIR__))
9+
end
10+
311
default_theme_config = Path.expand("../modules/starter_config.json", __DIR__)
412

513
# The starter ships with a packaged theme config. Older game_server_core builds

lib/mix/tasks/host.migrate.ex

Lines changed: 0 additions & 43 deletions
This file was deleted.

lib/mix/tasks/host.rollback.ex

Lines changed: 0 additions & 41 deletions
This file was deleted.

mix.exs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,8 @@ defmodule GameServerHost.MixProject do
9292
"prod.start": ["assets.deploy", "db.setup", "phx.server"],
9393
"db.migrate": ["host.migrate -r GameServer.Repo"],
9494
"db.rollback": ["host.rollback -r GameServer.Repo"],
95-
"db.setup": [
96-
"ecto.create -r GameServer.Repo",
97-
"db.migrate",
98-
"run --if-present priv/repo/seeds.exs"
99-
],
100-
"db.reset": ["ecto.drop -r GameServer.Repo", "db.setup"],
95+
"db.setup": ["host.db.setup"],
96+
"db.reset": ["host.db.reset"],
10197
test:
10298
[
10399
"ecto.create --quiet -r GameServer.Repo",

mix.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"exqlite": {:hex, :exqlite, "0.38.0", "324bca1d9b26d34b02ea64bd3724302a7d11978c682bc4a945186aeae7f61adb", [:make, :mix], [{:cc_precompiler, "~> 0.1", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.8", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "f3da7b6e7b08bd548c33a118890d0eb8c5395fe093b31c8b329663234d0e988e"},
4343
"file_system": {:hex, :file_system, "1.1.1", "31864f4685b0148f25bd3fbef2b1228457c0c89024ad67f7a81a3ffbc0bbad3a", [:mix], [], "hexpm", "7a15ff97dfe526aeefb090a7a9d3d03aa907e100e262a0f8f7746b78f8f87a5d"},
4444
"finch": {:hex, :finch, "0.23.0", "e3f9287ac25a8832f848b144c2b57346aac65b205e2e0629a52adfe6507fd837", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.8", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "80e58d3f936f57e3fdf404f83a3642897ae6d9fb642934e46da4d8fe761b99d5"},
45-
"game_server_core": {:git, "https://github.com/appsinacup/game_server.git", "a6263b7641272a6ac59fe7417e1e1e783de3cc1e", [sparse: "apps/game_server_core"]},
46-
"game_server_web": {:git, "https://github.com/appsinacup/game_server.git", "a6263b7641272a6ac59fe7417e1e1e783de3cc1e", [sparse: "apps/game_server_web"]},
45+
"game_server_core": {:git, "https://github.com/appsinacup/game_server.git", "f868f63079ce9fb5dbd1ce097a76473a82c626f8", [sparse: "apps/game_server_core"]},
46+
"game_server_web": {:git, "https://github.com/appsinacup/game_server.git", "f868f63079ce9fb5dbd1ce097a76473a82c626f8", [sparse: "apps/game_server_web"]},
4747
"gen_smtp": {:hex, :gen_smtp, "1.3.0", "62c3d91f0dcf6ce9db71bcb6881d7ad0d1d834c7f38c13fa8e952f4104a8442e", [:rebar3], [{:ranch, ">= 1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "0b73fbf069864ecbce02fe653b16d3f35fd889d0fdd4e14527675565c39d84e6"},
4848
"gen_stage": {:hex, :gen_stage, "1.3.2", "7c77e5d1e97de2c6c2f78f306f463bca64bf2f4c3cdd606affc0100b89743b7b", [:mix], [], "hexpm", "0ffae547fa777b3ed889a6b9e1e64566217413d018cabd825f786e843ffe63e7"},
4949
"geolix": {:hex, :geolix, "2.1.0", "e46b0ec57a1ee2f6969e552f4195644bc883ba099ea72761e21d99f778ef0bd3", [:mix], [], "hexpm", "0b871bc2db8efd0114d1fd7087c83180056a1fff20d90946c89d32200e368651"},

0 commit comments

Comments
 (0)