Skip to content

Instantly share code, notes, and snippets.

@felix-d
Last active April 8, 2019 15:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felix-d/6acfe282998543f6a8e77de4acab734d to your computer and use it in GitHub Desktop.
Save felix-d/6acfe282998543f6a8e77de4acab734d to your computer and use it in GitHub Desktop.
Elixir Phoenix Distillery Multi-Stage Dockerfile
# Assets compilation
FROM aparedes/alpine-node-yarn as node
## Node modules
COPY ./deps /tmp/deps
COPY ./assets/package.json /tmp/deps
COPY ./assets/package-lock.json /tmp/deps
WORKDIR /tmp/deps
RUN yarn
## Assets compilation
COPY ./assets /tmp/assets
RUN cp -R /tmp/deps/node_modules /tmp/assets
WORKDIR /tmp/assets
RUN ./node_modules/.bin/brunch build --production
# Distillery release
FROM bitwalker/alpine-elixir as distillery
ARG APP_NAME=web
ENV MIX_ENV prod
COPY . /app
COPY --from=node /tmp/priv/static /app/priv/static
WORKDIR /app
RUN mix phx.digest && mix release --env=prod
RUN mkdir target
RUN tar xzf ./_build/prod/rel/$APP_NAME/releases/*/$APP_NAME.tar.gz -C ./target
# Final image
FROM alpine:latest
RUN apk add --update openssl bash && \
rm -rf /var/cache/apk/*
COPY --from=distillery /app/target /app
ENV PORT 4000
WORKDIR /app
CMD ["./bin/web", "foreground", "--sname", "web", "--cookie", "secret"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment