Skip to content

Adds rust to docker image #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,34 @@ COPY README.md README.md
RUN mix do compile, release

# Stage 2
# We build rust binaries.
# Rust is required for `explorer` and `polars`, possibly other NIFs.
FROM rust:1.54-alpine3.13 AS rust

# Stage 3
# Prepares the runtime environment and copies over the relase.
# We use the same base image, because we need Erlang, Elixir and Mix
# during runtime to spawn the Livebook standalone runtimes.
# Consequently the release doesn't include ERTS as we have it anyway.
FROM hexpm/elixir:1.12.0-erlang-24.0-alpine-3.13.3

ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
# Without this line we get "does not support these crate types" error
RUSTFLAGS='-C target-feature=-crt-static'

RUN apk add --no-cache \
# Runtime dependencies
openssl ncurses-libs \
# In case someone uses `Mix.install/2` and point to a git repo
git
git \
# It is required to compile some Rust crates:
gcc musl-dev

# Copy Rust compiler, `cargo`, etc:
COPY --from=rust /usr/local/rustup /usr/local/rustup
COPY --from=rust /usr/local/cargo /usr/local/cargo

# Run in the /data directory by default, makes for
# a good place for the user to mount local volume
Expand All @@ -47,7 +64,8 @@ WORKDIR /data
ENV HOME=/home/livebook
# Make sure someone running the container with `--user`
# has permissions to the home dir (for `Mix.install/2` cache)
RUN mkdir $HOME && chmod 777 $HOME
RUN mkdir $HOME && chmod 777 $HOME && \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME

# Install hex and rebar for `Mix.install/2` and Mix runtime
RUN mix local.hex --force && \
Expand Down