prop/Dockerfile.ci
Graham McIntire 07dbcbc428
Some checks failed
Build base image / Build and push base image (push) Successful in 1m58s
Build and Push / Build CI test image (push) Failing after 5m58s
Build and Push / Build and Push Docker Image (push) Has been skipped
fix: patch EXLA Makefile directly for -O0 and -j1 in CI image
elixir_make builds a sanitized env map for make — MAKEFLAGS and DEBUG
never reach make. EXLA also sets make_args to nproc-2 parallel jobs.
We must patch the Makefile (-O3→-O0) and override make_args via
Application.put_env to actually control compilation behavior.
2026-08-05 13:11:05 -05:00

67 lines
2.5 KiB
Text

# syntax=docker/dockerfile:1.6
#
# Pre-built CI test image. Extends the hexpm/elixir image with:
# * build-essential + git + curl + ca-certificates + cdo
# * hex + rebar
# * Precompiled EXLA NIF + object files at /opt/exla-cache/
#
# EXLA's cached_make copies libexla.so to deps/exla/cache/, but Make
# still tries to compile .o files when they're missing (they don't
# survive mix deps.get). We save the full cache/ directory and restore
# it in the test step before mix test runs.
#
# Rebuild whenever mix.exs changes elixir/exla/xla versions or c_src/
# files change (the cache key auto-invalidates).
#
# Built by .forgejo/workflows/build.yaml (build-ci-image job).
ARG ELIXIR_IMAGE="docker.io/hexpm/elixir:1.20.1-erlang-29.0.2-debian-trixie-20260518-slim"
FROM ${ELIXIR_IMAGE} AS builder
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update -qq && \
apt-get install -y -qq git curl ca-certificates build-essential cdo && \
rm -rf /var/lib/apt/lists/*
RUN mix local.hex --force && mix local.rebar --force
WORKDIR /tmp/exla_warm
COPY mix.exs mix.lock /tmp/exla_warm/
COPY vendor /tmp/exla_warm/vendor
RUN mkdir -p /tmp/exla_warm/config && \
printf 'import Config\nconfig :nx, :default_backend, EXLA.Backend\n' > /tmp/exla_warm/config/config.exs
# Compile all deps. EXLA's Makefile defaults to -O3 which OOM-kills g++
# on low-memory CI runners. Patch it to -O0 before compilation.
# Also override make_args to -j1 (EXLA defaults to nproc-2 parallel jobs)
# since elixir_make's sanitized env blocks MAKEFLAGS/DEBUG from reaching make.
RUN mix deps.get && \
sed -i 's/-O3/-O0/g' deps/exla/Makefile && \
mix run -e 'Application.put_env(:exla, :make_args, ["-j1"])' && \
mix deps.compile
# Save the full build cache (libexla.so + .o files + xla_extension lib)
# so Make finds all targets already built when restored in the test step.
RUN mkdir -p /opt/exla-cache && \
cp -a deps/exla/cache /opt/exla-cache/cache
FROM ${ELIXIR_IMAGE} AS final
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update -qq && \
apt-get install -y -qq git curl ca-certificates build-essential cdo && \
rm -rf /var/lib/apt/lists/*
RUN mix local.hex --force && mix local.rebar --force
# XLA archive download + cached libexla.so (cached_make fast path).
COPY --from=builder /root/.cache/xla /root/.cache/xla
# Pre-built EXLA object files + libexla.so + xla_extension/ lib.
# Restored in the test step: cp -a /opt/exla-cache/cache /app/deps/exla/cache
COPY --from=builder /opt/exla-cache /opt/exla-cache
WORKDIR /app