Skip to content

Commit ffc872d

Browse files
committed
Optimize image size
1 parent b6ebffa commit ffc872d

File tree

12 files changed

+112
-109
lines changed

12 files changed

+112
-109
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-amd64-local
1+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-builder-local AS builder
22
ARG ROOTFS_DIR=/crossrootfs/x64
33

44
RUN /scripts/eng/common/cross/build-rootfs.sh x64 alpine3.13 --skipunmount
5+
6+
7+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-amd64-local
8+
ARG ROOTFS_DIR=/crossrootfs/x64
9+
10+
COPY --from=builder $ROOTFS_DIR $ROOTFS_DIR
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-amd64-local
1+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-builder-local AS builder
22
ARG ROOTFS_DIR=/crossrootfs/x64
33

4-
RUN tdnf install -y debootstrap
5-
64
RUN /scripts/eng/common/cross/build-rootfs.sh x64 xenial --skipunmount
75

6+
7+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-amd64-local
8+
ARG ROOTFS_DIR=/crossrootfs/x64
9+
10+
COPY --from=builder $ROOTFS_DIR $ROOTFS_DIR
11+
812
RUN LLVM_VERSION=12.0.1 LLVM_VERSION_MAJOR="${LLVM_VERSION%%.*}" && \
913
mkdir -p $ROOTFS_DIR/usr/lib/llvm-${LLVM_VERSION_MAJOR}/lib/clang/${LLVM_VERSION}/lib/linux/ && \
1014
cp /usr/lib/clang/${LLVM_VERSION}/lib/linux/libclang_rt.profile-x86_64.a $ROOTFS_DIR/usr/lib/llvm-${LLVM_VERSION_MAJOR}/lib/clang/${LLVM_VERSION}/lib/linux/
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-arm-local
1+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-builder-local AS builder
22
ARG ROOTFS_DIR=/crossrootfs/arm64
33

44
RUN /scripts/eng/common/cross/build-rootfs.sh arm64 alpine3.13 --skipunmount
5+
6+
7+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-arm-local
8+
ARG ROOTFS_DIR=/crossrootfs/arm64
9+
10+
COPY --from=builder $ROOTFS_DIR $ROOTFS_DIR
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-artifacts-local as artifacts
2-
3-
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-arm-local
1+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-builder-local AS builder
42
ARG ROOTFS_DIR=/crossrootfs/arm64
53

6-
RUN tdnf install -y debootstrap
7-
84
RUN /scripts/eng/common/cross/build-rootfs.sh arm64 xenial --skipunmount
95

106
# Build compiler-rt profile library for PGO instrumentation
11-
COPY --from=artifacts /llvm-project.src.tar.xz .
12-
RUN mkdir llvm-project.src && \
13-
tar -xf llvm-project.src.tar.xz --directory llvm-project.src --strip-components=1 && \
14-
rm llvm-project.src.tar.xz && \
15-
mkdir compiler-rt_build && cd compiler-rt_build && \
7+
RUN mkdir compiler-rt_build && cd compiler-rt_build && \
168
BUILD_FLAGS="-v --sysroot=$ROOTFS_DIR" \
179
TARGET_TRIPLE=aarch64-linux-gnu && \
1810
cmake ../llvm-project.src/compiler-rt \
@@ -33,11 +25,14 @@ RUN mkdir llvm-project.src && \
3325
-DCMAKE_INSTALL_PREFIX=$ROOTFS_DIR/usr \
3426
-DCMAKE_C_FLAGS="${BUILD_FLAGS}" \
3527
-DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" && \
36-
make -j $(getconf _NPROCESSORS_ONLN) && \
37-
make install
28+
make -j $(getconf _NPROCESSORS_ONLN)
3829

3930
RUN LLVM_VERSION=12.0.1 LLVM_VERSION_MAJOR="${LLVM_VERSION%%.*}" && \
4031
mkdir -p $ROOTFS_DIR/usr/lib/llvm-${LLVM_VERSION_MAJOR}/lib/clang/${LLVM_VERSION}/lib/linux/ && \
4132
cp compiler-rt_build/lib/linux/libclang_rt.profile-aarch64.a $ROOTFS_DIR/usr/lib/llvm-${LLVM_VERSION_MAJOR}/lib/clang/${LLVM_VERSION}/lib/linux/
4233

