-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.server
More file actions
164 lines (133 loc) · 6.31 KB
/
Copy pathDockerfile.server
File metadata and controls
164 lines (133 loc) · 6.31 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# syntax=docker/dockerfile:1.7
ARG RUST_IMAGE=rust:bookworm@sha256:adab7941580c74513aa3347f2d2a1f975498280743d29ec62978ba12e3540d3a
ARG NODE_IMAGE=node:24-bookworm-slim@sha256:03eae3ef7e88a9de535496fb488d67e02b9d96a063a8967bae657744ecd513f2
ARG DEBIAN_IMAGE=debian:bookworm-slim@sha256:f9c6a2fd2ddbc23e336b6257a5245e31f996953ef06cd13a59fa0a1df2d5c252
ARG RUNTIME_IMAGE=gcr.io/distroless/cc-debian12:nonroot@sha256:e2d29aec8061843706b7e484c444f78fafb05bfe47745505252b1769a05d14f1
FROM ${RUST_IMAGE} AS chef
ARG USE_CN_MIRRORS=false
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
WORKDIR /app
RUN if [ "$USE_CN_MIRRORS" = "true" ]; then \
mkdir -p /usr/local/cargo && \
printf '[source.crates-io]\nreplace-with = "rsproxy-sparse"\n\n[source.rsproxy-sparse]\nregistry = "sparse+https://rsproxy.cn/index/"\n' \
> /usr/local/cargo/config.toml; \
fi
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
if [ "$USE_CN_MIRRORS" = "true" ]; then \
export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup \
RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup; \
fi && \
cargo install cargo-chef --version 0.1.73 --locked
COPY . .
RUN if [ "$USE_CN_MIRRORS" = "true" ]; then \
export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup \
RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup; \
fi && \
cargo chef prepare --recipe-path recipe.json
FROM ${RUST_IMAGE} AS rust-builder
ARG USE_CN_MIRRORS=false
ARG CARGO_BUILD_JOBS
ARG SERVER_FEATURES=""
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
ENV CARGO_BUILD_JOBS=${CARGO_BUILD_JOBS}
WORKDIR /app
RUN if [ "$USE_CN_MIRRORS" = "true" ]; then \
mkdir -p /usr/local/cargo && \
printf '[source.crates-io]\nreplace-with = "rsproxy-sparse"\n\n[source.rsproxy-sparse]\nregistry = "sparse+https://rsproxy.cn/index/"\n' \
> /usr/local/cargo/config.toml; \
fi
COPY --from=chef /usr/local/cargo/bin/cargo-chef /usr/local/cargo/bin/cargo-chef
COPY --from=chef /app/recipe.json recipe.json
COPY rust-toolchain.toml rust-toolchain.toml
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/app/target \
if [ "$USE_CN_MIRRORS" = "true" ]; then \
export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup \
RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup; \
fi && \
if [ -n "$SERVER_FEATURES" ]; then \
cargo chef cook --release --locked --recipe-path recipe.json --package server --features "$SERVER_FEATURES"; \
else \
cargo chef cook --release --locked --recipe-path recipe.json --package server; \
fi
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/app/target \
if [ "$USE_CN_MIRRORS" = "true" ]; then \
export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup \
RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup; \
fi && \
if [ -n "$SERVER_FEATURES" ]; then \
cargo build --release --locked --package server --features "$SERVER_FEATURES"; \
else \
cargo build --release --locked --package server; \
fi && \
mkdir -p /out && \
cp target/release/server /out/broccoli-server && \
strip /out/broccoli-server
FROM ${NODE_IMAGE} AS web-builder
ARG USE_CN_MIRRORS=false
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \
HUSKY=0
WORKDIR /app
RUN if [ "$USE_CN_MIRRORS" = "true" ]; then \
npm config set registry https://registry.npmmirror.com; \
fi && \
corepack enable
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig.base.json ./
COPY packages/web/package.json packages/web/package.json
COPY packages/web-sdk/package.json packages/web-sdk/package.json
RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store \
pnpm config set store-dir /pnpm/store && \
if [ "$USE_CN_MIRRORS" = "true" ]; then \
pnpm config set registry https://registry.npmmirror.com; \
fi && \
pnpm install --frozen-lockfile --ignore-scripts
COPY packages/web packages/web
COPY packages/web-sdk packages/web-sdk
RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store \
pnpm --filter @broccoli/web-sdk build && \
pnpm --filter @broccoli/web build && \
mkdir -p /out/dist && \
cp -a packages/web/build/client/. /out/dist/
FROM scratch AS plugin-stage
COPY plugins /out/plugins
FROM ${DEBIAN_IMAGE} AS tini-stage
ARG USE_CN_MIRRORS=false
RUN if [ "$USE_CN_MIRRORS" = "true" ]; then \
sed -i 's|deb.debian.org|mirrors.tuna.tsinghua.edu.cn|g; s|security.debian.org|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list.d/debian.sources; \
fi && \
apt-get update && \
apt-get install -y --no-install-recommends tini=0.19.0-1+b3 && \
rm -rf /var/lib/apt/lists/*
FROM ${RUNTIME_IMAGE} AS runtime
ARG CREATED=unknown
ARG REVISION=unknown
ARG SOURCE=https://github.com/THUSAAC-PSD/broccoli
ARG VERSION=dev
LABEL org.opencontainers.image.title="Broccoli Server" \
org.opencontainers.image.description="Broccoli online judge server with baked frontend assets" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.revision="${REVISION}" \
org.opencontainers.image.source="${SOURCE}" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.vendor="THUSAAC-PSD" \
org.opencontainers.image.documentation="https://github.com/THUSAAC-PSD/broccoli/blob/main/docs/build.md" \
org.opencontainers.image.created="${CREATED}"
COPY --from=rust-builder --chown=65532:65532 /out/broccoli-server /usr/local/bin/broccoli-server
COPY --from=web-builder --chown=65532:65532 /out/dist /srv/dist
COPY --from=plugin-stage --chown=65532:65532 /out/plugins /plugins
COPY --from=tini-stage --chown=65532:65532 /usr/bin/tini /usr/bin/tini
ENV BROCCOLI__PLUGIN__PLUGINS_DIR=/plugins \
BROCCOLI__SERVER__FRONTEND_DIST=/srv/dist \
BROCCOLI__SERVER__HOST=0.0.0.0 \
BROCCOLI__SERVER__PORT=3000 \
RUST_LOG=info
USER 65532:65532
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD ["/usr/local/bin/broccoli-server", "--healthcheck"]
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/broccoli-server"]