Repository navigation
Expand file tree
/
Copy pathDockerfile.rustms-server
More file actions
60 lines (50 loc) · 1.89 KB
/
Copy pathDockerfile.rustms-server
File metadata and controls
60 lines (50 loc) · 1.89 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
# syntax=docker/dockerfile:1.7
FROM rust:1.87-alpine AS builder
# The build cache for target/ must not be shared between checkouts: cargo
# trusts mtimes, so another checkout's newer artifacts would be reused for
# this one's sources. The harness sets this per compose project.
ARG TARGET_CACHE_ID=rustms-target
# Passed through from the host to cap the build's parallel jobs; empty
# leaves cargo's default.
ARG CARGO_BUILD_JOBS=
WORKDIR /app
RUN apk add --no-cache \
build-base \
musl-dev \
openssl-dev \
postgresql-dev \
pkgconf
ENV RUSTFLAGS="-C target-feature=-crt-static"
COPY Cargo.toml Cargo.lock ./
COPY config config
COPY crypt crypt
COPY db db
COPY game game
COPY game-data game-data
COPY integration-harness integration-harness
COPY net net
COPY packet packet
COPY runtime runtime
COPY rust-ms rust-ms
COPY tools tools
# Cargo decides whether a workspace crate is fresh by comparing source mtimes
# with the cached artifacts, and the cached target/ may hold artifacts built
# from other source states (other branches, stashes). Touch the sources so
# workspace crates always rebuild from what was just copied; dependencies
# stay cached.
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,id=${TARGET_CACHE_ID},target=/app/target \
find /app -path /app/target -prune -o -name '*.rs' -exec touch {} + \
&& cargo build ${CARGO_BUILD_JOBS:+-j $CARGO_BUILD_JOBS} -p rust-ms --bin login --bin world --release \
&& mkdir -p /out \
&& cp /app/target/release/login /out/login \
&& cp /app/target/release/world /out/world
FROM alpine:3.22
RUN apk add --no-cache ca-certificates libpq libgcc libstdc++ \
&& adduser -D rustms
WORKDIR /app
COPY --from=builder /out/login /usr/local/bin/login
COPY --from=builder /out/world /usr/local/bin/world
COPY --from=builder /app/config /app/config
USER rustms