bryanhuntesl
Bundling scripts (mix ecto.setup etc) with new elixir releases
I’ve done this a lot when using distillery - for example, bundling a script which will execute an ecto.migration task.
Here’s an example of with this kind of configuration.
The reason this is important is for kubernetes. Kubernetes has various lifecycle hooks such as healthcheck, startup, etc.
It’s very nice to provide the cluster administrators with the means to run extra tasks - and it’s even nicer when you package this with the application so that you have targets like this :
docker run --rm -ti \
-e POSTGRES_HOSTNAME=postgres.notifications \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DATABASE=notifications_dev \
-e DATADOG_AGENT_HOSTNAME=localhost \
-e DATADOG_AGENT_APM_PORT=8126 \
-e EXQ_HOST=redis.notifications \
-e EXQ_PASSWORD= \
-e EXQ_PORT=6379 \
-e EXQ_NAMESPACE=exq \
--name notificatons \
--network notifications \
--hostname notifications \
-p 4000:4000 \
foo/notifications:latest help
Usage: notifications COMMAND [ARGS]
The known commands are:
start Starts the system
start_iex Starts the system with IEx attached
daemon Starts the system as a daemon
daemon_iex Starts the system as a daemon with IEx attached
eval "EXPR" Executes the given expression on a new, non-booted system
rpc "EXPR" Executes the given expression remotely on the running system
remote Connects to the running system via a remote shell
restart Restarts the running system via a remote command
stop Stops the running system via a remote command
pid Prints the OS PID of the running system via a remote command
version Prints the release name and version to be booted
--> run_migration Run ecto migration
--> update_email_templates Update email templates (for example)
ERROR: Unknown command help
Marked As Solved
josevalim
Elixir v1.10 supports overlays, so you can also just drop those scripts in rel/overlays/bin/ without changing your mix.exs. ![]()
Also Liked
josevalim
You can define them in lib. Here is an example from Phoenix release guides: Deploying with Releases — Phoenix v1.8.8
LostKobrakai
That‘s what I‘ve gone with:
https://github.com/LostKobrakai/doist
josevalim
@bryanhuntesl to be clear, I mean it could be called bin/setup-db and inside it does ./my_app eval "..." and that’s all. ![]()
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








