Skip to content

Instantly share code, notes, and snippets.

@almann
Last active October 2, 2020 18:43
Show Gist options
  • Save almann/f4ccce9747361e71b2b2e7693b83e792 to your computer and use it in GitHub Desktop.
Save almann/f4ccce9747361e71b2b2e7693b83e792 to your computer and use it in GitHub Desktop.
Simple Dockerfile for Rust Cargo Build/Test
# Build:
# docker build -t rust-al2 --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) -f rust-al2.dockerfile $(pwd)
#
# Run:
# docker run --interactive --tty --rm --mount type=bind,source="$(pwd)",target=/workspace rust-al2
FROM amazonlinux:2
ARG USER_ID
ARG GROUP_ID
ARG WORKSPACE_DIR=/workspace
RUN yum -y install clang llvm-devel git gcc gcc-c++ wget curl tar make openssl-devel
RUN wget --quiet https://github.com/Kitware/CMake/releases/download/v3.18.3/cmake-3.18.3.tar.gz
RUN tar xzvf cmake-3.18.3.tar.gz
RUN cd cmake-3.18.3 && ./configure --prefix=/usr/local && make install -j$(nproc)
RUN groupadd -f --gid $GROUP_ID user
RUN useradd -l --uid $USER_ID --gid $GROUP_ID user
RUN mkdir $WORKSPACE_DIR && chown $USER_ID.$GROUP_ID $WORKSPACE_DIR
USER user
WORKDIR $WORKSPACE_DIR
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | /bin/sh -s -- -y
ENV PATH=/home/user/.cargo/bin:$PATH
CMD cargo clean && cargo build --workspace --all-targets && cargo test --workspace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment