fusillicode

fusillicode

Hi :slight_smile:

I’m having an hard times trying to figure out “the best” way to build a “simple” Elixir script (or task) that should run scheduled by a k8s job.

I know that Elixir doesn’t actually address this kind of use cases but I would really like use it considering the great experience I had in the past.

I’ve already implemented some tasks (mix tasks) to accomplish some data transformations with Flow & other libs and I would really love to replicate the experience but in a containerized environment.

The task that I need to implement would need to fetch some data from some REST APIs, query a DB and save some info inside it. So I’ll have a few dependencies to libs like postgrex & httpoison.

Is there an easy way to accomplish what I have in mind? :thinking:

Thanks in advance to everyone :smile:

Showing Posts 1 to 10

OvermindDL1

OvermindDL1

One you have an escript the Dockerfile should be as simple as just FROM an existing elixir docker, adding the file to it, and setting it as the entrypoint, pretty much the same as any normal docker runner. :slight_smile:

Just doing a full proper release with distillery and having it make the docker for you is good too, plus then you get dependencies!

fusillicode

fusillicode OP

Thanks a lot for the support :smiley:

You’re totally right, but the tricky part is also that I want to build the escript directly inside the container to make it totally dependent to it so that I can share just the built image.

Right now I’ve managed to accomplish something with the following Dockerfile but I’m sincerely not sure about the COPY . .

# Dockerfile

FROM elixir:1.7.3-alpine

# install build dependencies

RUN apk add --update git

# prepare build dir

RUN mkdir /app

WORKDIR /app

# install hex + rebar

RUN mix local.hex --force && \

mix local.rebar --force

# set build ENV

ENV MIX_ENV=prod

# install mix dependencies

# COPY mix.exs mix.lock ./

# COPY config ./

# COPY deps ./

# COPY lib ./

COPY . .

RUN mix deps.get && \

mix escript.build

ENTRYPOINT ["./myscript"]
NobbZ

NobbZ

A good first step, now it’s time to make it multistage to squeeze the very last byte out of it.

fusillicode

fusillicode OP

@NobbZ that is the main goal & concern! :wink:

Actually, I’ve also another big concern about the possibility to use libs like Flow inside my script :thinking:

NobbZ

NobbZ

After mix build.escript (or whatever that task was named), the escript should be self-contained (except for Erlang).

OvermindDL1

OvermindDL1

All easily done and in fact should be done by the Dockerfile itself. :slight_smile:

Honestly at that point I wouldn’t COPY anything in but rather have it git clone ... and etc… to build it all inside it in full. :slight_smile:

You could even wipe the content you don’t need from it when done to minimize size if you want.

fusillicode

fusillicode OP

Got it.

One last (I hope) concern…I’m just trying (almost live) to pass ENV vars both by building & running the script locally on my machine & through docker.

Unfortunately, as I expected, their not properly evaluated.

P.S: I’m just trying to find the post that describe the issue with ENV and compilation that I’ve read just a little while ago :sweat_smile:

sneako

sneako

I have only deployed one escript in a docker container in the past, and to get around this issue of reading from ENV, I included a bash script, which was used as the docker entry point, and in this bash script I call the escript passing in any env vars the script needs as arguments like ./my_script --env-var $MY_ENV_VAR.

However, I suspect the forum may provide us with a better way :slight_smile:

fusillicode

fusillicode OP

Got it but unfortunately I don’t think that a solution like the one you’re suggesting would fit my needs :frowning_face:

I’ve quite a lot ENV vars that I need to pass to my script, mainly DB related stuff as well as some REST API config.

Just for you to know I’m actually trying to use the ENV RELX_REPLACE_OS_VARS=true inside my build and then get the vars out with System.get_env("VAR") but right now I didn’t had any success :disappointed_face:

I’ve also tried to use Mix.Config but considering that I don’t have an application running but only a simple script it seems that it would not fit my needs either.

NobbZ

NobbZ

In an escript you can simply read the os-environment and write to the app-environment. There shouldn’t be any issues.

— All posts loaded —

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
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
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
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
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews