-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
90 lines (70 loc) · 3.68 KB
/
Dockerfile
File metadata and controls
90 lines (70 loc) · 3.68 KB
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
# Multi-stage build: Frontend build stage
FROM node:20-bookworm AS frontend-build
WORKDIR /moor-frontend
COPY /vendor/moor/package.json /vendor/moor/package-lock.json* ./
RUN npm ci
COPY /vendor/moor/web-client/ ./web-client/
COPY /vendor/moor/tsconfig.json /vendor/moor/vite.config.ts ./
RUN npm run build
# Backend build stage
FROM rust:1.88-bookworm AS backend-build
WORKDIR /moor-build
RUN apt update
RUN apt -y install clang-16 libclang-16-dev swig python3-dev cmake libc6 git
# Generate the keypair for signing PASETO tokens. Shared between hosts and the daemon.
RUN openssl genpkey -algorithm ed25519 -out moor-signing-key.pem
RUN openssl pkey -in moor-signing-key.pem -pubout -out moor-verifying-key.pem
# Stuff we'll need from the host to make the build work
COPY ./vendor/moor/crates ./crates
COPY ./vendor/moor/tools ./tools
COPY ./vendor/moor/Cargo.toml ./Cargo.toml
COPY ./vendor/moor/Cargo.lock ./Cargo.lock
COPY ./vcs-worker ./crates/vcs-worker
# Need to add vcs-worker to the members to be compiled
RUN sed -i 's/members = \[/members = [\"crates\/vcs-worker\", /' ./Cargo.toml
RUN sed -i 's/default-members = \[/default-members = [\"crates\/vcs-worker\", /' ./Cargo.toml
# Replace vendor/moor paths with ../ paths in vcs-worker Cargo.toml
RUN sed -i 's|../vendor/moor/crates/|../|g' ./crates/vcs-worker/Cargo.toml
# We bring this over so we can get the git hash via shadow-rs. A bit bloated, but oh well.
COPY ./vendor/moor/.git ./.git
# Build configuration: Use ARG to allow build-time customization
ARG BUILD_PROFILE=debug
ARG CARGO_BUILD_FLAGS=""
# Build flags here if you want optimal performance for your *particular* CPU,
# at the expense of portability.
# ENV RUSTFLAGS="-C target-cpu=native"
# Build either debug (fast) or release (optimized) based on BUILD_PROFILE
RUN if [ "$BUILD_PROFILE" = "release" ]; then \
CARGO_PROFILE_RELEASE_DEBUG=true cargo build --release $CARGO_BUILD_FLAGS; \
else \
cargo build $CARGO_BUILD_FLAGS; \
fi
# But we don't need the source code and all the rust stuff and packages in our final image. Just slim.
FROM linuxcontainers/debian-slim:latest AS backend
# Pass the build profile to the final stage
ARG BUILD_PROFILE=debug
# We need libssl for the curl worker and git for VCS backups
RUN apt update
RUN apt -y install libssl3 git
WORKDIR /moor
# The keys for signing and verifying PASETO tokens, we built them in the backend build image
COPY --from=backend-build ./moor-build/moor-signing-key.pem ./moor-signing-key.pem
COPY --from=backend-build ./moor-build/moor-verifying-key.pem ./moor-verifying-key.pem
# The compiled service binaries from the backend build (debug or release depending on BUILD_PROFILE)
COPY --from=backend-build /moor-build/target/${BUILD_PROFILE}/moor-daemon /moor/moor-daemon
COPY --from=backend-build /moor-build/target/${BUILD_PROFILE}/moor-web-host /moor/moor-web-host
COPY --from=backend-build /moor-build/target/${BUILD_PROFILE}/moor-telnet-host /moor/moor-telnet-host
COPY --from=backend-build /moor-build/target/${BUILD_PROFILE}/moor-curl-worker /moor/moor-curl-worker
COPY --from=backend-build /moor-build/target/${BUILD_PROFILE}/moor-vcs-worker /moor/moor-vcs-worker
# The built web client static files from the frontend build
COPY --from=frontend-build /moor-frontend/dist /moor/web-client
# `moorc` binary can be used to compile objdef or textdump sources without running a full daemon
COPY --from=backend-build /moor-build/target/${BUILD_PROFILE}/moorc /moor/moorc
EXPOSE 8080
# nginx-based frontend image
FROM nginx:alpine AS frontend
COPY --from=frontend-build /moor-frontend/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
# Default stage - backend services with moor binaries
FROM backend AS default