Skip to content

Commit

Permalink
Merge pull request #1 from jchristgit/slim-image
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 authored Jun 16, 2024
2 parents ad78e54 + 8fad272 commit c0f4d73
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

ARG ELIXIR_VERSION=1.17.0
ARG OTP_VERSION=27.0
ARG DEBIAN_VERSION=bookworm-20240612
ARG ALPINE_VERSION=3.19.1

ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
ARG BUILDER_IMAGE="docker.io/hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-alpine-${ALPINE_VERSION}"
ARG RUNNER_IMAGE="docker.io/library/alpine:${ALPINE_VERSION}"

FROM ${BUILDER_IMAGE} as builder

# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
RUN apk add --no-cache git

# prepare build dir
WORKDIR /app
Expand All @@ -21,13 +20,13 @@ RUN mix local.hex --force && \
mix local.rebar --force

# set build ENV
ENV MIX_ENV="prod"
ENV ERL_FLAGS="+JPperf true"
ENV MIX_ENV="prod" \
ERL_FLAGS="+JPperf true"

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config
RUN mix deps.get --only $MIX_ENV && \
mkdir config

# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
Expand All @@ -49,23 +48,16 @@ RUN mix release
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}

RUN apt-get update -y && \
apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates git \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
RUN apk add --no-cache ca-certificates git libstdc++ openssl ncurses

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8 \
MIX_ENV=prod

WORKDIR "/app"
RUN chown nobody /app

# set runner ENV
ENV MIX_ENV="prod"

# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/ ./

Expand Down

0 comments on commit c0f4d73

Please sign in to comment.