# Use an official Elixir runtime as a parent image FROM elixir:1.15.6-slim AS build # Set the environment to production ENV MIX_ENV=prod # Install system dependencies RUN apt-get update && \ apt-get install -y build-essential sqlite3 libsqlite3-dev && \ apt-get clean # Install hex and rebar RUN mix local.hex --force && \ mix local.rebar --force # Create the application build directory WORKDIR /app # Copy our mix files and fetch our dependencies COPY mix.exs mix.lock ./ COPY config config RUN mix do deps.get, deps.compile # Set Node.js environment to production ENV NODE_ENV=production # Use Node.js to install assets FROM node:14 AS node-build WORKDIR /app/assets COPY assets/package.json assets/package-lock.json ./ RUN npm install COPY assets/ ./ RUN npm run deploy # Switch back to our Elixir image to continue building FROM build AS app-build WORKDIR /app COPY --from=node-build /app/assets/build ./priv/static RUN mix phx.digest # Copy our application source code COPY lib lib COPY priv priv # Compile and build the application RUN mix do compile, phx.digest # Create the release RUN mix release # ---- Application Stage ---- FROM debian:buster-slim AS app # Install runtime dependencies RUN apt-get update && apt-get install -y openssl libsqlite3-0 && apt-get clean # Create and switch to the app user RUN useradd --create-home app USER app WORKDIR /home/app # Copy over the build artifact from the previous step and create a symlink COPY --from=build --chown=app:app /app/_build/prod/rel/ezcontainer_railway ./ RUN ln -s /home/app/ezcontainer_railway/bin/my_app /home/app/bin # Specify the entry point ENTRYPOINT ["bin/my_app", "start"]