Skip to content

Instantly share code, notes, and snippets.

@mazz
Created January 6, 2022 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mazz/8359ba412c47fcc17a5e26695ad9aabc to your computer and use it in GitHub Desktop.
Save mazz/8359ba412c47fcc17a5e26695ad9aabc to your computer and use it in GitHub Desktop.
Dockerfile
# STEP 1 - BUILD RELEASE
# cannot use alpine 3.14.0 because of issue here with bcrypt-elxir compiling using make on docker:
# https://github.com/riverrun/bcrypt_elixir/issues/26#issuecomment-881966412
FROM hexpm/elixir:1.12.3-erlang-24.0.6-alpine-3.13.5 AS build
# install build dependencies
RUN apk add --update git \
build-base \
ffmpeg \
--update npm
RUN apk add ffprobe --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
RUN npm install npm@latest -g
RUN mkdir /app
WORKDIR /app
# extend hex timeout
ENV HEX_HTTP_TIMEOUT=20
# install Hex + Rebar
RUN mix do local.hex --force, local.rebar --force
# set build ENV
ENV MIX_ENV=prod
ENV HOSTNAME=faithfulaudio.org
ENV DATABASE_URL=ecto://postgres:postgres@postgres/faithful_word
ENV SECRET_KEY_BASE=secret
# install mix dependencies
COPY mix.exs mix.lock ./
COPY config config
RUN mix deps.get --only $MIX_ENV
RUN mix deps.compile
# install npm dependencies
COPY assets/package.json assets/package-lock.json ./assets/
RUN npm --prefix ./assets install --progress=false --no-audit --loglevel=error
COPY priv priv
# build assets
COPY assets assets
# NOTE: If using TailwindCSS, it uses a special "purge" step and that requires
# the code in `lib` to see what is being used. Uncomment that here before
# running the npm deploy script if that's the case.
COPY lib lib
# RUN cd ./assets \
# && npm install \
# && cd ..
RUN mix assets.deploy
COPY lib lib
COPY rel rel
# build project
# COPY priv priv
# COPY lib lib
RUN mix compile
# build release
# at this point we should copy the rel directory but
# we are not using it so we can omit it
# COPY rel rel
RUN mix release
####################################################################################################
# STEP 2 - FINAL
FROM alpine:3.13.5 as app
# install runtime dependencies
# https://stackoverflow.com/questions/68010688/docker-run-error-loading-shared-library-libstdc-so-6-and-libgcc-s-so-1
RUN apk upgrade --no-cache && \
apk add --update bash \
openssl \
postgresql-client \
libstdc++
EXPOSE 4000
ENV MIX_ENV=prod
ENV DATABASE_URL=ecto://postgres:postgres@postgres/faithful_word
ENV SECRET_KEY_BASE=secret
# prepare app directory
RUN mkdir /app
WORKDIR /app
# copy build deps that cannot be installed via alpine
COPY ffprobe .
# copy release to app container
COPY --from=build /app/_build/prod/rel/faithful_word .
COPY entrypoint.sh .
RUN chown -R nobody: /app
USER nobody
ENV HOME=/app
CMD ["bash", "/app/entrypoint.sh"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment