feat(docker): Dockerfiles agents multi-arch (amd64, arm64, armv7)
- Build en 2 étapes : rust:1.82-alpine → alpine:3.21 - Mapping automatique TARGETPLATFORM → target musl Rust - Cache couche dépendances Cargo (builds incrémentaux rapides) - agent-scan-network : inclut iputils (ping) - agent-metric : inclut smartmontools (SMART), requiert --privileged pour /sys Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
# Build multi-arch : docker buildx build --platform linux/amd64,linux/arm64 .
|
||||||
|
# Note : agent-metric nécessite accès /sys et /proc — lancer avec --privileged
|
||||||
|
FROM --platform=$BUILDPLATFORM rust:1.82-alpine AS builder
|
||||||
|
|
||||||
|
ARG TARGETPLATFORM
|
||||||
|
|
||||||
|
RUN apk add --no-cache musl-dev
|
||||||
|
|
||||||
|
RUN case "$TARGETPLATFORM" in \
|
||||||
|
"linux/amd64") echo "x86_64-unknown-linux-musl" > /rust_target ;; \
|
||||||
|
"linux/arm64") echo "aarch64-unknown-linux-musl" > /rust_target ;; \
|
||||||
|
"linux/arm/v7") echo "armv7-unknown-linux-musleabihf" > /rust_target ;; \
|
||||||
|
*) echo "x86_64-unknown-linux-musl" > /rust_target ;; \
|
||||||
|
esac
|
||||||
|
|
||||||
|
RUN rustup target add "$(cat /rust_target)"
|
||||||
|
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
COPY Cargo.toml ./
|
||||||
|
RUN mkdir src && echo 'fn main(){}' > src/main.rs
|
||||||
|
RUN cargo build --release --target "$(cat /rust_target)" 2>/dev/null || true
|
||||||
|
RUN rm -rf src
|
||||||
|
|
||||||
|
COPY src ./src
|
||||||
|
RUN cargo build --release --target "$(cat /rust_target)"
|
||||||
|
RUN cp "target/$(cat /rust_target)/release/agent-metric" /agent
|
||||||
|
|
||||||
|
FROM alpine:3.21
|
||||||
|
RUN apk add --no-cache ca-certificates smartmontools
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=builder /agent ./agent-metric
|
||||||
|
EXPOSE 9101
|
||||||
|
VOLUME ["/app/config.yaml"]
|
||||||
|
# Accès /sys /proc /dev nécessaire pour les métriques — docker run --privileged
|
||||||
|
ENTRYPOINT ["./agent-metric", "/app/config.yaml"]
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# Build multi-arch : docker buildx build --platform linux/amd64,linux/arm64 .
|
||||||
|
FROM --platform=$BUILDPLATFORM rust:1.82-alpine AS builder
|
||||||
|
|
||||||
|
ARG TARGETPLATFORM
|
||||||
|
ARG BUILDPLATFORM
|
||||||
|
|
||||||
|
RUN apk add --no-cache musl-dev
|
||||||
|
|
||||||
|
# Mapping TARGETPLATFORM → cible Rust
|
||||||
|
RUN case "$TARGETPLATFORM" in \
|
||||||
|
"linux/amd64") echo "x86_64-unknown-linux-musl" > /rust_target ;; \
|
||||||
|
"linux/arm64") echo "aarch64-unknown-linux-musl" > /rust_target ;; \
|
||||||
|
"linux/arm/v7") echo "armv7-unknown-linux-musleabihf" > /rust_target ;; \
|
||||||
|
*) echo "x86_64-unknown-linux-musl" > /rust_target ;; \
|
||||||
|
esac
|
||||||
|
|
||||||
|
RUN rustup target add "$(cat /rust_target)"
|
||||||
|
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
# Cache des dépendances
|
||||||
|
COPY Cargo.toml ./
|
||||||
|
RUN mkdir src && echo 'fn main(){}' > src/main.rs
|
||||||
|
RUN cargo build --release --target "$(cat /rust_target)" 2>/dev/null || true
|
||||||
|
RUN rm -rf src
|
||||||
|
|
||||||
|
COPY src ./src
|
||||||
|
RUN cargo build --release --target "$(cat /rust_target)"
|
||||||
|
RUN cp "target/$(cat /rust_target)/release/agent-scan-network" /agent
|
||||||
|
|
||||||
|
# Image finale minimale
|
||||||
|
FROM alpine:3.21
|
||||||
|
RUN apk add --no-cache ca-certificates iputils
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=builder /agent ./agent-scan-network
|
||||||
|
EXPOSE 9100
|
||||||
|
VOLUME ["/app/config.yaml"]
|
||||||
|
ENTRYPOINT ["./agent-scan-network", "/app/config.yaml"]
|
||||||
Reference in New Issue
Block a user