dsec-discord-bot/Dockerfile
Clupai8o0 5751be129d OPS-04: restart on crash, real logging, and a deploy that fails when the bot does
- docker-compose.yml: `restart: unless-stopped` so a panic, bad frame or VPS
  reboot brings the bot back instead of leaving it dead. Comment explaining why
  no healthcheck (slim runtime, no HTTP port).
- Cargo.toml: enable tracing-subscriber's env-filter feature (declared but never
  initialised until now).
- main.rs: initialise tracing as the first statement in main(), defaulting to
  `info` — serenity/poise/supabase logs now surface, without leaking student IDs
  or the service email that the Supabase client emits at `debug`.
- deploy.yml: after `up -d`, assert the container is actually Running 30s later
  and dump its logs and fail if not — `up -d` returns 0 on container creation,
  not on a working process.
- Dockerfile: pin the builder to rust:1-bookworm to match the bookworm-slim
  runtime, removing the trixie/bookworm glibc mismatch.
- README: document the info-level default and the RUST_LOG=debug PII footgun.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017XrE7F9ZuBWdQnS8CZvYDE
2026-08-30 15:42:48 +10:00

60 lines
No EOL
1.8 KiB
Docker

# Pin the builder to the same Debian release as the runtime (bookworm). A binary
# built on a newer release can die at exec on the older one the day a dependency
# reaches for a newer glibc/OpenSSL symbol — with no log and, before OPS-04, no
# restart. Keep this in lockstep with the runtime FROM below.
FROM rust:1-bookworm AS builder
# Install build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /usr/src/dsec_bot
# Copy manifest files first to leverage Docker layer caching for dependencies
COPY Cargo.toml Cargo.lock ./
# Create a dummy project structure to cache dependency compilation
RUN mkdir src && \
echo 'fn main() { println!("Dummy main for dependency caching"); }' > src/main.rs
# Build dependencies (this layer will be cached unless Cargo.toml/Cargo.lock changes)
RUN cargo build --locked --release && \
rm -rf src target/release/deps/dsec_bot*
# Copy the actual source code
COPY src ./src
# Build the actual application
RUN cargo build --locked --release
# Runtime stage - use a minimal image
FROM debian:bookworm-slim
# Create a non-root user for security
RUN groupadd -r dsecbot && useradd --no-log-init -r -g dsecbot dsecbot
# Install runtime dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
&& rm -rf /var/lib/apt/lists/* \
&& update-ca-certificates
# Set the working directory
WORKDIR /app
# Copy the application binary from the builder stage
COPY --from=builder /usr/src/dsec_bot/target/release/dsec_bot ./dsec_bot
# Change ownership of the application to the non-root user
RUN chown dsecbot:dsecbot /app/dsec_bot && \
chmod +x /app/dsec_bot
# Switch to non-root user
USER dsecbot
# Specify the command to run the application
CMD ["./dsec_bot"]