2019-01-08 05:25:21 +03:00
|
|
|
#
|
|
|
|
# Step 1 - Build the OTP binary
|
|
|
|
#
|
2019-02-06 16:31:06 +03:00
|
|
|
FROM elixir:1.8.1-alpine AS builder
|
2019-01-08 05:25:21 +03:00
|
|
|
|
|
|
|
ARG APP_NAME
|
|
|
|
ARG APP_VERSION
|
|
|
|
ARG MIX_ENV=prod
|
|
|
|
|
|
|
|
ENV APP_NAME=${APP_NAME} \
|
|
|
|
APP_VERSION=${APP_VERSION} \
|
|
|
|
MIX_ENV=${MIX_ENV}
|
|
|
|
|
|
|
|
WORKDIR /build
|
|
|
|
|
2019-07-22 20:01:36 +03:00
|
|
|
RUN apk --no-cache update && \
|
|
|
|
apk --no-cache upgrade && \
|
|
|
|
apk --no-cache add make g++ git openssl-dev python yaml-dev
|
2019-01-08 05:25:21 +03:00
|
|
|
|
|
|
|
RUN mix local.rebar --force && \
|
|
|
|
mix local.hex --force
|
|
|
|
|
|
|
|
COPY mix.* ./
|
|
|
|
RUN mix deps.get --only ${MIX_ENV}
|
|
|
|
RUN mix deps.compile
|
|
|
|
|
|
|
|
COPY . .
|
|
|
|
RUN mix compile
|
|
|
|
RUN mix phx.digest
|
|
|
|
|
|
|
|
RUN mkdir -p /opt/build && \
|
|
|
|
mix release --verbose && \
|
|
|
|
cp _build/${MIX_ENV}/rel/${APP_NAME}/releases/${APP_VERSION}/${APP_NAME}.tar.gz /opt/build
|
|
|
|
|
|
|
|
RUN cd /opt/build && \
|
|
|
|
tar -xzf ${APP_NAME}.tar.gz && \
|
|
|
|
rm ${APP_NAME}.tar.gz
|
|
|
|
|
2019-07-22 20:01:36 +03:00
|
|
|
#
|
|
|
|
# Step 2 - Build webapp and jipt deps
|
|
|
|
#
|
|
|
|
FROM alpine:3.9 AS webapp-builder
|
|
|
|
RUN apk --no-cache update && \
|
|
|
|
apk --no-cache upgrade && \
|
|
|
|
apk --no-cache add make git nodejs-npm
|
|
|
|
WORKDIR /opt/build
|
|
|
|
COPY webapp .
|
|
|
|
RUN npm ci --no-audit --no-color && \
|
|
|
|
npm run build-production
|
2019-01-08 05:25:21 +03:00
|
|
|
|
2019-07-22 20:01:36 +03:00
|
|
|
FROM alpine:3.9 AS jipt-builder
|
|
|
|
RUN apk --no-cache update && \
|
|
|
|
apk --no-cache upgrade && \
|
|
|
|
apk --no-cache add make git nodejs-npm
|
|
|
|
WORKDIR /opt/build
|
|
|
|
COPY jipt .
|
|
|
|
RUN npm ci --no-audit --no-color && \
|
|
|
|
npm run build-production
|
2019-01-08 05:25:21 +03:00
|
|
|
#
|
2019-07-22 20:01:36 +03:00
|
|
|
# Step 3 - Build a lean runtime container
|
2019-01-08 05:25:21 +03:00
|
|
|
#
|
2019-03-11 19:51:16 +03:00
|
|
|
FROM alpine:3.9
|
2019-01-08 05:25:21 +03:00
|
|
|
|
|
|
|
ARG APP_NAME
|
|
|
|
ARG APP_VERSION
|
|
|
|
ENV APP_NAME=${APP_NAME} \
|
|
|
|
APP_VERSION=${APP_VERSION}
|
|
|
|
|
|
|
|
RUN apk --no-cache update && \
|
|
|
|
apk --no-cache upgrade && \
|
2019-07-19 00:13:24 +03:00
|
|
|
apk --no-cache add bash openssl erlang-crypto yaml-dev
|
2019-01-08 05:25:21 +03:00
|
|
|
|
2019-07-19 00:13:24 +03:00
|
|
|
WORKDIR /opt/$APP_NAME
|
2019-01-08 05:25:21 +03:00
|
|
|
|
2019-07-22 20:01:36 +03:00
|
|
|
# Copy the OTP binary and assets deps from the build step
|
2019-01-08 05:25:21 +03:00
|
|
|
COPY --from=builder /opt/build .
|
2019-07-22 20:01:36 +03:00
|
|
|
COPY --from=webapp-builder /opt/build .
|
|
|
|
COPY --from=jipt-builder /opt/build .
|
2019-01-08 05:25:21 +03:00
|
|
|
|
2019-07-22 20:01:36 +03:00
|
|
|
RUN mv /opt/$APP_NAME/webapp-dist /opt/$APP_NAME/lib/$APP_NAME-$APP_VERSION/priv/static/webapp && \
|
|
|
|
mv /opt/$APP_NAME/jipt-dist /opt/$APP_NAME/lib/$APP_NAME-$APP_VERSION/priv/static/jipt
|
2019-07-19 00:13:24 +03:00
|
|
|
|
2019-01-08 05:25:21 +03:00
|
|
|
# Copy the entrypoint script
|
|
|
|
COPY priv/scripts/docker-entrypoint.sh /usr/local/bin
|
|
|
|
RUN chmod a+x /usr/local/bin/docker-entrypoint.sh
|
|
|
|
|
|
|
|
# Create a non-root user
|
2019-07-22 20:01:36 +03:00
|
|
|
RUN adduser -D $APP_NAME && chown -R $APP_NAME: /opt/$APP_NAME
|
2019-01-08 05:25:21 +03:00
|
|
|
|
2019-07-19 00:13:24 +03:00
|
|
|
USER $APP_NAME
|
2019-01-08 05:25:21 +03:00
|
|
|
|
|
|
|
ENTRYPOINT ["docker-entrypoint.sh"]
|
|
|
|
CMD ["foreground"]
|