-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
82 lines (68 loc) · 2.75 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
###########################
# Stage 1 : Backend build #
###########################
# Set up an environnement to cross-compile the app for musl to create a statically-linked binary
FROM --platform=$BUILDPLATFORM rust:1.84 AS backend-builder
ARG TARGETPLATFORM
RUN case "$TARGETPLATFORM" in \
"linux/amd64") echo x86_64-unknown-linux-gnu > /rust_target.txt ;; \
"linux/arm64") echo aarch64-unknown-linux-gnu > /rust_target.txt ;; \
"linux/arm/v7") echo armv7-unknown-linux-gnueabihf > /rust_target.txt ;; \
"linux/arm/v6") echo arm-unknown-linux-musleabihf > /rust_target.txt ;; \
*) exit 1 ;; \
esac
RUN rustup target add $(cat /rust_target.txt)
RUN apt update && apt install -y binutils-arm-linux-gnueabihf gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf libcap2-bin musl-dev musl-tools
RUN ln -s /usr/bin/arm-linux-gnueabihf-gcc /usr/bin/arm-linux-musleabihf-gcc
RUN ln -s /usr/bin/aarch64-linux-gnu-gcc /usr/bin/aarch64-linux-musl-gcc
# Create appuser
ENV USER=appuser
ENV UID=1000
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
WORKDIR /build
COPY ./backend/.cargo ./.cargo
COPY ./backend/Cargo.toml ./
COPY ./backend/src ./src
COPY ./backend/tests ./tests
#RUN cargo test --release --target $(cat /rust_target.txt)
RUN cargo build --profile release_optimized --target $(cat /rust_target.txt)
RUN cp target/$(cat /rust_target.txt)/release_optimized/atrium .
RUN chown -f "${UID}":"${UID}" ./atrium
# Allow running on ports < 1000
RUN setcap cap_net_bind_service=+ep ./atrium
RUN mkdir -p /myapp/app
COPY ./backend/atrium.yaml /myapp/app
COPY ./backend/web/onlyoffice/ /myapp/app/web/onlyoffice/
COPY ./backend/web/oauth2/ /myapp/app/web/oauth2/
RUN chown -Rf "${UID}":"${UID}" /myapp
############################
# Stage 2 : Frontend build #
############################
FROM --platform=$BUILDPLATFORM ghcr.io/cirruslabs/flutter:3.27.2 AS frontend-builder
WORKDIR /build
COPY ./frontend .
RUN flutter pub get
RUN flutter build web
#########################
# Stage 3 : Final image #
#########################
FROM --platform=linux/amd64 gcr.io/distroless/cc-debian12 AS base-amd64
FROM --platform=linux/arm64 gcr.io/distroless/cc-debian12 AS base-arm64
FROM --platform=linux/arm/v7 gcr.io/distroless/cc-debian12 AS base-armv7
FROM --platform=linux/arm/v6 scratch AS base-armv6
FROM base-${TARGETARCH}${TARGETVARIANT}
COPY --from=backend-builder /etc/passwd /etc/passwd
COPY --from=backend-builder /etc/group /etc/group
COPY --from=backend-builder /myapp /
WORKDIR /app
COPY --from=backend-builder /build/atrium ./
COPY --chown=appuser:appuser --from=frontend-builder /build/build/web/ /app/web/
USER appuser:appuser
ENTRYPOINT ["./atrium"]