Skip to content

Commit

Permalink
chore: Create a regular use inside containers
Browse files Browse the repository at this point in the history
Install the Rustup toolchain as that regular user.

Avoiding usage of `root` makes it easier to avoid bind volume ownership
problems. Having a regular user in combination with using
`--userns keep-id` ensures that the build artifacts prodiced inside the
container are owned by a regular user on the host.
  • Loading branch information
vadorovsky committed Oct 27, 2024
1 parent f504476 commit bea3ddf
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 26 deletions.
13 changes: 9 additions & 4 deletions containers/Dockerfile.cross-aarch64-unknown-linux-gnu
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM docker.io/debian:bookworm

ENV PATH="/root/.cargo/bin:/usr/lib/llvm-18/bin:${PATH}"
ENV PATH="/home/cross/.cargo/bin:/usr/lib/llvm-18/bin:${PATH}"

# Even though we are using clang as a C compiler, we need the libgcc_s and
# libstdc++.
Expand Down Expand Up @@ -28,12 +28,17 @@ RUN dpkg --add-architecture arm64 \
&& chmod +x llvm.sh \
&& ./llvm.sh 18 \
&& rm -f llvm.sh \
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& rm -rf /var/lib/apt/lists/* \
&& useradd -m -G users -s /bin/bash cross

USER cross
WORKDIR /home/cross

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& rustup toolchain install stable --component rust-src \
&& rustup toolchain install beta --component rust-src \
&& rustup toolchain install nightly --component rust-src \
&& rustup target add aarch64-unknown-linux-gnu \
&& rustup +beta target add aarch64-unknown-linux-gnu \
&& rustup +nightly target add aarch64-unknown-linux-gnu \
&& cargo install btfdump \
&& rm -rf /var/lib/apt/lists/*
&& cargo install btfdump
19 changes: 12 additions & 7 deletions containers/Dockerfile.cross-aarch64-unknown-linux-musl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM docker.io/gentoo/stage3:musl-llvm

ENV PATH="/root/.cargo/bin:/usr/lib/llvm/18/bin:${PATH}"
ENV PATH="/home/cross/.cargo/bin:/usr/lib/llvm/18/bin:${PATH}"
# Install only aarch64 user-space wrapper when installing app-emulation/qemu.
ENV QEMU_USER_TARGETS="aarch64"
# Enable static libraries for installed packages (zstd, zlib etc.).
Expand Down Expand Up @@ -64,15 +64,20 @@ RUN emerge --sync --quiet \
app-arch/zstd \
sys-libs/llvm-libgcc \
sys-libs/zlib \
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& rm -rf \
/var/cache/binpkgs/* \
/var/cache/distfiles/* \
/var/tmp/portage/* \
&& useradd -m -G users -s /bin/bash cross

USER cross
WORKDIR /home/cross

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& rustup toolchain install stable --component rust-src \
&& rustup toolchain install beta --component rust-src \
&& rustup toolchain install nightly --component rust-src \
&& rustup target add aarch64-unknown-linux-musl \
&& rustup +beta target add aarch64-unknown-linux-musl \
&& rustup +nightly target add aarch64-unknown-linux-musl \
&& cargo install btfdump \
&& rm -rf \
/var/cache/binpkgs/* \
/var/cache/distfiles/* \
/var/tmp/portage/*
&& cargo install btfdump
13 changes: 9 additions & 4 deletions containers/Dockerfile.cross-riscv64gc-unknown-linux-gnu
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# [1] https://packages.debian.org/search?keywords=software-properties-common
FROM docker.io/debian:sid

ENV PATH="/root/.cargo/bin:/usr/lib/llvm-18/bin:${PATH}"
ENV PATH="/home/cross/.cargo/bin:/usr/lib/llvm-18/bin:${PATH}"

# Even though we are using clang as a C compiler, we need the libgcc_s and
# libstdc++.
Expand Down Expand Up @@ -37,12 +37,17 @@ RUN dpkg --add-architecture riscv64 \
&& chmod +x llvm.sh \
&& ./llvm.sh 18 \
&& rm -f llvm.sh \
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& rm -rf /var/lib/apt/lists/* \
&& useradd -m -G users -s /bin/bash cross

USER cross
WORKDIR /home/cross

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& rustup toolchain install stable --component rust-src \
&& rustup toolchain install beta --component rust-src \
&& rustup toolchain install nightly --component rust-src \
&& rustup target add riscv64gc-unknown-linux-gnu \
&& rustup +beta target add riscv64gc-unknown-linux-gnu \
&& rustup +nightly target add riscv64gc-unknown-linux-gnu \
&& cargo install btfdump \
&& rm -rf /var/lib/apt/lists/*
&& cargo install btfdump
13 changes: 9 additions & 4 deletions containers/Dockerfile.native-x86_64-unknown-linux-gnu
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM docker.io/debian:bookworm

ENV PATH="/root/.cargo/bin:/usr/lib/llvm-18/bin:${PATH}"
ENV PATH="/home/cross/.cargo/bin:/usr/lib/llvm-18/bin:${PATH}"

RUN apt update \
&& apt install -y \
Expand All @@ -18,9 +18,14 @@ RUN apt update \
&& chmod +x llvm.sh \
&& ./llvm.sh 18 \
&& rm -f llvm.sh \
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& rm -rf /var/lib/apt/lists/* \
&& useradd -m -G users -s /bin/bash cross

USER cross
WORKDIR /home/cross

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& rustup toolchain install stable --component rust-src \
&& rustup toolchain install beta --component rust-src \
&& rustup toolchain install nightly --component rust-src \
&& cargo install btfdump \
&& rm -rf /var/lib/apt/lists/*
&& cargo install btfdump
19 changes: 12 additions & 7 deletions containers/Dockerfile.native-x86_64-unknown-linux-musl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM docker.io/gentoo/stage3:musl-llvm

ENV PATH="/root/.cargo/bin:/usr/lib/llvm/18/bin:${PATH}"
ENV PATH="/home/cross/.cargo/bin:/usr/lib/llvm/18/bin:${PATH}"
# Enable static libraries for installed packages (zstd, zlib etc.).
ENV USE="static-libs"

Expand All @@ -18,12 +18,17 @@ RUN emerge --sync --quiet \
&& eselect repository add vadorovsky git https://gitlab.com/vadorovsky/overlay \
&& emerge --sync --quiet \
&& emerge sys-libs/llvm-libgcc \
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& rustup toolchain install stable --component rust-src \
&& rustup toolchain install beta --component rust-src \
&& rustup toolchain install nightly --component rust-src \
&& cargo install btfdump \
&& rm -rf \
/var/cache/binpkgs/* \
/var/cache/distfiles/* \
/var/tmp/portage/*
/var/tmp/portage/* \
&& useradd -m -G users -s /bin/bash cross

USER cross
WORKDIR /home/cross

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& rustup toolchain install stable --component rust-src \
&& rustup toolchain install beta --component rust-src \
&& rustup toolchain install nightly --component rust-src \
&& cargo install btfdump

0 comments on commit bea3ddf

Please sign in to comment.