-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
39 lines (30 loc) · 1.22 KB
/
Dockerfile
File metadata and controls
39 lines (30 loc) · 1.22 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
FROM --platform=$BUILDPLATFORM rust:slim AS builder
# 1. Install Docker cross-compilation helpers (xx)
COPY --from=tonistiigi/xx:master / /
WORKDIR /usr/src/app
# 2. Install C compiler and libraries for the target platform ($TARGETPLATFORM)
ARG TARGETPLATFORM
RUN apt-get update && \
apt-get install -y clang lld && \
xx-apt-get install -y gcc g++ libc6-dev
COPY Cargo.toml ./
RUN mkdir src
COPY src ./src
# 3. Perform cross-compilation
RUN --mount=type=cache,target=/usr/local/cargo/git/db \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/src/app/target \
xx-cargo build --release --target-dir ./target && \
# Move the binary to a common location (/bin) as the build path varies by architecture
cp ./target/$(xx-cargo --print-target-triple)/release/rustuya-bridge /bin/rustuya-bridge
# [Stage 2: Runtime]
# The runtime image matches the target architecture (implicit default).
FROM debian:trixie-slim
WORKDIR /app
# Copy the binary from the builder stage
COPY --from=builder /bin/rustuya-bridge /app/rustuya-bridge
ENV MQTT_BROKER="mqtt://localhost:1883"
ENV STATE_FILE="/data/rustuya.json"
ENV CONFIG="/data/config.json"
RUN mkdir /data
ENTRYPOINT ["/app/rustuya-bridge"]