Skip to content

Instantly share code, notes, and snippets.

@amattn
Created January 6, 2021 17:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amattn/037e3ef59c02140efe60b8aa1c00b687 to your computer and use it in GitHub Desktop.
Save amattn/037e3ef59c02140efe60b8aa1c00b687 to your computer and use it in GitHub Desktop.
Dockerfile example used to build an elixir/phoenix project on linux and output a tarball
FROM elixir:1.11.2 AS build
## instll some dependencies (webpack basically)
RUN \
apt-get update -y && \
curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
apt-get install -y nodejs && node -v && npm -v
# Required environment variables passed in via --build-arg flags
ARG DATABASE_URL
ARG SECRET_KEY_BASE
# prepare build dir
WORKDIR /app
# install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force
# set build ENV
ENV MIX_ENV=prod
# install mix dependencies
COPY mix.exs mix.lock ./
COPY config config
RUN mix deps.get --only prod
RUN mix deps.compile
# copy lib first, otherwise tailwind's purgeCSS or other tree-shaking tools will purge everything.
COPY lib lib
# clean install of package-lock
COPY assets/package.json assets/package-lock.json ./assets/
RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
# build assets
COPY priv priv
COPY assets assets
RUN npm run --prefix ./assets deploy
RUN mix phx.digest
# compile and build release
# uncomment COPY if rel/ exists
# COPY rel rel
RUN mix do compile, release
FROM scratch AS app
WORKDIR /app
COPY --from=build /app/_build/prod/my_app-*.tar.gz ./
CMD ["/bin/bash"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment