bryanhuntesl

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

josevalim

Creator of Elixir

Elixir v1.10 supports overlays, so you can also just drop those scripts in rel/overlays/bin/ without changing your mix.exs. :slight_smile:

Also Liked

josevalim

josevalim

Creator of Elixir

You can define them in lib. Here is an example from Phoenix release guides: Deploying with Releases — Phoenix v1.8.8

LostKobrakai

LostKobrakai

That‘s what I‘ve gone with:
https://github.com/LostKobrakai/doist

josevalim

josevalim

Creator of Elixir

@bryanhuntesl to be clear, I mean it could be called bin/setup-db and inside it does ./my_app eval "..." and that’s all. :slight_smile:

Where Next?

Popular in Questions Top

greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement