2016-09-12 10:45:04 +00:00
|
|
|
# Use Debian 16.04 as the base for our Rust musl toolchain, because of
|
|
|
|
# https://github.com/rust-lang/rust/issues/34978 (as of Rust 1.11).
|
|
|
|
FROM ubuntu:16.04
|
2016-04-16 14:00:12 +00:00
|
|
|
|
2016-11-25 12:45:10 +00:00
|
|
|
# The Rust toolchain to use when building our image. Set by `hooks/build`.
|
|
|
|
ARG TOOLCHAIN=stable
|
|
|
|
|
2016-04-17 11:41:55 +00:00
|
|
|
# Make sure we have basic dev tools for building C libraries. Our goal
|
|
|
|
# here is to support the musl-libc builds and Cargo builds needed for a
|
|
|
|
# large selection of the most popular crates.
|
2016-04-16 14:00:12 +00:00
|
|
|
#
|
|
|
|
# We also set up a `rust` user by default, in whose account we'll install
|
|
|
|
# the Rust toolchain. This user has sudo privileges if you need to install
|
|
|
|
# any more software.
|
|
|
|
RUN apt-get update && \
|
2016-04-17 11:41:55 +00:00
|
|
|
apt-get install -y \
|
|
|
|
build-essential \
|
|
|
|
cmake \
|
|
|
|
curl \
|
|
|
|
file \
|
|
|
|
git \
|
2016-11-19 13:50:23 +00:00
|
|
|
musl-tools \
|
2016-04-17 11:41:55 +00:00
|
|
|
sudo \
|
|
|
|
xutils-dev \
|
|
|
|
&& \
|
2016-04-16 14:00:12 +00:00
|
|
|
apt-get clean && rm -rf /var/lib/apt/lists/* && \
|
2016-04-17 11:41:55 +00:00
|
|
|
useradd rust --user-group --create-home --shell /bin/bash --groups sudo
|
|
|
|
|
|
|
|
# Allow sudo without a password.
|
|
|
|
ADD sudoers /etc/sudoers.d/nopasswd
|
|
|
|
|
|
|
|
# Run all further code as user `rust`, and create our working directories
|
|
|
|
# as the appropriate user.
|
|
|
|
USER rust
|
|
|
|
RUN mkdir -p /home/rust/libs /home/rust/src
|
2016-04-16 14:00:12 +00:00
|
|
|
|
2016-04-17 11:41:55 +00:00
|
|
|
# Set up our path with all our binary directories, including those for the
|
|
|
|
# musl-gcc toolchain and for our Rust toolchain.
|
2016-04-16 14:00:12 +00:00
|
|
|
ENV PATH=/home/rust/.cargo/bin:/usr/local/musl/bin:/usr/local/bin:/usr/bin:/bin
|
|
|
|
|
2016-04-17 11:41:55 +00:00
|
|
|
# Install our Rust toolchain and the `musl` target. We patch the
|
|
|
|
# command-line we pass to the installer so that it won't attempt to
|
|
|
|
# interact with the user or fool around with TTYs. We also set the default
|
|
|
|
# `--target` to musl so that our users don't need to keep overriding it
|
|
|
|
# manually.
|
2016-11-25 12:52:24 +00:00
|
|
|
RUN curl https://sh.rustup.rs -sSf | \
|
2016-11-25 12:56:34 +00:00
|
|
|
sh -s -- -y --default-toolchain $TOOLCHAIN && \
|
2016-11-25 12:54:46 +00:00
|
|
|
rustup target add x86_64-unknown-linux-musl
|
2016-04-17 11:41:55 +00:00
|
|
|
ADD cargo-config.toml /home/rust/.cargo/config
|
|
|
|
|
|
|
|
# We'll build our libraries in subdirectories of /home/rust/libs. Please
|
|
|
|
# clean up when you're done.
|
|
|
|
WORKDIR /home/rust/libs
|
|
|
|
|
2016-04-16 14:00:12 +00:00
|
|
|
# Build a static library version of OpenSSL using musl-libc. This is
|
|
|
|
# needed by the popular Rust `hyper` crate.
|
2017-08-08 15:40:33 +00:00
|
|
|
RUN VERS=1.0.2l && \
|
2016-04-16 14:00:12 +00:00
|
|
|
curl -O https://www.openssl.org/source/openssl-$VERS.tar.gz && \
|
|
|
|
tar xvzf openssl-$VERS.tar.gz && cd openssl-$VERS && \
|
|
|
|
env CC=musl-gcc ./config --prefix=/usr/local/musl && \
|
2016-04-17 11:41:55 +00:00
|
|
|
env C_INCLUDE_PATH=/usr/local/musl/include/ make depend && \
|
|
|
|
make && sudo make install && \
|
|
|
|
cd .. && rm -rf openssl-$VERS.tar.gz openssl-$VERS
|
2016-11-19 13:50:55 +00:00
|
|
|
ENV OPENSSL_DIR=/usr/local/musl/ \
|
|
|
|
OPENSSL_INCLUDE_DIR=/usr/local/musl/include/ \
|
2016-05-18 22:05:15 +00:00
|
|
|
DEP_OPENSSL_INCLUDE=/usr/local/musl/include/ \
|
2016-04-16 14:00:12 +00:00
|
|
|
OPENSSL_LIB_DIR=/usr/local/musl/lib/ \
|
|
|
|
OPENSSL_STATIC=1
|
|
|
|
|
|
|
|
# (Please feel free to submit pull requests for musl-libc builds of other C
|
|
|
|
# libraries needed by the most popular and common Rust crates, to avoid
|
|
|
|
# everybody needing to build them manually.)
|
|
|
|
|
2016-04-17 11:41:55 +00:00
|
|
|
# Expect our source code to live in /home/rust/src. We'll run the build as
|
2016-04-16 14:00:12 +00:00
|
|
|
# user `rust`, which will be uid 1000, gid 1000 outside the container.
|
|
|
|
WORKDIR /home/rust/src
|