Repository navigation
Expand file tree
/
Copy pathDockerfile.fde
More file actions
153 lines (128 loc) · 7.22 KB
/
Copy pathDockerfile.fde
File metadata and controls
153 lines (128 loc) · 7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Builder stage - build RPM packages
FROM alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:latest AS builder
# Increase yum download speed
RUN sed -i 's/^max_parallel_downloads=.*/max_parallel_downloads=20/' /etc/yum.conf ; if ! grep -q '^max_parallel_downloads=' /etc/yum.conf; then sed -i '/^\[main\]$/a max_parallel_downloads=20' /etc/yum.conf; fi ;
# Install Rust toolchain
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
sh -s -- -y --no-modify-path --default-toolchain none
WORKDIR /code/
COPY rust-toolchain.toml .
COPY cryptpilot.spec .
# Install toolchain and cache it
RUN . "$HOME/.cargo/env" && rustup show
# Install build dependencies and resolve the spec's BuildRequires in the same
# yum transaction. Running yum-builddep again in the build step doubles the
# repository metadata download for no gain.
# The in-cloud mirror is far faster than the public one, but is only routable
# from inside Alibaba Cloud; fall back to the public mirror elsewhere.
# Only the fde subpackages are packaged by this image, so disable the
# crypt/verity builds (and their BuildRequires) in the same spec.
# (bcond disables need the underscore-prefixed _without_X macros.)
RUN if ! curl -fsS --max-time 5 \
http://mirrors.cloud.aliyuncs.com/alinux/3/os/x86_64/repodata/repomd.xml \
| grep -q '<repomd'; then \
sed -i -E 's|https?://mirrors\.cloud\.aliyuncs\.com/|https://mirrors.aliyun.com/|g' \
/etc/yum.repos.d/*.repo; \
fi && \
yum install -y git protobuf-devel gcc cmake clang clang-libs \
cryptsetup-devel perl-IPC-Cmd device-mapper-devel fuse3-devel \
rpmdevtools yum-utils && \
yum-builddep -y --skip-unavailable ./cryptpilot.spec \
--define 'with_rustup 1' \
--define '_without_crypt 1' --define '_without_verity 1' && \
yum clean all
COPY . .
# Setup RPM build tree
RUN rpmdev-setuptree
# Build RPM packages using the same process as rpm-build target
RUN . "$HOME/.cargo/env" && \
# Create source tarball
make create-tarball && \
# Copy tarball to RPM build sources
cp /tmp/cryptpilot-$(grep '^version' Cargo.toml | awk -F' = ' '{print $2}' | tr -d '"')-vendored-source.tar.gz ~/rpmbuild/SOURCES/ && \
# Build RPM packages (BuildRequires were installed above)
rpmbuild -ba ./cryptpilot.spec --define 'with_rustup 1' --without crypt --without verity
# e2fsprogs-builder - build a newer e2fsprogs (1.47.0) than alinux3 ships
# (1.46.0). e2fsck >= 1.47 is required to check/resize alinux4 guest images:
# their ext4 uses the casefold feature (FEATURE_C12) which 1.46.0 rejects
# with "Get a newer version of e2fsck!". alinux4's packaged e2fsprogs cannot
# simply be installed here (it needs glibc >= 2.33 while alinux3 has 2.28),
# so build from source against the container's own glibc.
FROM alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:latest AS e2fsprogs-builder
# Increase yum download speed
RUN sed -i 's/^max_parallel_downloads=.*/max_parallel_downloads=20/' /etc/yum.conf ; if ! grep -q '^max_parallel_downloads=' /etc/yum.conf; then sed -i '/^\[main\]$/a max_parallel_downloads=20' /etc/yum.conf; fi ;
RUN if ! curl -fsS --max-time 5 \
http://mirrors.cloud.aliyuncs.com/alinux/3/os/x86_64/repodata/repomd.xml \
| grep -q '<repomd'; then \
sed -i -E 's|https?://mirrors\.cloud\.aliyuncs\.com/|https://mirrors.aliyun.com/|g' \
/etc/yum.repos.d/*.repo; \
fi && \
yum install -y gcc make gettext tar && \
yum clean all
ARG E2FSPROGS_VERSION=1.47.0
ARG E2FSPROGS_SHA256=0b4fe723d779b0927fb83c9ae709bc7b40f66d7df36433bef143e41c54257084
RUN curl -fsSL -o /tmp/e2fsprogs.tar.gz \
"https://kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v${E2FSPROGS_VERSION}/e2fsprogs-${E2FSPROGS_VERSION}.tar.gz" && \
echo "${E2FSPROGS_SHA256} /tmp/e2fsprogs.tar.gz" | sha256sum -c - && \
tar xf /tmp/e2fsprogs.tar.gz -C /tmp && \
cd "/tmp/e2fsprogs-${E2FSPROGS_VERSION}" && \
./configure --libdir=/usr/lib64 && \
make -j"$(nproc)" && \
make install DESTDIR=/staging
# Release stage for cryptpilot-fde
FROM alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:latest AS release-fde
# Increase yum download speed
RUN sed -i 's/^max_parallel_downloads=.*/max_parallel_downloads=20/' /etc/yum.conf ; if ! grep -q '^max_parallel_downloads=' /etc/yum.conf; then sed -i '/^\[main\]$/a max_parallel_downloads=20' /etc/yum.conf; fi ;
# Install the package's heavy, source-independent dependency tree in its own
# layer. This layer depends only on the base image, so a rebuild after a source
# change reuses it and downloads none of the ~670 MB dependency set.
# The list is the host package's Requires plus its Recommends; a cold build
# resolves the same closure that installing the RPM directly would.
RUN if ! curl -fsS --max-time 5 \
http://mirrors.cloud.aliyuncs.com/alinux/3/os/x86_64/repodata/repomd.xml \
| grep -q '<repomd'; then \
sed -i -E 's|https?://mirrors\.cloud\.aliyuncs\.com/|https://mirrors.aliyun.com/|g' \
/etc/yum.repos.d/*.repo; \
fi && \
yum install -y cryptsetup cryptsetup-libs device-mapper-libs kmod coreutils \
util-linux veritysetup lvm2 qemu-img libguestfs-tools-c \
cloud-utils-growpart grub2-tools dosfstools xfsprogs e2fsprogs && \
yum clean all && \
rm -rf /var/cache/yum
# Copy RPM from builder
COPY --from=builder /root/rpmbuild/RPMS/x86_64/cryptpilot-fde-host-*.rpm /tmp/
# place guest RPM to root directory
COPY --from=builder /root/rpmbuild/RPMS/x86_64/cryptpilot-fde-guest-*.rpm /root/
# Install only the freshly built RPM here. Every repository is disabled so this
# transaction resolves against the rpmdb alone: a rebuild downloads no
# metadata and no packages. A dependency added to the spec without being added
# to the layer above fails here loudly instead of being fetched silently.
RUN yum install -y --disablerepo='*' /tmp/cryptpilot-fde-host-*.rpm && \
rm -f /tmp/*.rpm
# Replace the distro e2fsprogs 1.46.0 binaries with the 1.47.0 build (see
# e2fsprogs-builder above). The e2fsprogs tools are statically linked against
# their internal libs, so no shared libraries need to be copied. Only an
# allowlist is copied: e2fsprogs' make install also stages an unmaintained
# 2003-era "blkid" plus "fsck"/"findfs", which must not shadow the
# util-linux versions the image already has.
COPY --from=e2fsprogs-builder \
/staging/sbin/e2fsck \
/staging/sbin/fsck.ext2 \
/staging/sbin/fsck.ext3 \
/staging/sbin/fsck.ext4 \
/staging/sbin/resize2fs \
/staging/sbin/tune2fs \
/staging/sbin/mke2fs \
/staging/sbin/mkfs.ext2 \
/staging/sbin/mkfs.ext3 \
/staging/sbin/mkfs.ext4 \
/staging/sbin/dumpe2fs \
/usr/sbin/
COPY --from=e2fsprogs-builder /staging/etc/mke2fs.conf /etc/mke2fs.conf
# The build may have used the in-cloud mirror (see the probe above). This image
# is published for use outside Alibaba Cloud, so ship public mirror URLs.
RUN sed -i -E 's|https?://mirrors\.cloud\.aliyuncs\.com/|https://mirrors.aliyun.com/|g' /etc/yum.repos.d/*.repo
# No libvirtd runs inside the container; drive virt-customize's qemu directly
# instead of through the libvirt backend.
ENV LIBGUESTFS_BACKEND=direct
CMD ["cryptpilot-fde-host"]