1
- # Because 1.62.0-alpine3.16 does not have a build for arm/v7
2
- FROM rust:1.62.0-slim as build-env
1
+ # See: https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
2
+
3
+ FROM --platform=x86_64 rust:1.62-alpine3.16 as build-env-x86_64-musl
4
+
5
+ ARG TARGETPLATFORM
6
+ ARG BUILDPLATFORM
7
+ ARG TARGETARCH
8
+ ARG TARGETVARIANT
9
+
10
+ WORKDIR /workspace
11
+
12
+ ADD https://github.com/FedericoPonzi/Horust/archive/c6a4cedb5f53836f14d12fd809272fdac9c8969b.tar.gz Horust.tar.gz
13
+ RUN echo "Building arch: ${TARGETARCH}, variant: ${TARGETVARIANT} for ${TARGETPLATFORM} on ${BUILDPLATFORM}" && \
14
+ if [ "${TARGETARCH}" = "amd64" ]; then \
15
+ apk add --no-cache musl-dev openssl-dev; \
16
+ tar -C ./ --strip-components=1 -xzf ./Horust.tar.gz; \
17
+ # https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172
18
+ RUSTFLAGS="-C target-feature=-crt-static" cargo build --release; \
19
+ else \
20
+ mkdir -p /workspace/target/release/; \
21
+ # provide a fake file for Docker copy to suceess
22
+ touch /workspace/target/release/horust; \
23
+ fi
24
+
25
+ # Because rust:1.62-alpine3.16 does not have a build for arm/v7 but arm32v7/rust:1.62-alpine3.16 has it
26
+ # fetch the vendor with the builder platform to avoid qemu issues (https://github.com/docker/buildx/issues/395)
27
+ FROM --platform=x86_64 blackdex/rust-musl:armv7-musleabihf-stable-1.62.1 as build-env-horust
28
+
29
+ ARG TARGETPLATFORM
30
+ ARG BUILDPLATFORM
31
+ ARG TARGETARCH
32
+ ARG TARGETVARIANT
3
33
4
34
WORKDIR /workspace
5
35
6
- RUN apk add --no-cache curl musl-dev openssl-dev && \
7
- curl -s -L -# -o ./Horust.tar.gz https://github.com/FedericoPonzi/Horust/archive/c6a4cedb5f53836f14d12fd809272fdac9c8969b.tar.gz && \
8
- tar -C ./ --strip-components=1 -xzf ./Horust.tar.gz && \
9
- # https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172
10
- RUSTFLAGS="-C target-feature=-crt-static" cargo build --release
36
+ COPY --from=build-env-x86_64-musl /workspace/target/release/horust /workspace/horust_x86_64
37
+
38
+ ADD https://github.com/FedericoPonzi/Horust/archive/c6a4cedb5f53836f14d12fd809272fdac9c8969b.tar.gz Horust.tar.gz
39
+ RUN echo "Building arch: ${TARGETARCH}, variant: ${TARGETVARIANT} for ${TARGETPLATFORM} on ${BUILDPLATFORM}" && \
40
+ if [ "${TARGETARCH}${TARGETVARIANT}" = "armv7" ]; then \
41
+ tar -C ./ --strip-components=1 -xzf ./Horust.tar.gz; \
42
+ # https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172
43
+ RUSTFLAGS="-C target-feature=-crt-static" cargo build --release --target=armv7-unknown-linux-musleabihf; \
44
+ mv /workspace/target/armv7-unknown-linux-musleabihf/release/horust /workspace/horust; \
45
+ else \
46
+ mv /workspace/horust_x86_64 /workspace/horust; \
47
+ fi
11
48
12
- FROM alpine:3.16 as build-env-sasl
49
+ # fetch the vendor with the builder platform to avoid qemu issues (https://github.com/docker/buildx/issues/395)
50
+ FROM --platform=$TARGETPLATFORM alpine:3.16 as build-env-sasl
51
+
52
+ ARG TARGETPLATFORM
53
+ ARG BUILDPLATFORM
13
54
14
55
WORKDIR /workspace
15
56
@@ -24,10 +65,13 @@ RUN apk add --no-cache --update alpine-sdk && \
24
65
apk add --no-cache gdbm-dev openssl1.1-compat-dev linux-pam-dev py3-sphinx sqlite-dev openldap-dev automake autoconf libtool && \
25
66
abuild -F && \
26
67
mv /root/.abuild/
[email protected] *.rsa.pub /root/packages/${RSA_PRIVATE_KEY_NAME}.pub && \
27
- mv /root/.abuild/
[email protected] *.rsa /root/packages/${RSA_PRIVATE_KEY_NAME} && \
28
- abuild-sign -k /root/packages/${RSA_PRIVATE_KEY_NAME} /root/packages/x86_64/APKINDEX.tar.gz
68
+ mv /root/.abuild/
[email protected] *.rsa /root/packages/${RSA_PRIVATE_KEY_NAME}
69
+
70
+ # fetch the vendor with the builder platform to avoid qemu issues (https://github.com/docker/buildx/issues/395)
71
+ FROM --platform=$TARGETPLATFORM alpine:3.16
29
72
30
- FROM alpine:3.16
73
+ ARG TARGETPLATFORM
74
+ ARG BUILDPLATFORM
31
75
32
76
# See: https://www.openldap.org/software/release/changes.html
33
77
# See: https://git.openldap.org/openldap/openldap/-/tree/OPENLDAP_REL_ENG_2_6_3
@@ -42,7 +86,7 @@ ARG BUILD_DATE
42
86
ENV LDAP_LOG_LEVEL=0
43
87
ENV LDAP_NOFILE=1024
44
88
45
- COPY --from=build-env /workspace/target/release/ horust /sbin /horust
89
+ COPY --from=build-env-horust /workspace/horust /usr/bin /horust
46
90
COPY --from=build-env-sasl /root/packages/ /root/packages/
47
91
RUN apk add --no-cache --update \
48
92
# https://github.com/mischov/meeseeks/issues/98#issuecomment-636615680
@@ -70,7 +114,7 @@ RUN apk add --no-cache --update \
70
114
# Enable ldapi:///
71
115
mkdir /var/lib/openldap/run && \
72
116
touch /var/lib/openldap/run/ldapi && \
73
- /sbin/ horust --version && \
117
+ horust --version && \
74
118
# Add dependencies that the next step can not add without a network repo
75
119
apk add --no-cache linux-pam sqlite-libs && \
76
120
echo '/root/packages/' > /root/packages/repositories && \
0 commit comments