-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (46 loc) · 1.72 KB
/
Dockerfile
File metadata and controls
63 lines (46 loc) · 1.72 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
# Multi-stage build for smaller final image
FROM registry.access.redhat.com/ubi9/go-toolset:latest AS builder
# Set working directory
WORKDIR /opt/app-root/src
# Copy go mod files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY . .
# Build the application binaries
# Main scheduler binary (supports: server, api, worker, db_migration subcommands)
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o scheduler cmd/server/main.go
# Kafka producer utility
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o kafka-producer cmd/kafka-producer/main.go
# Final stage - minimal runtime image
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest
# Install ca-certificates for HTTPS calls
RUN microdnf update -y && \
microdnf install -y ca-certificates sqlite && \
microdnf clean all
# Create non-root user
RUN groupadd -r scheduler && useradd -r -g scheduler -u 1001 scheduler
# Create data directory
RUN mkdir -p /data && chown scheduler:scheduler /data
# Set working directory
WORKDIR /app
# Copy binaries from builder stage
COPY --from=builder /opt/app-root/src/scheduler .
COPY --from=builder /opt/app-root/src/kafka-producer .
COPY --from=builder /opt/app-root/src/trigger_swatch_report_gen.sh .
COPY --from=builder /opt/app-root/src/db/migrations db/migrations/
# Change ownership of the binaries
RUN chown scheduler:scheduler scheduler kafka-producer
# Switch to non-root user
USER 1001
# Expose port
EXPOSE 5000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:5000/api/v1/jobs || exit 1
# Set environment variables
ENV DB_PATH=/data/jobs.db
ENV PORT=5000
# Run the application
CMD ["./scheduler"]