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 versionreturns the expected0.1.1 - the file
releases/start_erl.datacontains15.2.1 0.1.1(the later is the version) - the folder in
releases/0.1.1exists
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?






















