Skip to content
Permalink
Browse files

Add Dockerfile. Build the image with “docker build -t cluster_demo:la…

…test .”
  • Loading branch information...
olefav committed Jun 27, 2019
1 parent 88551f7 commit 868c48dc16581a9a8580e4a5367a37fc6a484615
Showing with 91 additions and 0 deletions.
  1. +9 −0 .dockerignore
  2. +82 −0 Dockerfile
@@ -0,0 +1,9 @@
_build/
deps/
.git/
.gitignore
Dockerfile
Makefile
README*
test/
priv/static/
@@ -0,0 +1,82 @@
# The version of Alpine to use for the final image
# This should match the version of Alpine that the `elixir:1.8.2-alpine` image uses
ARG ALPINE_VERSION=3.9

FROM elixir:1.8.2-alpine AS builder

# The following are build arguments used to change variable parts of the image.
# The name of your application/release (required)
ARG APP_NAME=cluster_demo
# The version of the application we are building (required)
ARG APP_VSN=0.1.0
# The environment to build with
ARG MIX_ENV=prod
# Set this to true if this release is not a Phoenix app
ARG SKIP_PHOENIX=true
# If you are using an umbrella project, you can change this
# argument to the directory the Phoenix app is in so that the assets
# can be built
ARG PHOENIX_SUBDIR=.

ENV SKIP_PHOENIX=${SKIP_PHOENIX} \
APP_NAME=${APP_NAME} \
APP_VSN=${APP_VSN} \
MIX_ENV=${MIX_ENV}

# By convention, /opt is typically used for applications
WORKDIR /opt/app

# This step installs all the build tools we'll need
RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache \
nodejs \
yarn \
git \
build-base && \
mix local.rebar --force && \
mix local.hex --force

# This copies our app source code into the build container
COPY . .

RUN mix do deps.get, deps.compile, compile

# This step builds assets for the Phoenix app (if there is one)
# If you aren't building a Phoenix app, pass `--build-arg SKIP_PHOENIX=true`
# This is mostly here for demonstration purposes
RUN if [ ! "$SKIP_PHOENIX" = "true" ]; then \
cd ${PHOENIX_SUBDIR}/assets && \
yarn install && \
yarn deploy && \
cd - && \
mix phx.digest; \
fi

RUN \
mkdir -p /opt/built && \
mix distillery.release --verbose && \
cp _build/${MIX_ENV}/rel/${APP_NAME}/releases/${APP_VSN}/${APP_NAME}.tar.gz /opt/built && \
cd /opt/built && \
tar -xzf ${APP_NAME}.tar.gz && \
rm ${APP_NAME}.tar.gz

# From this line onwards, we're in a new image, which will be the image used in production
FROM alpine:${ALPINE_VERSION}

# The name of your application/release (required)
ARG APP_NAME=cluster_demo

RUN apk update && \
apk add --no-cache \
bash \
openssl-dev

ENV REPLACE_OS_VARS=true \
APP_NAME=${APP_NAME}

WORKDIR /opt/app

COPY --from=builder /opt/built .

CMD trap 'exit' INT; /opt/app/bin/${APP_NAME} foreground

0 comments on commit 868c48d

Please sign in to comment.
You can’t perform that action at this time.