ymtszw
Equivalent to distillery's boot hooks in mix release? (Elixir 1.9)
Distillery has Boot Hooks, which can be utilized to e.g. run ecto migration scripts before application startup during deployment.
I am basically following “Running Migrations” guide in distillery, wiring the task onto pre-start hook.
Now that Elixir 1.9 and mix release come out, are there similar mechanisms?
Marked As Solved
josevalim
None (necessarily). You can use eval to run any code you want, including what Distillery would call a custom command (not to confuse with Distillery custom hooks). We have an example on the new Phoenix releases guides: phoenix/guides/deployment/releases.md at main · phoenixframework/phoenix · GitHub (not yet deployed).
Ecto v3.0 actually locks the migration table when running migrations, so this is safe unless you disable the migration lock.
Also Liked
josevalim
We don’t have hooks on purpose. ![]()
You can run them when your application starts, as proposed by @LostKobrakai. Alternatively, you can add your own script to the bin directory, that you use to run migrations and then start the release. You can do this by adding a step to your mix.exs:
def project do
[
...,
releases: [
my_app: [
steps: [:assemble, ©_bin_files/1]
]
]
]
end
where:
defp copy_bin_files(release) do
File.cp_r("rel/bin", Path.join(release.path, "bin"))
release
end
And you put the extra scripts in rel/bin.
LostKobrakai
Couldn’t you run them as part of application startup but before starting handling user input (like e.g. starting the phoenix endpoint)
ymtszw
I will examine both approaches. Thank you @LostKobrakai and @josevalim.
I am slightly inclined to “bring scripts with release” method since I would like to decouple scripts from application implementation.
BTW,
I am curious about the rationale here. Simplification, perhaps?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










