-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
65 lines (47 loc) · 1.49 KB
/
Dockerfile
File metadata and controls
65 lines (47 loc) · 1.49 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
# Multi-stage Dockerfile for QuasarFlow API
# Production-ready with security best practices
# ================================
# STAGE 1 - Build
# ================================
FROM golang:1.21-alpine AS builder
# Install build dependencies
RUN apk add --no-cache git ca-certificates tzdata
# Create non-root user for build
RUN adduser -D -s /bin/sh -u 10001 appuser
WORKDIR /app
# Copy go mod files first for better caching
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download && go mod verify
# Copy source code
COPY . .
# Build the application with optimizations
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -a -installsuffix cgo \
-ldflags='-w -s -extldflags "-static"' \
-o quasarflow-api ./cmd/api
# ================================
# STAGE 2 - Runtime
# ================================
FROM alpine:3.19 AS final
# Install runtime dependencies
RUN apk --no-cache add ca-certificates tzdata curl && \
update-ca-certificates
# Create non-root user
RUN adduser -D -s /bin/sh -u 10001 appuser
# Create app directory
WORKDIR /app
# Copy binary from builder stage
COPY --from=builder /app/quasarflow-api .
COPY --from=builder /app/migrations ./migrations
# Set proper ownership
RUN chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8080
# Add health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Run the application
CMD ["./quasarflow-api"]