-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.multiarch
More file actions
72 lines (54 loc) · 1.88 KB
/
Dockerfile.multiarch
File metadata and controls
72 lines (54 loc) · 1.88 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
# Multi-architecture Dockerfile for Guardian Agent (Rust)
# Supports: linux/amd64, linux/arm64, linux/arm/v7
# Build stage
FROM --platform=$BUILDPLATFORM rust:1.75-slim AS builder
ARG TARGETPLATFORM
ARG BUILDPLATFORM
# Install build dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Install cross-compilation toolchain if needed
RUN case ${TARGETPLATFORM} in \
"linux/amd64") rustup target add x86_64-unknown-linux-gnu ;; \
"linux/arm64") rustup target add aarch64-unknown-linux-gnu && \
apt-get update && apt-get install -y gcc-aarch64-linux-gnu ;; \
"linux/arm/v7") rustup target add armv7-unknown-linux-gnueabihf && \
apt-get update && apt-get install -y gcc-arm-linux-gnueabihf ;; \
esac
WORKDIR /app
# Copy manifests
COPY Cargo.toml Cargo.lock ./
# Copy source
COPY src ./src
COPY build.rs ./
# Determine target architecture
RUN case ${TARGETPLATFORM} in \
"linux/amd64") TARGET=x86_64-unknown-linux-gnu ;; \
"linux/arm64") TARGET=aarch64-unknown-linux-gnu ;; \
"linux/arm/v7") TARGET=armv7-unknown-linux-gnueabihf ;; \
*) TARGET=x86_64-unknown-linux-gnu ;; \
esac && \
cargo build --release --target $TARGET --features server
# Runtime stage
FROM --platform=$TARGETPLATFORM debian:bookworm-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy binary from builder (architecture-specific)
COPY --from=builder /app/target/*/release/guardian /usr/local/bin/guardian
# Create log directory
RUN mkdir -p /var/lib/guardian
# Use non-root user
RUN useradd -r -u 1000 guardian && \
chown -R guardian:guardian /app /var/lib/guardian
USER guardian
# Expose port
EXPOSE 8080
# Run server
CMD ["guardian"]