-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Dockerfile_builder
148 lines (113 loc) · 4.11 KB
/
Dockerfile_builder
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
ARG IMAGE
FROM --platform=$BUILDPLATFORM $IMAGE as rust
# docker buildx args automatically available
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ENV HOME=/home
ENV PATH="${PATH}:/home/.cargo/bin"
WORKDIR /home
RUN cat <<EOF > /usr/local/bin/target
#!/bin/bash
if [ "arm64" = "$TARGETARCH" ]; then
echo aarch64-unknown-linux-musl
else
echo x86_64-unknown-linux-musl
fi
EOF
RUN chmod +x /usr/local/bin/target
# node and npm
#RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
# apt install -y nodejs && \
# rm -rf /var/lib/apt/lists/*
# install latest stable rust + tools
RUN <<EOF
set -e
curl --proto '=https' --tlsv1.3 https://sh.rustup.rs | sh -s -- -y
rustup target add $(target)
cargo install just
cargo install sd
cargo install mdbook
cargo install mdbook-admonish
cargo install sqlx-cli --no-default-features --features rustls,sqlite,postgres
rm -rf /home/.rustup/tmp
rm -rf /home/.cargo/registry
# avoid access rights conflicts for different users later on
chmod -R 777 /home/.cargo
EOF
# any user should be able to use rust from that directory for best DX
RUN chmod a+rwx -R /home
############################################
############################################
############################################
FROM --platform=$BUILDPLATFORM $IMAGE as openssl
ENV LD_LIBRARY_PATH="${PATH}:/usr/local/lib64:${LD_LIBRARY_PATH}"
ENV PKG_CONFIG_PATH="/usr/local/lib64/pkgconfig"
ENV MAKEFLAGS="-j32"
WORKDIR /root
RUN <<EOF
set -e
apt update
apt install -y build-essential checkinstall zlib1g-dev vim
rm -rf /var/lib/apt/lists/*
curl -LO https://github.com/openssl/openssl/releases/download/openssl-3.3.1/openssl-3.3.1.tar.gz
tar xvf openssl-3.3.1.tar.gz
cd openssl-3.3.1
./config
make
make test
make install
echo '/usr/local/lib64' > /etc/ld.so.conf.d/lib64.conf
ldconfig
cd ..
rm -rf openssl*
EOF
############################################
############################################
############################################
FROM --platform=$BUILDPLATFORM $IMAGE
# docker buildx args automatically available
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ENV HOME=/home
ENV PATH="${PATH}:/home/.cargo/bin"
ENV PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=x86_64-linux-musl-gcc
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUNNER="/qemu-runner x86_64"
ENV CC_x86_64_unknown_linux_musl=x86_64-linux-musl-gcc
ENV LD_LIBRARY_PATH="${PATH}:/usr/local/lib64:${LD_LIBRARY_PATH}"
ENV PKG_CONFIG_PATH="/usr/local/lib64/pkgconfig"
# node and npm
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
apt install -y nodejs && \
rm -rf /var/lib/apt/lists/*
# TODO the overhead of a direct npm installation at this point is rather small, but fix when more time
# TODO something is missing for the COPY's
# When the missing parts are found, move the installation up in stage 1 again
#COPY --from=stage1 /etc/alternatives/nodejs /etc/alternatives/nodejs
#COPY --from=stage1 /etc/apt/preferences.d/nodejs /etc/apt/preferences.d/nodejs
#COPY --from=stage1 /usr/bin/npm /usr/bin/npm
#COPY --from=stage1 /usr/bin/node /usr/bin/node
#COPY --from=stage1 /usr/bin/nodejs /usr/bin/nodejs
#COPY --from=stage1 /usr/include/node /usr/include/node
#COPY --from=stage1 /usr/share/doc/node /usr/share/doc/node
#COPY --from=stage1 /var/lib/dpkg/alternatives/nodejs /var/lib/dpkg/alternatives/nodejs
#COPY --from=stage1 /usr/lib/node_modules /usr/lib/node_modules
# rust and tools
COPY --from=rust /usr/local/bin/target /usr/local/bin/target
COPY --from=rust /home /home
# openssl
COPY --from=openssl /etc/ld.so.conf.d/lib64.conf /etc/ld.so.conf.d/lib64.conf
COPY --from=openssl /usr/local/lib64 /usr/local/lib64
COPY --from=openssl /usr/local/include/openssl /usr/local/include/openssl
COPY --from=openssl /usr/local/bin/openssl /usr/local/bin/openssl
COPY --from=openssl /usr/local/bin/c_rehash /usr/local/bin/c_rehash
COPY --from=openssl /usr/local/ssl /usr/local/ssl
COPY --from=openssl /usr/local/share/man /usr/local/share/man
COPY --from=openssl /usr/local/share/doc/openssl /usr/local/share/doc/openssl
RUN ldconfig
WORKDIR /work
CMD ["/bin/bash"]