Last active
October 3, 2021 12:35
-
-
Save pedromfedricci/d08544212bd9ae00bccf7fb60559077b to your computer and use it in GitHub Desktop.
Dockerfile for working with Rust and WebAssembly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG RUST_IMAGE=rust:1.52.1 | |
FROM $RUST_IMAGE AS install-sys-pkgs | |
RUN apt-get update \ | |
&& \ | |
apt-get install -y --no-install-recommends \ | |
# Z shell is a customizable Unix shell. | |
zsh \ | |
# Install node & npm. | |
nodejs npm \ | |
# Firefox dependencies to run headless. | |
xvfb libgtk-3-dev libdbus-glib-1-2 \ | |
&& \ | |
# Update npm. | |
npm install npm@latest -g \ | |
&& \ | |
# wasm-pack is a tool for building and working with rust generated wasm. | |
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh | |
FROM install-sys-pkgs AS get-firefox | |
ARG FIREFOX_VERSION="88.0" | |
ARG FIREFOX_LANG="en-US" | |
ENV PROT="https://" \ | |
FQDN="download-installer.cdn.mozilla.net" \ | |
TAR_PATH="/pub/firefox/releases/$FIREFOX_VERSION/linux-x86_64/$FIREFOX_LANG/" \ | |
TAR_BALL="firefox-$FIREFOX_VERSION.tar.bz2" | |
ENV TAR_URL="$PROT$FQDN$TAR_PATH$TAR_BALL" | |
# Decompresses firefox to /opt/, next stage will recover | |
# /opt/firefox/ and discard this intermediary image. | |
ADD $TAR_URL /tmp/ | |
RUN tar xjf /tmp/firefox-$FIREFOX_VERSION.tar.bz2 -C /opt/ | |
FROM install-sys-pkgs AS config-firefox | |
# Only copies /opt/firefox/ from previous stage, discarding the rest. | |
COPY --from=get-firefox /opt/firefox/ /opt/firefox/ | |
RUN ln -s /opt/firefox/firefox /usr/bin/firefox | |
FROM config-firefox AS create-dev-user | |
ARG USER=rustdev | |
RUN useradd ${USER} --shell /bin/bash --create-home | |
USER ${USER} | |
FROM create-dev-user AS install-rust-tools | |
RUN rustup component add \ | |
rustfmt \ | |
rust-src \ | |
rust-docs \ | |
clippy \ | |
&& \ | |
cargo install \ | |
cargo-watch \ | |
cargo-generate \ | |
cargo-expand |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment