Repository navigation
Expand file tree
/
Copy pathmix.exs
More file actions
186 lines (170 loc) · 7.21 KB
/
Copy pathmix.exs
File metadata and controls
186 lines (170 loc) · 7.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# Rename this module to match your project, e.g. MyGame.MixProject
# Also update: app: :my_game, name: "MyGame"
# and the Application module reference in application/0 below, and every
# :gamend_host in config/ (config.exs, prod.exs).
defmodule GamendHost.MixProject do
use Mix.Project
# The engine checkout, when one sits beside this app. Anchored to __DIR__
# rather than the cwd: `apps/gamend_web` was looked for relative to *this*
# project, which is not an umbrella and so never has it, and local mode could
# not be reached even with the sibling right there.
@local_gamend_root Path.expand("../gamend", __DIR__)
def project do
[
app: :gamend_host,
name: "Gamend",
version: System.get_env("APP_VERSION") || "1.0.0",
elixir: "~> 1.20",
elixirc_paths: ["lib"],
start_permanent: Mix.env() == :prod,
listeners: [Phoenix.CodeReloader],
aliases: aliases(),
# Writes `assets/vendor/gamend/`, the pointers `assets/css/app.css` loads
# Gamend core's stylesheet through (`mix gamend.assets`).
compilers: Mix.compilers() ++ [:gamend_assets],
deps: deps()
]
end
def application do
[
mod: {GamendHost.Application, []},
extra_applications:
[:logger, :runtime_tools, :swoosh, :sentry] ++
if(Mix.env() == :prod, do: [:os_mon], else: [])
]
end
def cli do
[
preferred_envs: [precommit: :test, "precommit.full": :test]
]
end
# Only what this app adds on top of the engine — versions for everything else
# come from gamend_web/gamend_core, whether they resolve as a sibling path
# checkout or as Hex releases. A dep earns a line here only if the engine
# does not declare it (sentry, castore, mix_audit), declares it `only: :dev`/
# `only: :test` (Mix does not propagate those to a parent), or it is not on
# Hex (heroicons).
defp deps do
[
shared_dep(:gamend_core, "apps/gamend_core"),
shared_dep(:gamend_web, "apps/gamend_web"),
{:phoenix_live_reload, "~> 1.7", only: :dev},
{:castore, "~> 1.0"},
{:sentry, "~> 13.5"},
{:credo, ">= 1.7.19", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.40", only: :dev, runtime: false},
{:mix_audit, "~> 2.1", only: [:dev, :test], runtime: false},
{:heroicons,
github: "tailwindlabs/heroicons",
tag: "v2.2.0",
sparse: "optimized",
app: false,
compile: false,
depth: 1}
]
end
defp aliases do
[
setup: ["deps.get", "db.setup", "assets.setup", "assets.build"],
"deps.get": &deps_get/1,
# `mix deps.update --all` only rewrites the lockfile of the project it
# runs in. The plugins under modules/plugins are Mix projects of their
# own, so a root-only update leaves them pinned to stale versions.
"deps.update.all": ["cmd bin/update-deps"],
"dev.start": [
"ecto.create --quiet -r Gamend.Repo",
"db.migrate",
"assets.build",
"phx.server"
],
"prod.start": ["assets.deploy", "db.setup", "phx.server"],
"db.migrate": ["host.migrate -r Gamend.Repo"],
"db.rollback": ["host.rollback -r Gamend.Repo"],
"db.setup": ["host.db.setup"],
"db.reset": ["host.db.reset"],
test: ["ecto.create --quiet -r Gamend.Repo", "host.migrate --quiet -r Gamend.Repo", "test"],
lint: ["format --check-formatted", "credo --strict"],
# Light inner loop; precommit.full adds deps.audit, run before a push.
precommit: [
"compile --warnings-as-errors",
"format",
# The Dockerfile is Gamend's, filled in from this mix.exs.
"gamend.gen.dockerfile",
# A release moves nothing Docker keys on: this commit takes it.
"gamend.latest",
"test",
"credo --strict",
"gamend.api.lint",
"gamend.literal.lint"
],
"precommit.full": ["precommit", "deps.audit"],
"assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"],
"assets.build": ["compile", "tailwind gamend_web", "esbuild gamend_web"],
"assets.deploy": [
"tailwind gamend_web --minify",
"esbuild gamend_web --minify",
"phx.digest",
# After the digest, because it is the hashed copies that get served.
# phx.digest writes .gz; this adds the .br that brotli_static wants.
"cmd bin/compress-static"
]
]
end
# GitHub's release-download redirect now carries ~11 KB of headers (a 9 KB
# content-security-policy), past :httpc's 10240-byte default, so every dep
# that fetches a release asset with :httpc fails with {:header_too_long,
# {:max, 10240}}: rustler_precompiled (the lumis and mdex_native NIFs) and
# elixir_make (exqlite's NIF, which then builds from source). In Docker, on
# CI, on any machine without them cached. Raise the limit in each after every
# fetch, and drop a copy built before the patch so Mix rebuilds it.
# Remove an entry once its dep ships a fix, as tailwind 0.5.2 did
# (rustler_precompiled: https://github.com/philss/rustler_precompiled/issues/113);
# the raise says when a patched line has moved.
@httpc_downloads [
rustler_precompiled: "lib/rustler_precompiled.ex",
elixir_make: "lib/elixir_make/downloader/httpc.ex"
]
defp deps_get(args) do
Mix.Tasks.Deps.Get.run(args)
unpatched = "options = [body_format: :binary]"
patched = "options = [body_format: :binary, max_header_size: 65_536]"
for {dep, path} <- @httpc_downloads,
file = Path.join([Mix.Project.deps_path(), Atom.to_string(dep), path]),
{:ok, source} <- [File.read(file)],
not String.contains?(source, patched) do
unless String.contains?(source, unpatched),
do: Mix.raise("#{dep} changed: revisit deps_get/1 in mix.exs")
File.write!(file, String.replace(source, unpatched, patched))
Mix.Project.build_path()
|> Path.dirname()
|> Path.join("*/lib/#{dep}")
|> Path.wildcard()
|> Enum.each(&File.rm_rf!/1)
end
end
# Two modes, and both have to work: the sibling checkout when you have one,
# otherwise the Hex release a fresh clone and the Docker build use. No
# `override:` on the Hex side — gamend_web asks for `gamend_core ~> 1.0`
# there, which this app's requirement narrows, so they converge on their
# own. Only the sibling path needs the engine's own source layout.
#
# The floor is the oldest release this code runs on. The lockfile holds no
# engine entry (it is a path dep locally), so a build takes whatever Hex has;
# without the floor a build that started before a release finished
# publishing compiled against the one before it and failed on a function
# that did not exist there yet. Raise it with any change that needs a newer
# engine.
@gamend_min "1.1.1474"
defp shared_dep(app, local_path) do
sibling_path = Path.join(@local_gamend_root, local_path)
if source_app?(sibling_path) do
{app, path: sibling_path}
else
{app, "~> 1.0 and >= #{@gamend_min}"}
end
end
# A mix.exs is the proof it is really a source checkout — a bare directory
# left behind by an earlier build is not.
defp source_app?(path), do: File.regular?(Path.join(path, "mix.exs"))
end