-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
63 lines (46 loc) · 1.24 KB
/
Dockerfile
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
# Stage 1: Build the frontend
FROM node:18-alpine as frontend-build
WORKDIR /app/frontend
# Install build dependencies
RUN apk add --no-cache python3 make g++
# Copy frontend files
COPY frontend/package*.json ./
RUN npm install --legacy-peer-deps
# Copy frontend source
COPY frontend/ .
# Build frontend with proper public path
ENV NODE_ENV=production
ENV PUBLIC_URL=/
RUN npm run build
# Stage 2: Build the backend
FROM golang:1.22-alpine as backend-build
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache git
# Copy go mod files first
COPY go.mod go.sum ./
# Update and download dependencies
RUN go mod download && \
go mod verify
# Copy backend source
COPY . .
# Copy frontend build to static directory
COPY --from=frontend-build /app/frontend/dist ./static
# Update modules and build
RUN go mod tidy && \
CGO_ENABLED=0 GOOS=linux go build -o main .
# Stage 3: Final image
FROM alpine:latest
WORKDIR /app
# Install runtime dependencies
RUN apk add --no-cache ca-certificates
# Copy built assets and binary
COPY --from=frontend-build /app/frontend/dist ./static
COPY --from=backend-build /app/main .
# Set production environment
ENV NODE_ENV=production
ENV PORT=8080
# Expose port
EXPOSE 8080
# Start application
CMD ["./main"]