-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
81 lines (65 loc) · 2.82 KB
/
Dockerfile
File metadata and controls
81 lines (65 loc) · 2.82 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
# Dockerfile for rJMX-Exporter
# Multi-stage build for minimal production image
#
# Build: docker build -t rjmx-exporter .
# Run: docker run -v ./config.yaml:/config.yaml rjmx-exporter
# =============================================================================
# Stage 1: Build
# =============================================================================
FROM rust:1.83-alpine AS builder
# Install build dependencies
RUN apk add --no-cache \
musl-dev \
openssl-dev \
openssl-libs-static \
pkgconfig
# Create app directory
WORKDIR /app
# Copy manifests first for better layer caching
COPY Cargo.toml Cargo.lock ./
# Create dummy src and benches to build dependencies
# (Cargo.toml references [[bench]] entries that must exist for manifest parsing)
RUN mkdir -p src benches && \
echo 'fn main() { println!("Dummy"); }' > src/main.rs && \
echo '' > src/lib.rs && \
echo 'fn main() {}' > benches/collector_bench.rs && \
echo 'fn main() {}' > benches/memory_bench.rs && \
echo 'fn main() {}' > benches/startup_bench.rs && \
echo 'fn main() {}' > benches/scrape_latency_bench.rs
# Build dependencies (this layer is cached)
RUN cargo build --release --target x86_64-unknown-linux-musl && \
rm -rf src benches && \
rm -rf target/x86_64-unknown-linux-musl/release/deps/rjmx* && \
rm -rf target/x86_64-unknown-linux-musl/release/deps/librjmx* && \
rm -rf target/x86_64-unknown-linux-musl/release/.fingerprint/rjmx*
# Copy actual source code
COPY src ./src
COPY benches ./benches
# Build the actual binary (touch files to ensure cache invalidation)
RUN touch src/lib.rs src/main.rs && \
cargo build --release --target x86_64-unknown-linux-musl && \
strip target/x86_64-unknown-linux-musl/release/rjmx-exporter
# =============================================================================
# Stage 2: Runtime
# =============================================================================
FROM alpine:3.19
# Labels
LABEL org.opencontainers.image.title="rJMX-Exporter"
LABEL org.opencontainers.image.description="High-performance JMX metrics exporter written in Rust"
LABEL org.opencontainers.image.source="https://github.com/jsoonworld/rJMX-Exporter"
LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0"
# Install runtime dependencies (CA certificates for HTTPS)
RUN apk add --no-cache ca-certificates tzdata && \
adduser -D -H -s /sbin/nologin rjmx
# Copy binary from builder
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/rjmx-exporter /usr/local/bin/
# Use non-root user
USER rjmx
# Expose metrics port
EXPOSE 9090
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:9090/health || exit 1
# Default entrypoint
ENTRYPOINT ["/usr/local/bin/rjmx-exporter"]
CMD ["-c", "/config.yaml"]