LukasKnuth

LukasKnuth

I’m using the standard Dockerfile generated by mix phx.gen.release --docker with a small change:

# Compile the release
ARG APP_VERSION
RUN mix compile

The added ARG expression accepts a Docker build-arg that I supply when building the image:

docker build . -t my_app --build-arg APP_VERSION=0.1.1

In my mix.exs I load the data from the Environment variable:

defmodule MyApp.MixProject do
  use Mix.Project

  def project do
    [ #Other config
      version: version()
    ]
  end

  def version do
    System.get_env("APP_VERSION", "0.0.0-local")
  end
end

I’m expecting that MyApp.MixProject.version/0 is invoked at compile time and that the ENV variable is read then and “baked” into the final release.
This seems to be true partially:

  • during image build it logs: assembling my_app-0.1.1 on MIX_ENV=prod
  • running bin/my_app version returns the expected 0.1.1
  • the file releases/start_erl.data contains 15.2.1 0.1.1 (the later is the version)
  • the folder in releases/0.1.1 exists

All this seems to indicate that it worked fine, but at runtime, i get the fallback value:

iex> Application.spec(:my_app, :vsn)
~c"0.0.0-local"

I can’t figure out why it seems to work everywhere except for the Application spec.

I have also tried setting the APP_VERSION env variable to some other string to see if it might be evaluated at runtime - it still returns "0.0.0-local". What am I overlooking?

Showing Posts 1 to 4

arcanemachine

arcanemachine

Off the top of my head, I would try this:

ARG APP_VERSION
ENV APP_VERSION=$APP_VERSION

build arg != environment variable

EDIT: On second thought, maybe just skip the build arg part altogether and pass it as an environment variable:

docker build . -t my_app -e APP_VERSION=0.1.1

Then, I don’t think you would need to put anything in the Dockerfile.

LostKobrakai

LostKobrakai

Not sure if that’s helpful, but all the places where things worked are the result of mix release, while Application.spec uses the .app file of the compiled application as created by mix compile. The .app file would be in lib/my_app-{version}/ebin/my_app.app of the release.

LukasKnuth

LukasKnuth OP

Bingo! Even the folder is called lib/my_app-0.0.0-local/. I have moved the ARG APP_VERSION instruction higher in the Dockerfile, just below ENV MIX_ENV="prod" and now everything works as expected!

I wonder what step really creates the .app file, because I had the instruction right above mix compile before (where it didn’t work). After moving it, the following commands now also receive it:

  • mix deps.get
  • mix deps.compile
  • mix assets.deploy

None of which seems like an obvious candidate to me.

rhcarvalho

rhcarvalho

One of those might be doing it as a side effect of their transitive dependencies. You don’t have to call “mix compile” exclusively to trigger compilation (and in that case your RUN mix compile line was likely a no-op.)

For example, it happens all the time when you run mix test – code is first compiled, then the test suite is run.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
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
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
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

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews