-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile.aarch64-unknown-linux-musl
50 lines (37 loc) · 1.67 KB
/
Dockerfile.aarch64-unknown-linux-musl
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
# syntax=docker/dockerfile:1.2
FROM --platform=$BUILDPLATFORM rust:1.80-alpine3.20 as SERVER_BUILDER
## Statically link binary to OpenSSL libraries.
ENV OPENSSL_STATIC=yes
ENV OPENSSL_LIB_DIR=/usr/lib/
ENV OPENSSL_INCLUDE_DIR=/usr/include/
ENV PATH="$PATH:/app/aarch64-linux-musl-cross/bin"
WORKDIR /app
RUN set -x && apk add --no-cache pkgconfig musl-dev openssl-dev perl make curl ca-certificates
# Prepare environment: for cross compilation we download toolchain and `aarch64` OpenSSL libs.
RUN set -x && \
curl --remote-name-all https://musl.cc/aarch64-linux-musl-cross.tgz https://dl-cdn.alpinelinux.org/alpine/v3.19/main/aarch64/openssl-libs-static-3.3.1-r3.apk && \
apk add --allow-untrusted openssl-libs-static-3.3.1-r3.apk && \
tar xzf ./aarch64-linux-musl-cross.tgz && \
rustup target add aarch64-unknown-linux-musl
# Copy assets.
COPY ["./assets", "./assets"]
# Fetch dependencies if they change.
COPY ["./Cargo.lock", "./Cargo.toml", "./"]
RUN set -x && cargo fetch
COPY [".", "./"]
RUN --mount=type=cache,target=/app/target set -x && \
cargo build --release --target=aarch64-unknown-linux-musl --config target.aarch64-unknown-linux-musl.linker=\"aarch64-linux-musl-gcc\" && \
cp ./target/aarch64-unknown-linux-musl/release/secutils ./
FROM alpine:3.20
EXPOSE 7070
ENV APP_USER=secutils
ENV APP_USER_UID=1001
WORKDIR /app
COPY --from=SERVER_BUILDER ["/app/secutils", "./"]
COPY --from=SERVER_BUILDER ["/etc/ssl/certs/ca-certificates.crt", "/etc/ssl/certs/"]
# Configure group and user.
RUN addgroup -S -g $APP_USER_UID $APP_USER && \
adduser -S -u $APP_USER_UID -G $APP_USER $APP_USER
RUN chown -R $APP_USER:$APP_USER ./
USER $APP_USER
CMD [ "./secutils" ]