bryanhuntesl

bryanhuntesl

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

Showing Posts 1 to 10

bryanhuntesl

bryanhuntesl OP

bryanhuntesl

bryanhuntesl OP

Not getting a lot of responses - might need to go back to using distillery

bryanhuntesl

bryanhuntesl OP

So I actually read the docs properly - and there is some description given to adding custom tasks -mix release — Mix v1.20.2

What I’m wondering though, is what’s the idiomatic way to package them up nicely with the bin/ init script? Is there a standard extension point?

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

bryanhuntesl

bryanhuntesl OP

Apologies - I’ve communicated appallingly badly, so what I’d like to do (end user ergonomics/tight integration) is build in such a way that rather than the end user invoking:

$ _build/prod/rel/my_app/bin/my_app eval "MyApp.Release.migrate"

The end user invokes:

$ _build/prod/rel/my_app/bin/my_app migrate

I should have asked is there an extension point or idiomatic way to extend the startup script.

josevalim

josevalim

Creator of Elixir

Ah, ok! No, there isn’t a way today to extend the built-in script. We considered this but we are unsure if this is really the direction we want to go. For example, wouldn’t it be better to have separate script in bin/? Or maybe, if the goal is to provide an API for users with no experience of Elixir, have a separate script altogether?

LostKobrakai

LostKobrakai

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

bryanhuntesl

bryanhuntesl OP

A script in bin for running mix ecto.setup ? Apart from hard coding, how would it know where the application code, etc lived?

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:

bryanhuntesl

bryanhuntesl OP

That’s a pragmatic solution - I’ll give it a go - I was getting too dogmatic there - still, I’d consider distillery’s approach just from the perspective of UX.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews