-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (52 loc) · 1.81 KB
/
Copy pathDockerfile
File metadata and controls
70 lines (52 loc) · 1.81 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
# ─────────────────────────────────────────────
# Baadal — Multi-stage Docker Build
# ─────────────────────────────────────────────
# Build stage
FROM golang:1.24-alpine AS builder
WORKDIR /build
# Install build dependencies
RUN apk add --no-cache git ca-certificates tzdata
# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download
RUN go mod verify
# Copy source code
COPY main.go ./
# Build binary
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags="-s -w -X main.version=docker" \
-a -installsuffix cgo \
-o baadal main.go
# Runtime stage
FROM alpine:latest
LABEL maintainer="Baadal Team"
LABEL description="Server Log Collector and Alerter"
# Install runtime dependencies
RUN apk --no-cache add \
ca-certificates \
tzdata \
docker-cli \
coreutils \
util-linux \
&& rm -rf /var/cache/apk/*
WORKDIR /app
# Copy binary from builder
COPY --from=builder /build/baadal /usr/local/bin/baadal
# Copy config template
COPY config.yml /app/config.yml.template
# Create non-root user
RUN addgroup -g 1000 baadal && \
adduser -D -u 1000 -G baadal baadal && \
mkdir -p /var/log/baadal && \
chown -R baadal:baadal /app /var/log/baadal
# Switch to non-root user (can be overridden for collector mode)
USER baadal
# Expose receiver port
EXPOSE 5170
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD [ "sh", "-c", "if [ \"$MODE\" = \"receiver\" ]; then wget --no-verbose --tries=1 --spider http://localhost:5170/health || exit 1; else exit 0; fi" ]
# Default to collector mode
ENV MODE=collector
ENTRYPOINT ["baadal"]
CMD ["--mode=${MODE}", "--config=/app/config.yml"]