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

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
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
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
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

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
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

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews