Files
nerd-monitor/Dockerfile.server
Ducky SSH User 98ecc61624 Add docker-compose support with environment variable configuration
- 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
2025-12-20 05:57:09 +00:00

57 lines
1.3 KiB
Docker

# Multi-stage build for nerd-monitor server
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 . .
# Generate templ templates
RUN go run github.com/a-h/templ/cmd/templ@latest generate
# Build the server binary
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o nerd-monitor-server ./cmd/server
# Runtime stage
FROM alpine:latest
WORKDIR /app
# Install ca-certificates for HTTPS
RUN apk add --no-cache ca-certificates
# Copy binary from builder
COPY --from=builder /app/nerd-monitor-server .
# Create non-root user
RUN addgroup -D appgroup && adduser -D appuser -G appgroup
USER appuser
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --quiet --tries=1 --spider http://localhost:8080/login || exit 1
# Create entrypoint script to handle environment variables
RUN echo '#!/bin/sh\n\
ADDR=${ADDR:-0.0.0.0}\n\
PORT=${PORT:-8080}\n\
USERNAME=${USERNAME:-admin}\n\
PASSWORD=${PASSWORD:-admin}\n\
exec ./nerd-monitor-server -addr "$ADDR" -port "$PORT" -username "$USERNAME" -password "$PASSWORD"\n\
' > /app/entrypoint.sh && chmod +x /app/entrypoint.sh
# Run the server
ENTRYPOINT ["/app/entrypoint.sh"]