-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
86 lines (61 loc) · 1.82 KB
/
Copy pathDockerfile
File metadata and controls
86 lines (61 loc) · 1.82 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Multi-stage Dockerfile for Analyzer Gateway
# Image: gemx-analyzer:latest
# Stage 1: Build frontend
FROM node:22-alpine AS frontend-builder
WORKDIR /app/frontend
# Copy package files
COPY frontend/package*.json ./
# Install dependencies (including dev dependencies for build)
RUN npm ci --no-fund --no-audit --loglevel=error
# Copy frontend source
COPY frontend/ ./
# Build frontend
RUN npm run build:static
# Stage 2: Build Go backend
FROM golang:1.25-alpine AS backend-builder
# Install build dependencies
RUN apk add --no-cache git ca-certificates tzdata
WORKDIR /app
# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Download dependencies
RUN go mod tidy
# Build the gateway binary
RUN CGO_ENABLED=0 GOOS=linux go build \
-trimpath \
-ldflags="-s -w -X main.version=dev" \
-o dist/analyzer_linux_amd64 \
./cmd
# Stage 3: Final runtime image
FROM alpine:3.19
# Install runtime dependencies
RUN apk add --no-cache \
ca-certificates \
tzdata \
curl \
&& rm -rf /var/cache/apk/*
# Create non-root user
RUN addgroup -g 1001 analyzer && \
adduser -D -u 1001 -G analyzer analyzer
# Create app directory
WORKDIR /app
# Copy binary from builder
COPY --from=backend-builder /app/dist/analyzer_linux_amd64 .
# Copy frontend assets from builder
COPY --from=frontend-builder /app/frontend/dist ./frontend/dist
# Copy configuration files
COPY config/ ./config/
# Set ownership
RUN chown -R analyzer:analyzer /app
# Switch to non-root user
USER analyzer
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/v1/health || exit 1
# Set entrypoint
ENTRYPOINT ["bash", "./dist/analyzer_linux_amd64", "gateway", "serve", "--config", "./config/config.example.yml", "&", "bash"]