-
-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathDockerfile
More file actions
96 lines (70 loc) · 2.42 KB
/
Dockerfile
File metadata and controls
96 lines (70 loc) · 2.42 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
87
88
89
90
91
92
93
94
95
96
# Stage 1: Build the React frontend
FROM node:22-alpine AS console-frontend-builder
# Set working directory for the frontend
WORKDIR /build/console
# Copy frontend package files
COPY console/package*.json ./
# Install dependencies with retry settings for network resilience
RUN npm config set fetch-retries 5 && \
npm config set fetch-retry-mintimeout 20000 && \
npm config set fetch-retry-maxtimeout 120000 && \
npm ci
# Copy frontend source code
COPY console/ ./
# Build frontend in production mode
RUN npm run build
# Stage 2: Build the notification center frontend
FROM node:22-alpine AS notification-center-builder
# Set working directory for the notification center
WORKDIR /build/notification_center
# Copy notification center package files
COPY notification_center/package*.json ./
# Install dependencies with retry settings for network resilience
RUN npm config set fetch-retries 5 && \
npm config set fetch-retry-mintimeout 20000 && \
npm config set fetch-retry-maxtimeout 120000 && \
npm ci
# Copy notification center source code
COPY notification_center/ ./
# Build notification center in production mode
RUN npm run build
# Stage 3: Build the Go binary (pure Go, no CGO needed)
FROM golang:1.25-alpine AS backend-builder
# Set working directory
WORKDIR /build
# Install build dependencies
RUN apk add --no-cache git
# Copy go.mod and go.sum files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy the source code
COPY cmd/ cmd/
COPY config/ config/
COPY internal/ internal/
COPY pkg/ pkg/
# Build the application with CGO disabled (pure Go)
ENV CGO_ENABLED=0
ENV GOOS=linux
RUN go build -ldflags="-s -w" -o /tmp/server ./cmd/api
# Stage 4: Create the runtime container (Alpine for smaller image)
FROM alpine:3.19
# Add necessary runtime packages
RUN apk add --no-cache \
ca-certificates \
tzdata \
postgresql-client
# Create application directory structure
WORKDIR /app
RUN mkdir -p /app/console/dist /app/notification_center/dist /app/data
# Copy the binary from the builder stage
COPY --from=backend-builder /tmp/server /app/server
# Copy the built console files
COPY --from=console-frontend-builder /build/console/dist/ /app/console/dist/
# Copy the built notification center files
COPY --from=notification-center-builder /build/notification_center/dist/ /app/notification_center/dist/
# Expose the application ports
EXPOSE 8080
EXPOSE 587
# Run the application
CMD ["/app/server"]