43-
RUN rm -r compiler-rt_build llvm-project.src
34+
35+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-arm-local
36+
ARG ROOTFS_DIR=/crossrootfs/arm64
37+
38+
COPY --from=builder $ROOTFS_DIR $ROOTFS_DIR
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-artifacts-local as artifacts
2-
3-
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-amd64-local AS rootfsbuild
1+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-builder-local as builder
42
ARG ROOTFS_DIR=/crossrootfs/x86
53

6-
RUN tdnf install -y \
7-
debootstrap \
8-
# Provides LLVMConfig.cmake, needed to build compiler-rt. Only needed on x86.
9-
# x64 doesn't need this because we use compiler-rt from the mariner package.
10-
# arm/arm64 don't need this because LLVMConfig.cmake is provided by the LLVM we build from source.
11-
llvm-devel
4+
# Provides LLVMConfig.cmake, needed to build compiler-rt. Only needed on x86.
5+
# x64 doesn't need this because we use compiler-rt from the mariner package.
6+
# arm/arm64 don't need this because LLVMConfig.cmake is provided by the LLVM we build from source.
7+
RUN tdnf install -y llvm-devel
128

139
RUN /scripts/eng/common/cross/build-rootfs.sh x86 xenial --skipunmount
1410

1511
# Build compiler-rt profile library for PGO instrumentation
16-
COPY --from=artifacts /llvm-project.src.tar.xz .
17-
RUN mkdir llvm-project.src && \
18-
tar -xf llvm-project.src.tar.xz --directory llvm-project.src --strip-components=1 && \
19-
rm llvm-project.src.tar.xz && \
20-
mkdir compiler-rt_build && cd compiler-rt_build && \
12+
RUN mkdir compiler-rt_build && cd compiler-rt_build && \
2113
BUILD_FLAGS="-v --sysroot=$ROOTFS_DIR" \
2214
TARGET_TRIPLE=i386-linux-gnu && \
2315
cmake ../llvm-project.src/compiler-rt \
@@ -38,11 +30,14 @@ RUN mkdir llvm-project.src && \
3830
-DCMAKE_INSTALL_PREFIX=$ROOTFS_DIR/usr \
3931
-DCMAKE_C_FLAGS="${BUILD_FLAGS}" \
4032
-DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" && \
41-
make -j $(getconf _NPROCESSORS_ONLN) && \
42-
make install
33+
make -j $(getconf _NPROCESSORS_ONLN)
4334

4435
RUN LLVM_VERSION=12.0.1 LLVM_VERSION_MAJOR="${LLVM_VERSION%%.*}" && \
4536
mkdir -p $ROOTFS_DIR/usr/lib/llvm-${LLVM_VERSION_MAJOR}/lib/clang/${LLVM_VERSION}/lib/linux/ && \
4637
cp compiler-rt_build/lib/linux/libclang_rt.profile-i386.a $ROOTFS_DIR/usr/lib/llvm-${LLVM_VERSION_MAJOR}/lib/clang/${LLVM_VERSION}/lib/linux/
4738

48-
RUN rm -r compiler-rt_build llvm-project.src
39+
40+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-amd64-local
41+
ARG ROOTFS_DIR=/crossrootfs/x86
42+
43+
COPY --from=builder $ROOTFS_DIR $ROOTFS_DIR
Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
1-
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-artifacts-local as artifacts
1+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-builder-local as builder
22

33
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-local
44

5-
# Install LLVM-only build dependencies
6-
RUN tdnf install -y \
7-
texinfo \
8-
diffutils \
9-
binutils
10-
11-
# Build LLVM cross-toolchain (with support for targeting arm architectures)
12-
COPY --from=artifacts /llvm-project.src.tar.xz .
13-
RUN mkdir llvm-project.src && \
14-
tar -xf llvm-project.src.tar.xz --directory llvm-project.src --strip-components=1 && \
15-
rm llvm-project.src.tar.xz && \
16-
mkdir build && cd build && \
17-
cmake ../llvm-project.src/llvm \
18-
-DCMAKE_BUILD_TYPE=Release \
19-
-DLLVM_TARGETS_TO_BUILD="host;AArch64;ARM" \
20-
-Wno-dev \
21-
-DLLVM_ENABLE_PROJECTS="clang;lld" && \
22-
make -j $(getconf _NPROCESSORS_ONLN) && \
23-
make install
24-
25-
RUN rm -r build llvm-project.src
26-
27-
RUN tdnf remove -y \
28-
texinfo \
29-
diffutils \
30-
binutils
5+
# Install LLVM that we built from source
6+
COPY --from=builder /usr/local /usr/local

