accent/Dockerfile

89 lines
2.2 KiB
Docker
Raw Normal View History

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
# This step installs all the build tools we'll need
RUN apk update && \
apk upgrade --no-cache && \
2019-03-13 05:25:06 +03:00
apk add --no-cache make g++ git openssl-dev nodejs-npm python yaml-dev
2019-01-08 05:25:21 +03:00
RUN mix local.rebar --force && \
mix local.hex --force
# This copies our app source code into the build container
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
COPY webapp /opt/build/webapp
2019-07-19 00:13:24 +03:00
RUN cd /opt/build && npm ci --prefix webapp --no-audit --no-color
RUN cd /opt/build && npm run build-production --prefix webapp
COPY jipt /opt/build/jipt
2019-01-08 05:25:21 +03:00
2019-07-19 00:13:24 +03:00
RUN cd /opt/build && npm ci --prefix jipt --no-audit --no-color
RUN cd /opt/build && npm run build-production --prefix jipt
2019-01-08 05:25:21 +03:00
2019-07-19 00:13:24 +03:00
RUN mv /opt/build/webapp/webapp-dist /opt/build
RUN rm -rf /opt/build/webapp
RUN mv /opt/build/jipt/jipt-dist /opt/build
RUN rm -rf /opt/build/jipt
2019-01-08 05:25:21 +03:00
#
# Step 2 - Build a lean runtime container
#
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}
# Update kernel and install runtime dependencies
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
# Copy the OTP binary from the build step
COPY --from=builder /opt/build .
2019-07-19 00:13:24 +03:00
RUN cp -r /opt/$APP_NAME/webapp-dist /opt/$APP_NAME/lib/$APP_NAME-$APP_VERSION/priv/static/webapp
RUN cp -r /opt/$APP_NAME/jipt-dist /opt/$APP_NAME/lib/$APP_NAME-$APP_VERSION/priv/static/jipt
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-19 00:13:24 +03:00
RUN adduser -D $APP_NAME && chown -R accent: /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"]