I have a project I want to deploy a release build for, and so I’ve written a docker file that I believe should work, but when I start my app I get the below error. The frustrating part of this is that I feel like I’ve had this error before and after a lot of time I solved it… somehow. But I don’t remember how.
(UndefinedFunctionError) function MyApp.Application.start/2 is undefined (module MyApp.Application is not available)
So everything works in dev mode with iex -S mix. Application starts and everything runs just fine. The module does exist. The docker build does work, and the release files are all generated, so far as I can tell. But something is missing somewhere.
Here’s the docker file
FROM elixir:1.7.4 as release
RUN mkdir /app
WORKDIR /app
RUN mix local.hex --force && \
mix local.rebar --force
ENV MIX_ENV=prod
COPY mix.exs mix.lock ./
COPY config ./config
RUN mix deps.get
RUN mix deps.compile
COPY rel rel/
RUN mix release --no-tar --verbose --env=prod
FROM erlang:21 as prod
RUN mkdir /app && chown -R nobody: /app
WORKDIR /app
USER nobody
ENV HOME=/app
COPY --from=release /app/_build/prod/rel/myapp ./
And my mix.exs
defmodule MyApp.Mixfile do
use Mix.Project
def project do
[app: :myapp,
version: "0.2.0",
elixir: "~> 1.7.4",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps()]
end
# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
def application do
[
extra_applications: [:logger],
mod: {MyApp.Application, []},
]
end
defp deps do
[
{:httpotion, "~> 3.0"},
{:distillery, "~> 2.0"}
]
end
end
And my rel/config.exs is just the standard thing that mix release.init tosses out. I can’t find anything in it to change that seems to help.
I’ve tried adding :myapp
to various of :applications
, :included_applications
, and such but it causes an infinite loop when I try to run it with iex -S mix
or causes the release to get into an infinite loop.
Has anyone seen this before? I feel like I’ve spent a lot of time on this with no progress.