src/cbl-mariner/2.0/crossdeps-artifacts/Dockerfile

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-crossdeps-local
2+
3+
# TODO: remove this once debootstrap is available in the base repos.
4+
COPY mariner-extended.repo /etc/yum.repos.d/
5+
6+
RUN tdnf install -y \
7+
# Rootfs build dependencies
8+
debootstrap \
9+
# LLVM build dependencies
10+
texinfo \
11+
diffutils \
12+
binutils
13+
14+
# Obtain ubuntu package signing key (for use by debootstrap)
15+
# 1. Add public key used to sign the ubuntu keyring
16+
COPY dimitri_john_ledkov.asc .
17+
RUN gpg --output dimitri_john_ledkov.gpg --dearmor dimitri_john_ledkov.asc && \
18+
rm dimitri_john_ledkov.asc && \
19+
# 2. Download the ubuntu keyrings
20+
wget https://mirrors.edge.kernel.org/ubuntu/pool/main/u/ubuntu-keyring/ubuntu-keyring_2021.03.26.tar.gz && \
21+
echo "492eed5c06408c6f632577adb0796130af5d6542013ef418f47187a209e49bb1 ubuntu-keyring_2021.03.26.tar.gz" | sha256sum -c && \
22+
tar xf ubuntu-keyring_2021.03.26.tar.gz && \
23+
rm ubuntu-keyring_2021.03.26.tar.gz && \
24+
# 3. Verify keyrings
25+
pushd ubuntu-keyring-2021.03.26 && \
26+
gpg --keyring /dimitri_john_ledkov.gpg --output SHA512SUMS.txt --decrypt SHA512SUMS.txt.asc && \
27+
rm /dimitri_john_ledkov.gpg && \
28+
sha512sum -c SHA512SUMS.txt && \
29+
# 4. Install the needed keyring and delete the rest
30+
mkdir -p /usr/share/keyrings && \
31+
mv keyrings/ubuntu-archive-keyring.gpg /usr/share/keyrings && \
32+
popd && \
33+
rm -r ubuntu-keyring-2021.03.26
34+
35+
# 1. Obtain signing keys used to sign llvm sources
36+
RUN wget https://releases.llvm.org/release-keys.asc && \
37+
echo "f181a90697e3ea4b7782f1ee48314a570aef058505b4f3a0ab0611094ec13241 release-keys.asc" | sha256sum -c && \
38+
gpg --output release-keys.gpg --dearmor release-keys.asc && \
39+
rm release-keys.asc && \
40+
# 2. Download llvm sources and signature, and verify signature
41+
LLVM_VERSION=12.0.1 && \
42+
wget -O llvm-project.src.tar.xz.sig https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/llvm-project-${LLVM_VERSION}.src.tar.xz.sig && \
43+
echo "6cc956d622a7d3d746de0d71d8ca616a6c291e2c561703ac7a9535f38b999955 llvm-project.src.tar.xz.sig" | sha256sum -c && \
44+
wget -O llvm-project.src.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/llvm-project-${LLVM_VERSION}.src.tar.xz && \
45+
echo "129cb25cd13677aad951ce5c2deb0fe4afc1e9d98950f53b51bdcfb5a73afa0e llvm-project.src.tar.xz" | sha256sum -c && \
46+
gpg --keyring /release-keys.gpg --verify llvm-project.src.tar.xz.sig && \
47+
rm llvm-project.src.tar.xz.sig
48+
49+
# Build LLVM cross-toolchain (with support for targeting arm architectures)
50+
RUN mkdir llvm-project.src && \
51+
tar -xf llvm-project.src.tar.xz --directory llvm-project.src --strip-components=1 && \
52+
rm llvm-project.src.tar.xz && \
53+
mkdir build && cd build && \
54+
cmake ../llvm-project.src/llvm \
55+
-DCMAKE_BUILD_TYPE=Release \
56+
-DLLVM_TARGETS_TO_BUILD="host;AArch64;ARM" \
57+
-Wno-dev \
58+
-DLLVM_ENABLE_PROJECTS="clang;lld" && \
59+
make -j $(getconf _NPROCESSORS_ONLN) && \
60+
make install
61+
62+
# Obtain arcade scripts used to build rootfs
63+
RUN git config --global user.email builder@dotnet-buildtools-prereqs-docker && \
64+
git clone --depth 1 --single-branch https://github.com/dotnet/arcade /scripts

0 commit comments

Comments
 (0)