ezcontainer_example/Dockerfile

66 lines
1.6 KiB
Text
Raw Normal View History

2023-10-27 01:58:26 -04:00
# Use an official Elixir runtime as a parent image
2023-10-27 01:59:02 -04:00
FROM elixir:1.15.6-slim AS build
2023-10-27 01:58:26 -04:00
# 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
2023-10-27 03:30:29 -04:00
FROM node:20 AS node-build
2023-10-27 01:58:26 -04:00
WORKDIR /app/assets
2023-10-27 03:30:29 -04:00
COPY assets/package.json assets/pnpm-lock.yaml ./
RUN npm install -g pnpm
RUN pnpm install
2023-10-27 01:58:26 -04:00
COPY assets/ ./
# Switch back to our Elixir image to continue building
FROM build AS app-build
WORKDIR /app
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 ----
2023-10-27 03:49:10 -04:00
FROM elixir:1.15.6-slim AS app
2023-10-27 01:58:26 -04:00
# Install runtime dependencies
2023-10-27 03:49:10 -04:00
RUN apt-get update && apt-get install -y openssl libssl-dev libsqlite3-0 && apt-get clean
2023-10-27 01:58:26 -04:00
# 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
2023-10-27 03:30:29 -04:00
COPY --from=app-build --chown=app:app /app/_build/prod/rel/ezcontainer_railway ./
2023-10-27 01:58:26 -04:00
# Specify the entry point
2023-10-27 03:50:06 -04:00
ENTRYPOINT ["/home/app/bin/ezcontainer_railway", "start"]