Last active
August 8, 2022 18:45
-
-
Save kyleVsteger/ae7f478c92b155d3f6d24bf44ed93a18 to your computer and use it in GitHub Desktop.
Multistage Elixir 1.11 Phoenix Live View Release Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG ALPINE_VERSION=3.12.0 | |
FROM hexpm/elixir:1.11.0-erlang-23.1.1-alpine-3.12.0 as builder | |
ARG APP_VSN="1.0.0" | |
# Replace `your_app` with your otp application name. | |
ENV APP_NAME=your_app \ | |
APP_VSN=${APP_VSN} \ | |
MIX_ENV=prod | |
WORKDIR /opt/app | |
# Add required packages for building the application. | |
# If you're not running Phoenix LiveView | |
# remove the `nodejs` and `npm` lines. | |
RUN apk update && \ | |
apk upgrade --no-cache && \ | |
apk add --no-cache git \ | |
nodejs=12.18.4-r0 \ | |
npm --update \ | |
build-base && \ | |
mix local.rebar --force && \ | |
mix local.hex --force | |
COPY mix.exs mix.lock ./ | |
RUN mix do deps.get, deps.compile | |
# If you're not running Phoenix LiveView | |
# remove these next two instructions. | |
COPY ./assets ./assets | |
RUN cd assets && npm install | |
COPY . . | |
# Remove `phx.digest` if you're not using LiveView | |
RUN mix do compile, phx.digest, release | |
# Final build stage. | |
FROM alpine:${ALPINE_VERSION} | |
RUN apk update && \ | |
apk add --no-cache bash | |
WORKDIR /opt/app | |
RUN addgroup -S app | |
RUN adduser -S app -G app | |
COPY --from=builder /opt/app/_build/prod/rel . | |
RUN chown -R app:app /opt/app | |
USER app | |
# Run the pending migrations for your application then start it. | |
# Replace `your_app` and `YourApp` with the otp app name and module respectively. | |
CMD trap 'exit' INT; \ | |
./your_app/bin/your_app eval "YourApp.Release.migrate" && \ | |
./your_app/bin/your_app start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment