diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7f1070b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,67 @@ +# Use an official Elixir runtime as a parent image +FROM elixir:1.12-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/my_app ./ +RUN ln -s /home/app/my_app/bin/my_app /home/app/bin + +# Specify the entry point +ENTRYPOINT ["bin/my_app", "start"]