-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
76 lines (56 loc) · 2.08 KB
/
Dockerfile
File metadata and controls
76 lines (56 loc) · 2.08 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
# Multi-stage build for optimal image size and security
FROM rust:1.83-slim-bullseye AS builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
liblmdb-dev \
&& rm -rf /var/lib/apt/lists/*
# Create app user for security
RUN useradd -m -u 1001 appuser
# Set working directory
WORKDIR /app
# Copy manifests first for better layer caching
COPY Cargo.toml Cargo.lock ./
# Create a dummy main.rs to build dependencies
RUN mkdir src && echo "fn main() {}" > src/main.rs
# Build dependencies (this layer will be cached unless Cargo files change)
RUN cargo build --release && rm -rf src target/release/deps/immortal*
# Copy source code
COPY src/ ./src/
# Build the application
RUN cargo build --release
# Runtime stage - use minimal base image
FROM debian:bullseye-slim AS runtime
# Install runtime dependencies only
RUN apt-get update && apt-get install -y \
liblmdb0 \
libssl1.1 \
ca-certificates \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Create app user (same UID as builder for consistency)
RUN useradd -m -u 1001 appuser
# Create working directory and data directory
WORKDIR /app
RUN mkdir -p /app/immo/database && chown -R appuser:appuser /app
# Copy the built binary from builder stage
COPY --from=builder /app/target/release/immortal /usr/local/bin/immortal
# Copy configuration file
COPY config.toml /app/config.toml
# Ensure binary is executable and owned by appuser
RUN chmod +x /usr/local/bin/immortal && chown appuser:appuser /usr/local/bin/immortal /app/config.toml
# Switch to non-root user
USER appuser
# Expose the default port (configurable via config.toml)
EXPOSE 7777
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7777/ || exit 1
# Use exec form for proper signal handling
ENTRYPOINT ["/usr/local/bin/immortal"]
# Add labels for better maintainability
LABEL maintainer="dezh-tech" \
version="0.1.0" \
description="Immortal Nostr Relay" \
org.opencontainers.image.source="https://github.com/dezh-tech/immortal"