- Create docker-compose.yml with server and agent services - Add environment variable support to Dockerfiles via entrypoint scripts - Configure server with ADDR, PORT, USERNAME, PASSWORD vars - Configure agent with SERVER, INTERVAL, AGENT_ID vars - Add health check to server service for container orchestration - Add service dependencies to ensure server starts before agent - Create .dockerignore to optimize Docker builds - Update QUICKSTART.md with Docker Compose instructions - Support running server only, agent only, or full stack - Support multiple agents with custom identifiers
46 lines
1.1 KiB
Docker
46 lines
1.1 KiB
Docker
# Multi-stage build for nerd-monitor agent
|
|
FROM golang:1.24.4-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Install build dependencies
|
|
RUN apk add --no-cache git make
|
|
|
|
# Copy go mod files
|
|
COPY go.mod go.sum ./
|
|
|
|
# Download dependencies
|
|
RUN go mod download
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the agent binary (no templ needed for agent)
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o nerd-monitor-agent ./cmd/agent
|
|
|
|
# Runtime stage
|
|
FROM alpine:latest
|
|
|
|
WORKDIR /app
|
|
|
|
COPY --from=builder /app/nerd-monitor-agent .
|
|
|
|
# Create non-root user
|
|
RUN addgroup -D appgroup && adduser -D appuser -G appgroup
|
|
USER appuser
|
|
|
|
# Create entrypoint script to handle environment variables
|
|
RUN echo '#!/bin/sh\n\
|
|
SERVER=${SERVER:-localhost:8080}\n\
|
|
INTERVAL=${INTERVAL:-15s}\n\
|
|
AGENT_ID=${AGENT_ID:-}\n\
|
|
if [ -z "$AGENT_ID" ]; then\n\
|
|
exec ./nerd-monitor-agent --server "$SERVER" --interval "$INTERVAL"\n\
|
|
else\n\
|
|
exec ./nerd-monitor-agent --server "$SERVER" --interval "$INTERVAL" --id "$AGENT_ID"\n\
|
|
fi\n\
|
|
' > /app/entrypoint.sh && chmod +x /app/entrypoint.sh
|
|
|
|
# Run the agent
|
|
ENTRYPOINT ["/app/entrypoint.sh"]
|