-
-
Save erkattak/1cfc6b4585bba09160418942c2d5b3be to your computer and use it in GitHub Desktop.
Elixir Phoenix Umbrella App + Distillery Multistage Docker Build
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
FROM elixir:1.4.5 as asset-builder-mix-getter | |
ENV HOME=/opt/app | |
RUN mix do local.hex --force, local.rebar --force | |
# Cache elixir deps | |
COPY config/ $HOME/config/ | |
COPY mix.exs mix.lock $HOME/ | |
COPY apps/myproject_web/mix.exs $HOME/apps/myproject_web/ | |
COPY apps/myproject_web/config/ $HOME/apps/myproject_web/config/ | |
WORKDIR $HOME/apps/myproject_web | |
RUN mix deps.get | |
######################################################################## | |
FROM node:6 as asset-builder | |
ENV HOME=/opt/app | |
WORKDIR $HOME | |
COPY --from=asset-builder-mix-getter $HOME/deps $HOME/deps | |
WORKDIR $HOME/apps/myproject_web/assets | |
COPY apps/myproject_web/assets/ ./ | |
RUN yarn install | |
RUN ./node_modules/.bin/brunch build --production | |
######################################################################## | |
FROM bitwalker/alpine-elixir:1.4.5 as releaser | |
ENV HOME=/opt/app | |
ARG ERLANG_COOKIE | |
ENV ERLANG_COOKIE $ERLANG_COOKIE | |
# dependencies for comeonin | |
RUN apk add --no-cache build-base cmake | |
# Install Hex + Rebar | |
RUN mix do local.hex --force, local.rebar --force | |
# Cache elixir deps | |
COPY config/ $HOME/config/ | |
COPY mix.exs mix.lock $HOME/ | |
# Copy umbrella app config + mix.exs files | |
COPY apps/myproject/mix.exs $HOME/apps/myproject/ | |
COPY apps/myproject/config/ $HOME/apps/myproject/config/ | |
COPY apps/myproject_web/mix.exs $HOME/apps/myproject_web/ | |
COPY apps/myproject_web/config/ $HOME/apps/myproject_web/config/ | |
ENV MIX_ENV=prod | |
RUN mix do deps.get --only $MIX_ENV, deps.compile | |
COPY . $HOME/ | |
# Digest precompiled assets | |
COPY --from=asset-builder $HOME/apps/myproject_web/priv/static/ $HOME/apps/myproject_web/priv/static/ | |
WORKDIR $HOME/apps/myproject_web | |
RUN mix phx.digest | |
# Release | |
WORKDIR $HOME | |
RUN mix release --env=$MIX_ENV --verbose | |
######################################################################## | |
FROM alpine:3.6 | |
ENV LANG=en_US.UTF-8 \ | |
HOME=/opt/app/ \ | |
TERM=xterm | |
ENV MYPROJECT_VERSION=0.1.0 | |
RUN apk add --no-cache ncurses-libs openssl | |
EXPOSE 4000 | |
ENV PORT=4000 \ | |
MIX_ENV=prod \ | |
REPLACE_OS_VARS=true \ | |
SHELL=/bin/sh | |
COPY --from=releaser $HOME/_build/prod/rel/myproject/releases/$MYPROJECT_VERSION/myproject.tar.gz $HOME | |
WORKDIR $HOME | |
RUN tar -xzf myproject.tar.gz | |
ENTRYPOINT ["/opt/app/bin/myproject"] | |
CMD ["foreground"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment