# syntax=docker/dockerfile:1.6 # # Builder: elixir-base (prebuilt hexpm/elixir + build-essential + git + hex + rebar) # https://git.mcintire.me/graham/elixir-base # Runtime: prop-base (prebuilt wgrib2 + cdo + gdal-bin, see Dockerfile.base) # ARG BUILDER_IMAGE="git.mcintire.me/graham/elixir-base:latest" # Prebuilt runtime base contains wgrib2 + cdo + gdal-bin + locale + the # BEAM runtime apt deps. ARG BASE_IMAGE="git.mcintire.me/gmcintire/prop-base:latest" # ---- Elixir build stage ---- FROM ${BUILDER_IMAGE} AS builder # build-essential, git, curl, ca-certificates, hex, and rebar are # already installed in the elixir-base image. # prepare build dir WORKDIR /app # set build ENV ENV MIX_ENV="prod" # install mix dependencies (changes only when mix.exs/mix.lock change) COPY mix.exs mix.lock ./ COPY vendor vendor RUN mix deps.get --only $MIX_ENV # copy compile-time config before compiling deps RUN mkdir config COPY config/config.exs config/${MIX_ENV}.exs config/ RUN mix deps.compile # install esbuild + tailwind binaries (cached until mix.exs changes) RUN mix assets.setup # create priv dir so :code.priv_dir works at compile time # (actual contents copied after compile to avoid cache busting) RUN mkdir -p priv/models priv/static # copy application code and compile COPY lib lib COPY algo.md algo.md # agent-skills markdown is read at compile time by AgentSkillsController # (sha256 digests are baked into the module attribute) COPY priv/agent-skills priv/agent-skills # /docs/api artifacts are read at compile time by ApiDocsController # and ApiDocsLive (baked into module attributes). COPY docs/api docs/api RUN mix compile # copy assets and build (JS/CSS changes don't require recompilation) COPY assets assets RUN mix assets.deploy # copy priv contents (migrations, ML model, static files) # after compile so model retraining doesn't bust the compile cache COPY priv priv # runtime config doesn't require recompilation COPY config/runtime.exs config/ COPY rel rel RUN mix release # ---- Final runtime stage ---- # Pulls the prebuilt prop-base image (Dockerfile.base) which already # carries wgrib2 + g2c libs + cdo + gdal-bin + locale + BEAM runtime # apt deps. We just COPY the Elixir release on top. FROM ${BASE_IMAGE} AS final # Build timestamp baked in by CI (--build-arg BUILD_TIMESTAMP=...). # Only consumed in this final stage, so it never busts the earlier # compile cache. Read at runtime by Microwaveprop.Application.build_timestamp/0. ARG BUILD_TIMESTAMP=unknown ENV MIX_ENV="prod" WORKDIR "/app" RUN chown nobody /app COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/microwaveprop ./ RUN echo "${BUILD_TIMESTAMP}" > /app/BUILD_TIMESTAMP \ && chown nobody /app/BUILD_TIMESTAMP USER nobody CMD ["/app/bin/server"]