-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathmix.exs
More file actions
349 lines (313 loc) · 10.8 KB
/
mix.exs
File metadata and controls
349 lines (313 loc) · 10.8 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
if System.otp_release() < "25" do
Mix.raise("Livebook requires Erlang/OTP 25+")
end
defmodule Livebook.MixProject do
use Mix.Project
@elixir_requirement "~> 1.18"
@version "0.20.0-dev"
@description "Automate code & data workflows with interactive notebooks"
def project do
[
app: :livebook,
version: @version,
elixir: @elixir_requirement,
name: "Livebook",
description: @description,
elixirc_paths: elixirc_paths(Mix.env()),
test_elixirc_options: [docs: true],
compilers: [:phoenix_live_view] ++ Mix.compilers() ++ [:ensure_livebook_priv],
start_permanent: Mix.env() == :prod,
listeners: [Phoenix.CodeReloader],
aliases: aliases(),
deps: with_lock(target_deps(Mix.target()) ++ deps()),
escript: escript(),
package: package(),
default_release: :livebook,
releases: releases(),
# Docs
homepage_url: "https://livebook.dev",
docs: &docs/0
]
end
def application do
env = Application.get_all_env(:livebook)
[
mod: {Livebook.Application, []},
extra_applications: [
:logger,
:runtime_tools,
:os_mon,
:inets,
:ssl,
:xmerl,
:crypto,
:public_key
],
# Erase live reload as it contains regexes which fails
# when loaded in the next run
env: put_in(env[LivebookWeb.Endpoint][:live_reload], [])
]
end
defp elixirc_paths(:test), do: elixirc_paths(:dev) ++ ["test/support"]
defp elixirc_paths(_), do: ["lib", "proto/lib"]
defp package do
[
licenses: ["Apache-2.0"],
links: %{
"GitHub" => "https://github.com/livebook-dev/livebook"
},
# Note that when publishing, we include pre-built priv and not assets.
files: ~w(lib config priv mix.exs mix.lock README.md LICENSE CHANGELOG.md proto/lib)
]
end
defp aliases do
[
setup: ["deps.get", "assets.setup"],
"setup.prod": ["deps.get --prod", "assets.setup"],
"assets.setup": ["bun.install --if-missing", "bun assets install", "assets.build"],
"assets.build": ["bun assets run build"],
"format.all": ["format", "bun assets run --silent format"],
"protobuf.generate": ["cmd --cd proto mix protobuf.generate"],
# Always build priv/ before publishing to Hex, so that no build
# is required on escript installation.
"hex.publish": [
"assets.setup",
# Compilation prunes code paths, so Hex task modules are no
# longer available. We need to bring the application back
# explicitly, in order to access its modules.
fn _ -> Mix.ensure_application!(:hex) end,
"hex.publish"
]
]
end
defp escript do
[
main_module: LivebookCLI,
app: nil,
emu_args: "-epmd_module Elixir.Livebook.EPMD",
include_priv_for: [:livebook]
]
end
## Dependencies
# Although we use requirements here, the with_lock() function
# below ensures we only use the locked versions. This is important
# for two reasons:
#
# 1. because we bundle assets from phoenix, phoenix_live_view,
# and phoenix_html, we want to make sure we have those exact
# versions
#
# 2. we don't want users to potentially get a new dependency
# when installing from git or as an escript
#
# Therefore, to update any dependency, you must call before:
#
# mix deps.unlock foo bar baz
#
defp deps do
[
{:phoenix, "~> 1.8"},
{:phoenix_live_view, "~> 1.1.0"},
{:phoenix_html, "~> 4.0"},
{:phoenix_live_dashboard, "~> 0.8.4"},
{:telemetry_metrics, "~> 1.0"},
{:telemetry_poller, "~> 1.0"},
{:bandit, "~> 1.0"},
{:plug, "~> 1.16"},
{:plug_crypto, "~> 2.0"},
{:earmark_parser, "~> 1.4.44"},
{:ecto, "~> 3.10"},
{:phoenix_ecto, "~> 4.4"},
{:aws_credentials, "~> 0.3.0", runtime: false},
{:mint_web_socket, "~> 1.0.0"},
{:protobuf, "~> 0.13.0"},
{:dns_cluster, "~> 0.1.2"},
{:kubereq, "~> 0.4.0"},
{:yaml_elixir, "~> 2.11"},
{:logger_json, "~> 6.1"},
{:req, "~> 0.5.8"},
{:nimble_zta, "~> 0.1.0"},
{:bun, "~> 1.6", runtime: Mix.env() == :dev},
# Dev tools
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:tidewave, "~> 0.5", only: :dev},
# Tests
{:lazy_html, "~> 0.1.0", only: :test},
{:bypass, "~> 2.1", only: :test},
{:pythonx, "~> 0.4.2", only: :test},
{:kino, "~> 0.18.0", only: :test},
# Docs
{:ex_doc, "~> 0.39", only: :dev, runtime: false}
]
end
defp target_deps(:app), do: [{:elixirkit, path: "elixirkit"}]
defp target_deps(:app_next), do: [{:elixirkit, path: "elixirkit_next"}]
defp target_deps(_), do: []
@lock (with {:ok, contents} <- File.read("mix.lock"),
{:ok, quoted} <-
Code.string_to_quoted(contents,
warn_on_unnecessary_quotes: false,
emit_warnings: false
),
{%{} = lock, _binding} <- Code.eval_quoted(quoted, []) do
for {dep, hex} when elem(hex, 0) == :hex <- lock,
do: {dep, elem(hex, 2)},
into: %{}
else
_ -> %{}
end)
defp with_lock(deps) do
for dep <- deps do
name = elem(dep, 0)
put_elem(dep, 1, @lock[name] || elem(dep, 1))
end
end
## Releases
# aws_credentials has runtime: false, so explicitly add is as :load
@release_apps [livebook: :permanent, aws_credentials: :load]
defp releases do
[
livebook: [
applications: @release_apps,
include_executables_for: [:unix, :windows],
include_erts: false,
rel_templates_path: "rel/server",
steps: [:assemble, &remove_cookie/1, &write_runtime_modules/1]
],
app: [
applications: @release_apps,
include_erts: false,
rel_templates_path: "rel/#{Mix.target()}",
steps: [
:assemble,
&remove_cookie/1,
&standalone_erlang_elixir/1
]
]
]
end
if Mix.target() == :app_next do
{cargo_output, 0} = System.cmd("cargo", ["pkgid"], cd: "#{__DIR__}/rel/app_next/src-tauri")
[_, cargo_version] = Regex.run(~r/#.+@(.+)$/, String.trim(cargo_output))
if @version != cargo_version do
Mix.raise("""
Version mismatch:
mix.exs: #{@version}
Cargo.toml: #{cargo_version}
""")
end
end
defp remove_cookie(release) do
# We remove the COOKIE file when assembling the release, because we
# don't want to share the same cookie across users.
File.rm!(Path.join(release.path, "releases/COOKIE"))
release
end
defp write_runtime_modules(release) do
# We copy the subset of Livebook modules that are injected into
# the runtime node. See overlays/bin/server for more details
app = release.applications[:livebook]
source = Path.join([release.path, "lib", "livebook-#{app[:vsn]}", "ebin"])
destination = Path.join([release.path, "lib", "livebook_runtime_ebin"])
File.mkdir_p!(destination)
for module <- Livebook.Runtime.ErlDist.required_modules() do
from = Path.join(source, "#{module}.beam")
to = Path.join(destination, "#{module}.beam")
File.cp!(from, to)
end
release
end
@compile {:no_warn_undefined, Standalone}
defp standalone_erlang_elixir(release) do
{_, bindings} = Code.eval_file("versions")
elixir_version = bindings[:elixir]
rebar3_version = bindings[:rebar3]
Code.require_file("rel/app/standalone.exs")
release
|> Standalone.copy_otp()
|> Standalone.copy_elixir(elixir_version)
|> Standalone.copy_hex()
|> Standalone.copy_rebar3(rebar3_version)
end
defp docs() do
[
logo: "assets/public/images/logo.png",
main: "readme",
api_reference: false,
extra_section: "Guides",
extras: extras(),
filter_modules: fn mod, _ -> mod in [Livebook] end,
assets: %{Path.expand("./docs/images") => "images"},
before_closing_head_tag: &before_closing_head_tag/1,
groups_for_extras: [
"Livebook Teams": Path.wildcard("docs/teams/*"),
Deployment: Path.wildcard("docs/deployment/*"),
"Airgapped Authentication": Path.wildcard("docs/authentication/*")
]
]
end
defp extras() do
[
{"README.md", title: "Welcome to Livebook"},
"docs/use_cases.md",
"docs/authentication.md",
{"docs/runtime.md", title: "Runtimes"},
"docs/stamping.md",
"docs/deployment/docker.md",
"docs/deployment/clustering.md",
"docs/deployment/fips.md",
"docs/deployment/nginx_https.md",
"docs/teams/intro_to_teams.md",
{"docs/teams/deploy_app.md", title: "Deploy Livebook apps"},
{"docs/teams/deploy_via_cli.md", title: "Deploy Livebook apps via CLI"},
"docs/teams/deploy_permissions.md",
{"docs/teams/app_folders.md", title: "Organize apps with folders"},
{"docs/teams/app_server_production.md", title: "Production app servers"},
{"docs/teams/email_domain.md", title: "Email domain auth"},
{"docs/teams/oidc_sso.md", title: "OIDC SSO"},
"docs/teams/oidc_groups.md",
"docs/teams/shared_secrets.md",
"docs/teams/shared_file_storages.md",
{"docs/teams/git_file_storage.md", title: "Open notebooks from a private Git"},
{"docs/teams/phoenix_integration.md", title: "Integrate with a Phoenix app"},
{"docs/teams/audit_logs.md", title: "Audit logs for code execution"},
{"docs/teams/teams_concepts.md", title: "Livebook Teams concepts"},
"docs/authentication/basic_auth.md",
"docs/authentication/cloudflare.md",
"docs/authentication/google_iap.md",
"docs/authentication/tailscale.md",
"docs/authentication/custom_auth.md"
]
end
defp before_closing_head_tag(:html) do
"""
<script defer src="https://cdn.jsdelivr.net/npm/mermaid@10.2.3/dist/mermaid.min.js"></script>
<script>
let initialized = false;
window.addEventListener("exdoc:loaded", () => {
if (!initialized) {
mermaid.initialize({
startOnLoad: false,
theme: document.body.className.includes("dark") ? "dark" : "default"
});
initialized = true;
}
let id = 0;
for (const codeEl of document.querySelectorAll("pre code.mermaid")) {
const preEl = codeEl.parentElement;
const graphDefinition = codeEl.textContent;
const graphEl = document.createElement("div");
const graphId = "mermaid-graph-" + id++;
mermaid.render(graphId, graphDefinition).then(({svg, bindFunctions}) => {
graphEl.innerHTML = svg;
bindFunctions?.(graphEl);
preEl.insertAdjacentElement("afterend", graphEl);
preEl.remove();
});
}
});
</script>
"""
end
defp before_closing_head_tag(_), do: ""
end