-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
105 lines (83 loc) · 3.66 KB
/
Dockerfile
File metadata and controls
105 lines (83 loc) · 3.66 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Build stage
# Note: Using 1.93+ for edition 2024 and time crate support (requires 1.88+)
FROM rust:1.93-slim AS builder
# Install required system dependencies for static linking
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config \
libssl-dev \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Set the working directory
WORKDIR /app
# Determine target architecture automatically
ARG TARGETARCH
ENV TARGET_TRIPLE=""
# Set target triple and install target
RUN case "$TARGETARCH" in \
"amd64") TARGET_TRIPLE="x86_64-unknown-linux-gnu" ;; \
"arm64") TARGET_TRIPLE="aarch64-unknown-linux-gnu" ;; \
*) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; \
esac && \
echo "Building for target: $TARGET_TRIPLE" && \
rustup target add $TARGET_TRIPLE && \
echo $TARGET_TRIPLE > /tmp/target_triple
# Copy dependency files first for better caching
COPY Cargo.toml Cargo.lock ./
# Create dummy source files to build dependencies
RUN mkdir src && \
echo "fn main() {}" > src/main.rs && \
echo "" > src/lib.rs
# Build dependencies (this will be cached unless Cargo.toml changes)
RUN TARGET_TRIPLE=$(cat /tmp/target_triple) && \
cargo build --release --target "$TARGET_TRIPLE"
RUN rm src/main.rs src/lib.rs
# Copy the actual source code
COPY src/ ./src/
# Copy static assets and templates
COPY static/ ./static/
COPY templates/ ./templates/
# Build the application with static linking
ENV RUSTFLAGS="-C target-feature=+crt-static"
RUN TARGET_TRIPLE=$(cat /tmp/target_triple) && \
cargo build --release --target "$TARGET_TRIPLE" && \
cp "target/$TARGET_TRIPLE/release/simple-docker-manager" /tmp/simple-docker-manager
# Runtime stage using scratch for minimal size
FROM scratch
# Build args for labels
ARG VERSION=0.1.0
ARG BUILD_DATE
ARG VCS_REF
# OCI Labels for better container registry UX
LABEL org.opencontainers.image.title="Simple Docker Manager"
LABEL org.opencontainers.image.description="A beautiful, lightweight Docker container management service with real-time metrics visualization"
LABEL org.opencontainers.image.version="${VERSION}"
LABEL org.opencontainers.image.authors="Simple Docker Manager Contributors"
LABEL org.opencontainers.image.url="https://github.com/OscillateLabsLLC/simple-docker-manager"
LABEL org.opencontainers.image.documentation="https://github.com/OscillateLabsLLC/simple-docker-manager#readme"
LABEL org.opencontainers.image.source="https://github.com/OscillateLabsLLC/simple-docker-manager"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.vendor="Simple Docker Manager"
LABEL org.opencontainers.image.created="${BUILD_DATE}"
LABEL org.opencontainers.image.revision="${VCS_REF}"
# Runtime labels
LABEL maintainer="Simple Docker Manager Contributors"
LABEL org.opencontainers.image.base.name="scratch"
# Copy CA certificates for HTTPS support
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Copy the statically compiled binary
COPY --from=builder /tmp/simple-docker-manager /usr/local/bin/simple-docker-manager
# Copy static assets and templates to the container
COPY --from=builder /app/static/ /app/static/
COPY --from=builder /app/templates/ /app/templates/
# Set the working directory for the application
WORKDIR /app
# Create a non-root user
# Note: For scratch images, we need to add the user in the final stage
# We use a high UID to avoid conflicts with host system users
USER 10001:10001
# Expose the default port
EXPOSE 3000
# Note: Health checks should be performed externally by hitting /health endpoint
# Example: curl -f http://localhost:3000/health
# Use the binary as the entrypoint
ENTRYPOINT ["/usr/local/bin/simple-docker-manager"]