-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (44 loc) · 1.12 KB
/
Dockerfile
File metadata and controls
63 lines (44 loc) · 1.12 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
# 多阶段构建
# 阶段1: 构建前端
FROM node:18-alpine AS frontend-builder
WORKDIR /app
# 复制前端依赖文件
COPY package*.json ./
COPY tsconfig*.json ./
COPY vite.config.ts ./
COPY tailwind.config.js ./
COPY postcss.config.js ./
# 安装前端依赖
RUN npm ci
# 复制前端源码
COPY frontend/ ./frontend/
# 构建前端
RUN npm run build
# 阶段2: 构建后端
FROM golang:1.21-alpine AS backend-builder
WORKDIR /app
# 安装必要的包
RUN apk add --no-cache git
# 复制Go模块文件
COPY go.mod go.sum ./
# 下载依赖
RUN go mod download
# 复制后端源码
COPY backend/ ./backend/
# 构建后端
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./backend/cmd
# 阶段3: 最终镜像
FROM alpine:latest
WORKDIR /app
# 安装必要的包
RUN apk --no-cache add ca-certificates tzdata zip unzip
# 设置时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' >/etc/timezone
# 从构建阶段复制文件
COPY --from=backend-builder /app/main .
COPY --from=frontend-builder /app/dist ./dist
# 暴露端口
EXPOSE 8080
# 运行应用
CMD ["./main"]