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?
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.
Just doing a full proper release with distillery and having it make the docker for you is good too, plus then you get dependencies!
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 . .
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
Got it but unfortunately I don’t think that a solution like the one you’re suggesting would fit my needs
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
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.