forked from bottlerocket-os/bottlerocket-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
1427 lines (1128 loc) · 43.9 KB
/
Dockerfile
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
FROM public.ecr.aws/docker/library/fedora:40 as base
# Everything we need to build our SDK and packages.
RUN \
dnf makecache && \
dnf -y update && \
dnf -y install --setopt=install_weak_deps=False \
bc \
bison \
cmake \
cpio \
curl \
dnf-plugins-core \
dwarves \
elfutils-devel \
flex \
g++ \
gcc \
git \
gperf \
hostname \
intltool \
jq \
json-c-devel \
kmod \
libcurl-devel \
libtool \
meson \
openssl \
openssl-devel \
p11-kit-devel \
perl-ExtUtils-MakeMaker \
perl-FindBin \
perl-IPC-Cmd \
perl-open \
python \
rsync \
wget \
which \
&& \
dnf config-manager --set-disabled \
fedora-cisco-openh264 \
&& \
useradd builder
COPY ./sdk-fetch /usr/local/bin
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
# We expect our C cross-compiler to be used on other distros for building kernel
# modules, so we build it with an older glibc for compatibility.
FROM public.ecr.aws/docker/library/ubuntu:16.04 as compat
RUN \
apt-get update && \
apt-get -y dist-upgrade && \
apt-get -y install \
autoconf \
automake \
bc \
build-essential \
cpio \
curl \
file \
git \
libexpat1-dev \
libtool \
libz-dev \
pkgconf \
python3 \
unzip \
wget \
&& \
useradd -m -u 1000 builder
COPY ./sdk-fetch /usr/local/bin
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM compat as toolchain
USER builder
# Configure Git for any subsequent use.
RUN \
git config --global user.name "Builder" && \
git config --global user.email "builder@localhost"
ARG UPSTREAM_SOURCE_FALLBACK
ENV BRVER="2024.02.8"
ENV KVER="5.10.228"
WORKDIR /home/builder
COPY ./hashes/buildroot ./hashes
RUN \
sdk-fetch hashes && \
tar xf buildroot-${BRVER}.tar.xz && \
rm buildroot-${BRVER}.tar.xz && \
mv buildroot-${BRVER} buildroot && \
mv queue.h queue.h?rev=1.70
WORKDIR /home/builder/buildroot
COPY ./patches/buildroot/* ./
COPY ./configs/buildroot/* ./configs/
COPY ./helpers/buildroot/* ./
RUN \
git init . && \
git apply --whitespace=nowarn *.patch
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM toolchain as toolchain-gnu-x86_64
ENV ARCH="x86_64"
RUN ./build-gnu-toolchain.sh --arch="${ARCH}" --kernel-version="${KVER}"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM toolchain as toolchain-gnu-aarch64
ENV ARCH="aarch64"
RUN ./build-gnu-toolchain.sh --arch="${ARCH}" --kernel-version="${KVER}"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM toolchain as toolchain-musl-x86_64
ENV ARCH="x86_64"
RUN ./build-musl-toolchain.sh --arch="${ARCH}" --kernel-version="${KVER}"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM toolchain as toolchain-musl-aarch64
ENV ARCH="aarch64"
RUN ./build-musl-toolchain.sh --arch="${ARCH}" --kernel-version="${KVER}"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
# Add our cross-compilers to the base SDK layer.
FROM base as sdk
USER root
ARG UPSTREAM_SOURCE_FALLBACK
ENV KVER="5.10.228"
WORKDIR /
COPY --chown=0:0 --from=toolchain-gnu-x86_64 \
/home/builder/buildroot/output/x86_64-gnu/toolchain/ /
COPY --chown=0:0 --from=toolchain-gnu-x86_64 \
/home/builder/buildroot/output/x86_64-gnu/build/linux-headers-${KVER}/usr/include/ \
/x86_64-bottlerocket-linux-gnu/sys-root/usr/include/
COPY --chown=0:0 --from=toolchain-gnu-x86_64 \
/home/builder/buildroot/output/x86_64-gnu/build/licenses/ \
/x86_64-bottlerocket-linux-gnu/sys-root/usr/share/licenses/
COPY --chown=0:0 --from=toolchain-gnu-aarch64 \
/home/builder/buildroot/output/aarch64-gnu/toolchain/ /
COPY --chown=0:0 --from=toolchain-gnu-aarch64 \
/home/builder/buildroot/output/aarch64-gnu/build/linux-headers-${KVER}/usr/include/ \
/aarch64-bottlerocket-linux-gnu/sys-root/usr/include/
COPY --chown=0:0 --from=toolchain-gnu-aarch64 \
/home/builder/buildroot/output/aarch64-gnu/build/licenses/ \
/aarch64-bottlerocket-linux-gnu/sys-root/usr/share/licenses/
COPY --chown=0:0 --from=toolchain-musl-x86_64 \
/home/builder/buildroot/output/x86_64-musl/toolchain/ /
COPY --chown=0:0 --from=toolchain-musl-x86_64 \
/home/builder/buildroot/output/x86_64-musl/build/linux-headers-${KVER}/usr/include/ \
/x86_64-bottlerocket-linux-musl/sys-root/usr/include/
COPY --chown=0:0 --from=toolchain-musl-x86_64 \
/home/builder/buildroot/output/x86_64-musl/build/licenses/ \
/x86_64-bottlerocket-linux-musl/sys-root/usr/share/licenses/
COPY --chown=0:0 --from=toolchain-musl-aarch64 \
/home/builder/buildroot/output/aarch64-musl/toolchain/ /
COPY --chown=0:0 --from=toolchain-musl-aarch64 \
/home/builder/buildroot/output/aarch64-musl/build/linux-headers-${KVER}/usr/include/ \
/aarch64-bottlerocket-linux-musl/sys-root/usr/include/
COPY --chown=0:0 --from=toolchain-musl-aarch64 \
/home/builder/buildroot/output/aarch64-musl/build/licenses/ \
/aarch64-bottlerocket-linux-musl/sys-root/usr/share/licenses/
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
# Build C libraries so we can build our rust and golang toolchains.
FROM sdk as sdk-gnu
USER builder
WORKDIR /home/builder
COPY ./hashes/glibc ./hashes
COPY ./helpers/glibc/* ./
ENV GLIBCVER="2.38"
ENV KVER="5.10.228"
RUN \
sdk-fetch hashes && \
tar xf glibc-${GLIBCVER}.tar.xz && \
rm glibc-${GLIBCVER}.tar.xz && \
mv glibc-${GLIBCVER} glibc && \
cd glibc && \
mkdir build
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-gnu as sdk-gnu-x86_64
ENV ARCH="x86_64"
RUN ./build-glibc.sh --arch="${ARCH}" --kernel-version="${KVER}"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-gnu as sdk-gnu-aarch64
ENV ARCH="aarch64"
RUN ./build-glibc.sh --arch="${ARCH}" --kernel-version="${KVER}"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk as sdk-musl
USER builder
WORKDIR /home/builder
COPY ./hashes/musl ./hashes
COPY ./helpers/musl/* ./
ENV MUSLVER="1.2.4"
RUN \
sdk-fetch hashes && \
tar xf musl-${MUSLVER}.tar.gz && \
rm musl-${MUSLVER}.tar.gz && \
mv musl-${MUSLVER} musl
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-musl as sdk-musl-x86_64
ENV ARCH="x86_64"
RUN ./build-musl.sh --arch="${ARCH}"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-musl as sdk-musl-aarch64
ENV ARCH="aarch64"
RUN ./build-musl.sh --arch="${ARCH}"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
# Rust's musl targets depend on libunwind.
FROM sdk as sdk-libunwind
USER builder
WORKDIR /home/builder
COPY ./hashes/libunwind ./hashes
COPY ./helpers/libunwind/* ./
ENV LLVMVER="14.0.6"
RUN \
sdk-fetch hashes && \
tar xf llvm-${LLVMVER}.src.tar.xz && \
rm llvm-${LLVMVER}.src.tar.xz && \
mv llvm-${LLVMVER}.src llvm && \
tar xf libcxx-${LLVMVER}.src.tar.xz && \
rm libcxx-${LLVMVER}.src.tar.xz && \
mv libcxx-${LLVMVER}.src libcxx && \
tar xf libunwind-${LLVMVER}.src.tar.xz && \
rm libunwind-${LLVMVER}.src.tar.xz && \
mv libunwind-${LLVMVER}.src libunwind && \
mkdir libunwind/build
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-libunwind as sdk-libunwind-x86_64
ENV ARCH="x86_64"
ENV MUSL_TARGET="${ARCH}-bottlerocket-linux-musl"
COPY --chown=0:0 --from=sdk-musl-x86_64 \
/home/builder/musl/output/${MUSL_TARGET}/sys-root/ \
/${MUSL_TARGET}/sys-root/
RUN ./build-libunwind.sh --arch="${ARCH}"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-libunwind as sdk-libunwind-aarch64
ENV ARCH="aarch64"
ENV MUSL_TARGET="${ARCH}-bottlerocket-linux-musl"
COPY --chown=0:0 --from=sdk-musl-aarch64 \
/home/builder/musl/output/${MUSL_TARGET}/sys-root/ \
/${MUSL_TARGET}/sys-root/
RUN ./build-libunwind.sh --arch="${ARCH}"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM scratch as sdk-libc-gnu
ENV GNU_TARGET_x86_64="x86_64-bottlerocket-linux-gnu"
ENV GNU_TARGET_aarch64="aarch64-bottlerocket-linux-gnu"
COPY --chown=0:0 --from=sdk-gnu-x86_64 \
/home/builder/glibc/output/${GNU_TARGET_x86_64}/sys-root/ \
/${GNU_TARGET_x86_64}/sys-root/
COPY --chown=0:0 --from=sdk-gnu-aarch64 \
/home/builder/glibc/output/${GNU_TARGET_aarch64}/sys-root/ \
/${GNU_TARGET_aarch64}/sys-root/
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM scratch as sdk-libc-musl
ENV MUSL_TARGET_x86_64="x86_64-bottlerocket-linux-musl"
ENV MUSL_TARGET_aarch64="aarch64-bottlerocket-linux-musl"
COPY --chown=0:0 --from=sdk-musl-x86_64 \
/home/builder/musl/output/${MUSL_TARGET_x86_64}/sys-root/ \
/${MUSL_TARGET_x86_64}/sys-root/
COPY --chown=0:0 --from=sdk-libunwind-x86_64 \
/home/builder/libunwind/output/${MUSL_TARGET_x86_64}/sys-root/ \
/${MUSL_TARGET_x86_64}/sys-root/
COPY --chown=0:0 --from=sdk-musl-aarch64 \
/home/builder/musl/output/${MUSL_TARGET_aarch64}/sys-root/ \
/${MUSL_TARGET_aarch64}/sys-root/
COPY --chown=0:0 --from=sdk-libunwind-aarch64 \
/home/builder/libunwind/output/${MUSL_TARGET_aarch64}/sys-root/ \
/${MUSL_TARGET_aarch64}/sys-root/
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk as sdk-libc
COPY --from=sdk-libc-gnu / /
COPY --from=sdk-libc-musl / /
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-libc as sdk-rust
USER root
RUN \
mkdir -p /usr/libexec/rust && \
chown -R builder:builder /usr/libexec/rust
ARG HOST_ARCH
ENV VENDOR="bottlerocket"
ENV RUSTVER="1.82.0"
USER builder
WORKDIR /home/builder
COPY ./hashes/rust ./hashes
RUN \
sdk-fetch hashes && \
tar xf rustc-${RUSTVER}-src.tar.xz && \
rm rustc-${RUSTVER}-src.tar.xz && \
mv rustc-${RUSTVER}-src rust
WORKDIR /home/builder/rust
RUN \
dir=build/cache/$(awk -F= '/^compiler_date/{print $2}' src/stage0); \
mkdir -p $dir && mv ../*.xz $dir
# For any architecture, we rely on two or more of Rust's native targets:
#
# 1) the host platform
# (x86_64-unknown-linux-gnu for a Fedora x86_64 host)
# 2) the target platform for dynamically linked builds
# (x86_64-unknown-linux-gnu for a Bottlerocket x86_64 target)
# 3) the target platform for statically linked builds
# (x86_64-unknown-linux-musl for a Bottlerocket x86_64 target)
#
# We need to override the C compiler used for linking the targets in #2 and #3,
# to ensure that the libraries in our sysroot are used instead of the host's
# libraries.
#
# If the target in #1 is the same as #2 or #3, then we're in trouble. This can
# happen with build scripts, which may require us to build for the host before
# we can build for the target. In this scenario, we have to pick from two bad
# options: link host programs with the target's libraries, which may fail to
# run if the host's libraries are too old; or link target programs with the
# host's libraries, which may fail to run if the host's libraries are too new.
#
# To resolve this, we create vendor-specific targets based on the native ones.
# That allows us to leave the settings for the host platform alone, while also
# ensuring that the target platform always uses the libraries from our sysroot.
# These vendor targets are effectively the same as the "unknown" targets.
COPY ./configs/rust/targets ./targets
# In addition to our vendor-specific targets, we also need to build for the host
# platform, since that is no longer done implicitly.
COPY ./configs/rust/config.toml.in ./
RUN \
sed -e "s,@HOST_TRIPLE@,${HOST_ARCH}-unknown-linux-gnu,g" config.toml.in > config.toml && \
RUSTUP_DIST_SERVER=example:// RUST_TARGET_PATH=${PWD}/targets python3 ./x.py install && \
for arch in x86_64 aarch64 ; do \
for libc in gnu musl ; do \
cp \
targets/${arch}-bottlerocket-linux-${libc}.json \
/usr/libexec/rust/lib/rustlib/${arch}-bottlerocket-linux-${libc}/target.json ; \
done ; \
done
RUN \
install -p -m 0644 -Dt licenses COPYRIGHT LICENSE-*
# Set appropriate environment for using this Rust compiler to build tools
ENV PATH="/usr/libexec/rust/bin:$PATH" LD_LIBRARY_PATH="/usr/libexec/rust/lib"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk as sdk-grub
USER root
ARG HOST_ARCH
ENV GRUB_VER="2.06-61.amzn2023.0.9"
RUN \
mkdir -p /usr/libexec/tools /usr/share/licenses/grub && \
chown -R builder:builder /usr/libexec/tools /usr/share/licenses/grub
USER builder
WORKDIR /home/builder
COPY ./hashes/grub /home/builder/hashes
COPY ./patches/grub /home/builder/patches
# This rather elaborate way of unpacking the sources and applying the
# patches mimics the way GRUB is built in Bottlerocket, which in turn
# mimics the way that Amazon Linux and Fedora build it.
RUN \
sdk-fetch /home/builder/hashes && \
rpm2cpio "grub2-${GRUB_VER}.src.rpm" \
| cpio -iu \
"grub-${GRUB_VER%%-*}.tar.xz" \
bootstrap bootstrap.conf gitignore \
"gnulib-*.tar.gz" "*.patch" && \
rm "grub2-${GRUB_VER}.src.rpm" && \
mkdir "grub-${GRUB_VER}" && \
cd "grub-${GRUB_VER}" && \
tar --strip-components=1 -xof "../grub-${GRUB_VER%%-*}.tar.xz" && \
rm "../grub-${GRUB_VER%%-*}.tar.xz" && \
mv ../bootstrap{,.conf} . && \
mv ../gitignore .gitignore && \
tar -xof ../gnulib-*.tar.gz && \
rm ../gnulib-*.tar.gz && \
mv gnulib-* gnulib && \
mv unicode/COPYING COPYING.unicode && \
rm -f configure && \
git init && \
git config user.name 'Builder' && \
git config user.email 'builder@localhost' && \
git add . && \
git commit -a -q -m "base" && \
git am --whitespace=nowarn ../*.patch ../patches/*.patch && \
rm ../*.patch && \
rm -r build-aux m4 && \
./bootstrap
WORKDIR /home/builder/grub-${GRUB_VER}
RUN \
cp -p COPYING COPYING.unicode /usr/share/licenses/grub
# We only need the grub-bios-setup tool for the host. However, we can only get
# it by specifying the "i386" target, which the host toolchain may not support.
# Work around this by using our cross-compiling toolchain for x86_64 to build
# any target binaries.
ENV TARGET="x86_64-bottlerocket-linux-gnu"
ENV TARGET_CPP="${TARGET}-gcc -E"
ENV TARGET_CC="${TARGET}-gcc"
ENV TARGET_NM="${TARGET}-nm"
ENV TARGET_OBJCOPY="${TARGET}-objcopy"
ENV TARGET_STRIP="${TARGET}-strip"
RUN \
./configure \
--host="${HOST_ARCH}-redhat-linux" \
--target="i386" \
--with-platform="pc" \
--with-utils=host \
--disable-grub-mkfont \
--disable-rpm-sort \
--disable-werror \
--enable-efiemu=no \
--enable-device-mapper=no \
--enable-libzfs=no && \
make -j"$(nproc)" && \
cp -p grub-bios-setup /usr/libexec/tools/grub-bios-setup
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk as sdk-bootconfig
USER root
ENV KVER="5.10.228"
RUN \
mkdir -p /usr/libexec/tools /usr/share/licenses/bootconfig && \
chown -R builder:builder /usr/libexec/tools /usr/share/licenses/bootconfig
USER builder
WORKDIR /home/builder
COPY ./hashes/kernel /home/builder/hashes
RUN \
sdk-fetch /home/builder/hashes && \
tar -xf linux-${KVER}.tar.xz && rm linux-${KVER}.tar.xz
WORKDIR /home/builder/linux-${KVER}
RUN \
cp -p COPYING LICENSES/preferred/GPL-2.0 /usr/share/licenses/bootconfig
RUN \
make -C tools/bootconfig && \
cp tools/bootconfig/bootconfig /usr/libexec/tools/bootconfig
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk as sdk-ca-certificates
USER root
ENV CABUNDLEVER="2024-07-02"
RUN \
mkdir -p /usr/share/bottlerocket/ca-certificates && \
chown -R builder:builder /usr/share/bottlerocket/ca-certificates
USER builder
WORKDIR /home/builder
COPY ./hashes/ca-certificates ./hashes
RUN \
sdk-fetch hashes && \
install -p -m 0644 cacert-${CABUNDLEVER}.pem /usr/share/bottlerocket/ca-certificates/ca-bundle.crt
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-libc as sdk-go-prep
# Set up the environment for building.
ENV GOOS="linux"
ENV CGO_ENABLED=1
ENV CFLAGS="-O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-clash-protection -fno-omit-frame-pointer"
ENV CXXFLAGS="${CFLAGS}"
ENV LDFLAGS="-Wl,-z,relro -Wl,-z,now"
ENV CGO_CFLAGS="${CFLAGS}"
ENV CGO_CXXFLAGS="${CXXFLAGS}"
ENV CGO_LDFLAGS="${LDFLAGS}"
ENV GO111MODULE="auto"
ENV AWS_LC_FIPS_VER="2.0.17"
USER root
RUN dnf -y install golang
ENV GO123VER="1.23.3"
ENV GO122VER="1.22.9"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-go-prep as sdk-go-1.23-prep
ENV GOMAJOR="1.23"
USER builder
WORKDIR /home/builder/sdk-go
COPY ./hashes/go-${GOMAJOR} /home/builder/hashes-go
COPY ./helpers/go/* ./
COPY ./patches/go-${GOMAJOR} /home/builder/patches-go
COPY ./hashes/aws-lc /home/builder/hashes-aws-lc
COPY ./patches/aws-lc /home/builder/patches-aws-lc
RUN ./prep-go.sh --go-version=${GO123VER}
WORKDIR /home/builder/aws-lc/build
COPY ./configs/aws-lc/* .
COPY ./helpers/aws-lc/* .
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-go-prep as sdk-go-1.22-prep
ENV GOMAJOR="1.22"
USER builder
WORKDIR /home/builder/sdk-go
COPY ./hashes/go-${GOMAJOR} /home/builder/hashes-go
COPY ./helpers/go/* ./
COPY ./patches/go-${GOMAJOR} /home/builder/patches-go
COPY ./hashes/aws-lc /home/builder/hashes-aws-lc
COPY ./patches/aws-lc /home/builder/patches-aws-lc
RUN ./prep-go.sh --go-version=${GO122VER}
WORKDIR /home/builder/aws-lc/build
COPY ./configs/aws-lc/* .
COPY ./helpers/aws-lc/* .
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-go-1.23-prep as sdk-go-1.23-aws-lc-x86_64
ENV ARCH="x86_64"
RUN ./build-aws-lc.sh --arch="${ARCH}" --go-dir="${HOME}/sdk-go"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-go-1.23-prep as sdk-go-1.23-aws-lc-aarch64
ENV ARCH="aarch64"
RUN ./build-aws-lc.sh --arch="${ARCH}" --go-dir="${HOME}/sdk-go"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-go-1.22-prep as sdk-go-1.22-aws-lc-x86_64
ENV ARCH="x86_64"
RUN ./build-aws-lc.sh --arch="${ARCH}" --go-dir="${HOME}/sdk-go"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-go-1.22-prep as sdk-go-1.22-aws-lc-aarch64
ENV ARCH="aarch64"
RUN ./build-aws-lc.sh --arch="${ARCH}" --go-dir="${HOME}/sdk-go"
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-go-1.23-prep as sdk-go-1.23
COPY --from=sdk-go-1.23-aws-lc-x86_64 \
/home/builder/aws-lc/build/goboringcrypto_linux_amd64.syso \
/home/builder/sdk-go/src/crypto/internal/boring/syso/goboringcrypto_linux_amd64.syso
COPY --from=sdk-go-1.23-aws-lc-aarch64 \
/home/builder/aws-lc/build/goboringcrypto_linux_arm64.syso \
/home/builder/sdk-go/src/crypto/internal/boring/syso/goboringcrypto_linux_arm64.syso
COPY ./helpers/go/* ./
# Build Go - finally!
RUN ./build-go.sh --go-version=${GO123VER}
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-go-1.22-prep as sdk-go-1.22
COPY --from=sdk-go-1.22-aws-lc-x86_64 \
/home/builder/aws-lc/build/goboringcrypto_linux_amd64.syso \
/home/builder/sdk-go/src/crypto/internal/boring/syso/goboringcrypto_linux_amd64.syso
COPY --from=sdk-go-1.22-aws-lc-aarch64 \
/home/builder/aws-lc/build/goboringcrypto_linux_arm64.syso \
/home/builder/sdk-go/src/crypto/internal/boring/syso/goboringcrypto_linux_arm64.syso
COPY ./helpers/go/* ./
# Build Go - finally!
RUN ./build-go.sh --go-version=${GO122VER}
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-rust as sdk-cargo
USER builder
# Cache crates.io index here to avoid repeated downloads if a build fails.
RUN cargo install lazy_static ||:
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-rust as rust-sources
# Copy the sources without clarify.toml or deny.toml, so that validation failures
# don't require a full rebuild from source every time those files are modified.
COPY license-scan /license-scan
USER root
RUN rm /license-scan/{clarify,deny}.toml
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-cargo as sdk-license-scan
ENV SPDXVER="3.19"
USER builder
WORKDIR /home/builder/license-scan
COPY ./hashes/license-scan ./hashes
RUN \
sdk-fetch hashes && \
tar xf license-list-data-${SPDXVER}.tar.gz license-list-data-${SPDXVER}/json/details && \
rm license-list-data-${SPDXVER}.tar.gz && \
mv license-list-data-${SPDXVER} /home/builder/license-list-data
COPY --from=rust-sources /license-scan /home/builder/license-scan
RUN cargo build --release --locked
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-cargo as sdk-cargo-deny
ENV DENYVER="0.16.1"
USER builder
WORKDIR /home/builder
COPY ./hashes/cargo-deny ./hashes
RUN \
sdk-fetch hashes && \
tar xf cargo-deny-${DENYVER}.tar.gz && \
rm cargo-deny-${DENYVER}.tar.gz && \
mv cargo-deny-${DENYVER} cargo-deny
WORKDIR /home/builder/cargo-deny
RUN cargo build --release --locked
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-cargo as sdk-cargo-make
ENV MAKEVER="0.36.8"
USER builder
WORKDIR /home/builder
COPY ./hashes/cargo-make ./hashes
RUN \
sdk-fetch hashes && \
tar xf cargo-make-${MAKEVER}.tar.gz && \
rm cargo-make-${MAKEVER}.tar.gz && \
mv cargo-make-${MAKEVER} cargo-make
WORKDIR /home/builder/cargo-make
RUN cargo build --release --locked
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-cargo as sdk-rust-tools
# Bring it all back together and run license-scan and cargo-deny on everything.
COPY --from=sdk-cargo-deny \
/home/builder/cargo-deny \
/home/builder/cargo-deny
COPY --from=sdk-cargo-make \
/home/builder/cargo-make \
/home/builder/cargo-make
COPY --from=sdk-license-scan \
/home/builder/license-scan \
/home/builder/license-scan
COPY --chown=0:0 --from=sdk-cargo-deny \
/home/builder/cargo-deny/target/release/cargo-deny \
/usr/libexec/tools/
COPY --chown=0:0 --from=sdk-cargo-make \
/home/builder/cargo-make/target/release/cargo-make \
/usr/libexec/tools/
COPY --chown=0:0 --from=sdk-license-scan \
/home/builder/license-scan/target/release/bottlerocket-license-scan \
/usr/libexec/tools/
COPY --chown=0:0 --from=sdk-license-scan \
/home/builder/license-list-data/json/details \
/usr/libexec/tools/spdx-data
COPY --chown=1000:1000 --from=sdk-cargo-deny \
/home/builder/cargo-deny/LICENSE-* \
/usr/share/licenses/cargo-deny/
COPY --chown=1000:1000 --from=sdk-cargo-make \
/home/builder/cargo-make/LICENSE \
/usr/share/licenses/cargo-make/
COPY --chown=1000:1000 \
COPYRIGHT LICENSE-APACHE LICENSE-MIT \
/usr/share/licenses/bottlerocket-license-scan/
WORKDIR /home/builder/cargo-deny
COPY ./configs/cargo-deny/clarify.toml .
RUN \
/usr/libexec/tools/bottlerocket-license-scan \
--clarify clarify.toml \
--spdx-data /usr/libexec/tools/spdx-data \
--out-dir /usr/share/licenses/cargo-deny/vendor \
cargo --locked Cargo.toml
COPY ./configs/cargo-deny/deny.toml .
RUN \
/usr/libexec/tools/cargo-deny \
--all-features check --disable-fetch licenses bans sources
WORKDIR /home/builder/cargo-make
COPY ./configs/cargo-make/clarify.toml .
RUN \
/usr/libexec/tools/bottlerocket-license-scan \
--clarify clarify.toml \
--spdx-data /usr/libexec/tools/spdx-data \
--out-dir /usr/share/licenses/cargo-make/vendor \
cargo --locked Cargo.toml
COPY ./configs/cargo-make/deny.toml .
RUN \
/usr/libexec/tools/cargo-deny \
--all-features check --disable-fetch licenses bans sources
WORKDIR /home/builder/license-scan
COPY license-scan/clarify.toml .
RUN \
/usr/libexec/tools/bottlerocket-license-scan \
--clarify clarify.toml \
--spdx-data /usr/libexec/tools/spdx-data \
--out-dir /usr/share/licenses/bottlerocket-license-scan/vendor \
cargo --locked Cargo.toml
COPY license-scan/deny.toml .
RUN \
/usr/libexec/tools/cargo-deny \
--all-features check --disable-fetch licenses bans sources
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-go-1.22 as sdk-govc
USER root
RUN \
mkdir -p /usr/libexec/tools /usr/share/licenses/govmomi && \
chown -R builder:builder /usr/libexec/tools /usr/share/licenses/govmomi
ENV GOVMOMIVER="0.30.2"
ENV GOVMOMISHORTCOMMIT="9078b0b"
ENV GOVMOMIDATE="2023-02-01T04:38:23Z"
USER builder
WORKDIR /home/builder/go/src/github.com/vmware/govmomi
COPY ./hashes/govmomi /home/builder/hashes
RUN \
sdk-fetch /home/builder/hashes && \
tar --strip-components=1 -xf govmomi-${GOVMOMIVER}.tar.gz && \
rm govmomi-${GOVMOMIVER}.tar.gz
COPY --chown=0:0 --from=sdk-rust-tools /usr/libexec/tools/ /usr/libexec/tools/
RUN \
cp -p LICENSE.txt /usr/share/licenses/govmomi && \
go mod vendor && \
/usr/libexec/tools/bottlerocket-license-scan \
--spdx-data /usr/libexec/tools/spdx-data \
--out-dir /usr/share/licenses/govmomi/vendor \
go-vendor ./vendor
RUN \
export CGO_ENABLED=0 ; \
export BUILD_VERSION_PKG="github.com/vmware/govmomi/govc/flags" ; \
go build -mod=vendor -o /usr/libexec/tools/govc -ldflags " \
-s -w \
-X ${BUILD_VERSION_PKG}.BuildVersion=${GOVMOMIVER} \
-X ${BUILD_VERSION_PKG}.BuildCommit=${GOVMOMISHORTCOMMIT} \
-X ${BUILD_VERSION_PKG}.BuildDate=${GOVMOMIDATE} \
" github.com/vmware/govmomi/govc
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-go-1.22 as sdk-docker
USER root
RUN \
mkdir -p /usr/libexec/tools /usr/share/licenses/docker && \
chown -R builder:builder /usr/libexec/tools /usr/share/licenses/docker
ENV DOCKERVER="20.10.21"
ENV DOCKERCOMMIT="baeda1f82a10204ec5708d5fbba130ad76cfee49"
ENV DOCKERIMPORT="github.com/docker/cli"
ENV MOBYBIRTHDAY="2017-04-18T14:29:00.000000000+00:00"
USER builder
WORKDIR /home/builder/go/src/${DOCKERIMPORT}
COPY ./hashes/docker /home/builder/hashes
RUN \
sdk-fetch /home/builder/hashes && \
tar --strip-components=1 -xf cli-${DOCKERVER}.tar.gz && \
rm cli-${DOCKERVER}.tar.gz
COPY --chown=0:0 --from=sdk-rust-tools /usr/libexec/tools/ /usr/libexec/tools/
COPY ./configs/docker/clarify.toml .
RUN \
cp -p LICENSE NOTICE /usr/share/licenses/docker && \
/usr/libexec/tools/bottlerocket-license-scan \
--clarify clarify.toml \
--spdx-data /usr/libexec/tools/spdx-data \
--out-dir /usr/share/licenses/docker/vendor \
go-vendor ./vendor
RUN \
export CGO_ENABLED=0 ; \
go build -o /usr/libexec/tools/docker -ldflags " \
-s -w \
-X github.com/docker/cli/cli/version.Version=${DOCKERVER} \
-X github.com/docker/cli/cli/version.GitCommit=${DOCKERCOMMIT} \
-X github.com/docker/cli/cli/version.BuildTime=${MOBYBIRTHDAY} \
-X \"github.com/docker/cli/cli/version.PlatformName=Docker Engine - Community\" \
" ${DOCKERIMPORT}/cmd/docker
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-go-1.22 as sdk-oras
USER root
RUN \
mkdir -p /usr/libexec/tools /usr/share/licenses/oras && \
chown -R builder:builder /usr/libexec/tools /usr/share/licenses/oras
ENV ORASVER="1.1.0"
ENV ORASCOMMIT="7079c468a06fb5815c99395eb4aaf46dd459d3fa"
ENV ORASIMPORT="oras.land/oras"
USER builder
WORKDIR /home/builder/go/src/${ORASIMPORT}
COPY ./hashes/oras /home/builder/hashes
RUN \
sdk-fetch /home/builder/hashes && \
tar --strip-components=1 -xf oras-${ORASVER}.tar.gz && \
rm oras-${ORASVER}.tar.gz
COPY --chown=0:0 --from=sdk-rust-tools /usr/libexec/tools/ /usr/libexec/tools/
RUN \
cp -p LICENSE /usr/share/licenses/oras && \
go mod vendor && \
/usr/libexec/tools/bottlerocket-license-scan \
--spdx-data /usr/libexec/tools/spdx-data \
--out-dir /usr/share/licenses/oras/vendor \
go-vendor ./vendor
RUN \
export CGO_ENABLED=0 ; \
export BUILD_VERSION_PKG="${ORASIMPORT}/internal/version" ; \
go build -mod=vendor -o /usr/libexec/tools/oras -ldflags " \
-s -w \
-X ${BUILD_VERSION_PKG}.BuildMetadata=${ORASVER} \
-X ${BUILD_VERSION_PKG}.GitCommit=${ORASCOMMIT} \
-X ${BUILD_VERSION_PKG}.GitTreeState=clean \
" ${ORASIMPORT}/cmd/oras
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk as sdk-cpp
ENV AWS_SDK_CPP_VER="1.11.398"
USER builder
WORKDIR /home/builder/aws-sdk-cpp-src
COPY ./hashes/aws-sdk-cpp /home/builder/aws-sdk-cpp-src/hashes
# Upstream source fallback is explicitly disabled here as the SHA512 hash
# verification fails due to a difference in the upstream names and the SDK's.
RUN \
UPSTREAM_SOURCE_FALLBACK=false sdk-fetch hashes && \
tar --strip-components=1 -xf aws-sdk-cpp-${AWS_SDK_CPP_VER}.tar.gz && \
rm aws-sdk-cpp-${AWS_SDK_CPP_VER}.tar.gz && \
install -p -m 0644 -D -t \
licenses/aws-sdk-cpp-${AWS_SDK_CPP_VER} \
LICENSE {LICENSE,NOTICE}.txt && \
tar -C crt/aws-crt-cpp --strip-components=1 -xf aws-crt-cpp.tar.gz && \
rm aws-crt-cpp.tar.gz && \
install -p -m 0644 -D -t \
licenses/aws-sdk-cpp-${AWS_SDK_CPP_VER}/crt \
crt/aws-crt-cpp/{LICENSE,NOTICE}
RUN \
for tar in *.tar.gz ; do \
dir="${tar%%.*}" && \
tar -C crt/aws-crt-cpp/crt/${dir} --strip-components=1 -xf ${tar} && \
licenses="$(\
cd crt/aws-crt-cpp && \
find crt/${dir} -type f \
\( -iname '*LICENSE*' -o -iname '*NOTICE*' \) \
! -iname '*.cpp' ! -iname '*.h' ! -iname '*.json' \
! -iname '*.go' ! -iname '*.yml' ! -path '*tests*' )" && \
for license in ${licenses} ; do \
licensedir="licenses/aws-sdk-cpp-${AWS_SDK_CPP_VER}/${license%/*}" && \
mkdir -p "${licensedir}" && \
install -p -m 0644 "crt/aws-crt-cpp/${license}" "${licensedir}" ; \
done ; \
done && \
rm *.tar.gz
WORKDIR /home/builder/aws-sdk-cpp-src/build
RUN \
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_ONLY="kms;acm-pca" \
-DENABLE_TESTING=OFF \
-DCMAKE_INSTALL_PREFIX=/home/builder/aws-sdk-cpp \
-DBUILD_SHARED_LIBS=OFF && \
make && \
make install
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
FROM sdk-cpp as sdk-aws-kms-pkcs11
ENV AWS_KMS_PKCS11_VER="0.0.11"
USER builder