Skip to content

Instantly share code, notes, and snippets.

@joseph-lozano
Created August 14, 2020 14:49
Show Gist options
  • Save joseph-lozano/d8cdca9cea46ffca71717b43f7cd6e18 to your computer and use it in GitHub Desktop.
Save joseph-lozano/d8cdca9cea46ffca71717b43f7cd6e18 to your computer and use it in GitHub Desktop.
Docker file for Elixir + Rust
# Setup build image
FROM elixir:1.10.4-alpine AS builder
# Install build dependencies
RUN apk update && \
apk add --no-cache \
bash \
build-base \
curl \
git \
libgcc \
python3
# Install rustup
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV RUSTUP_HOME=/root/.rustup \
RUSTFLAGS="-C target-feature=-crt-static" \
CARGO_HOME=/root/.cargo \
PATH="/root/.cargo/bin:$PATH"
# Install Node.js
RUN apk add --update npm
# Prepare app dir
WORKDIR /build
ENV HOME=/build
ARG SECRET_KEY_BASE
# Set app ENV
ENV MIX_ENV=prod
ENV SECRET_KEY_BASE=${SECRET_KEY_BASE}
# Install Hex and Rebar
RUN mix local.hex --force && \
mix local.rebar --force
# Install mix dependencies
COPY mix.exs mix.lock ./
COPY config config
RUN mix do deps.get, deps.compile
# Build assets
COPY assets/package.json assets/package-lock.json ./assets/
RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
COPY priv priv
COPY assets assets
RUN npm run --prefix ./assets deploy
RUN mix phx.digest
# Compile app
COPY lib lib
RUN mix compile
# Release
RUN mix release
# Setup app image
FROM alpine AS app
RUN apk update && \
apk add --no-cache \
bash \
imagemagick \
libgcc \
openssl-dev
RUN mkdir /app
WORKDIR /app
COPY --from=builder /build/_build/prod/rel/one_million_words ./
ARG PORT
EXPOSE ${PORT}
CMD ["bin/one_million_words", "start"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment