xref: /aosp_15_r20/external/crosvm/tools/impl/dev_container/Dockerfile (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1# Copyright 2021 The ChromiumOS Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# Development container for crosvm.
6#
7# Provides all dependencies specified in install-deps with some additonal
8# logic to cache cargo data in CI runs.
9
10# Build catapult dashboard upload tool in a builder container
11FROM docker.io/golang:bullseye AS gobuilder
12WORKDIR /root/
13RUN git clone https://fuchsia.googlesource.com/infra/infra
14WORKDIR /root/infra/cmd/catapult
15RUN go build
16
17FROM docker.io/debian:testing-slim
18
19ENV RUSTUP_HOME=/usr/local/rustup \
20    CARGO_HOME=/usr/local/cargo \
21    PATH=/workspace/tools:/usr/local/cargo/bin:$PATH
22
23# Install pipx applications globally in /usr/local/bin
24ENV PIPX_HOME=/usr/local/pipx \
25    PIPX_BIN_DIR=/usr/local/bin
26
27# Use a dedicated target directory so we do not write into the source directory.
28RUN mkdir -p /scratch/cargo_target \
29    && mkdir /cache
30
31# Prevent the container from writing __pycache__ files into the src.
32ENV PYTHONDONTWRITEBYTECODE=1
33ENV CARGO_TARGET_DIR=/scratch/cargo_target
34
35# Allow APT to cache packages between docker image builds
36RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
37
38# Add foreign architectures for cross-compilation.
39RUN dpkg --add-architecture arm64 \
40    && dpkg --add-architecture armhf
41
42# Install dependencies (APT and cargo packages are cached between image builds for faster iterative builds).
43COPY --chmod=555 tools/install-deps tools/install-aarch64-deps tools/install-armhf-deps tools/install-mingw64-deps tools/setup-wine64 rust-toolchain /tools/
44RUN cd /tools \
45    && apt-get update \
46    && apt-get install --yes sudo curl \
47    && ./install-deps \
48    # We only use the nightly toolchain for rustfmt, remove other parts to save space.
49    && rustup component remove --toolchain nightly rust-std \
50    && rustup component remove --toolchain nightly cargo
51
52# HACK ALERT!
53# libc6:arm64 postinstall will attempt to call telinit to restart services. This will block
54# indefinitely in the container with no init running. Replace telinit with true to make it
55# a no-op. See b/322015733
56RUN rm /usr/sbin/telinit && cp /bin/true /usr/sbin/telinit
57
58RUN cd /tools \
59    && ./install-aarch64-deps \
60    && ./install-armhf-deps \
61    && ./install-mingw64-deps
62
63# Add wine64 to PATH, as debian removed alternative entry to wine64
64ENV PATH=/usr/lib/wine:$PATH
65
66# Setup wine for root user
67RUN /tools/setup-wine64
68
69# Install global config.toml for cross-compilation
70COPY --chmod=555 .cargo/config.debian.toml /.cargo/config.toml
71
72# Install catapult dashboard upload tool
73COPY --from=gobuilder /root/infra/cmd/catapult/catapult /tools/
74
75# Cache CARGO_HOME between container runs in CI.
76VOLUME /cache
77ENV CROSVM_CACHE_DIR=/cache
78ENV CARGO_HOME=/cache/cargo_home
79
80VOLUME /workspace
81WORKDIR /workspace
82