-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.china
More file actions
75 lines (51 loc) · 1.69 KB
/
Dockerfile.china
File metadata and controls
75 lines (51 loc) · 1.69 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
# Build stage for frontend
FROM node:18-alpine AS frontend-builder
# 设置阿里云Alpine镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
WORKDIR /app/frontend
COPY frontend/package*.json ./
# 设置npm淘宝镜像源
RUN npm config set registry https://registry.npmmirror.com
RUN npm install
COPY frontend/ ./
RUN npm run build
# Build stage for backend
FROM golang:1.23-alpine AS backend-builder
# 设置阿里云Alpine镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# Install build dependencies
RUN apk add --no-cache git gcc musl-dev
WORKDIR /app
# 设置Go模块代理为中国镜像
ENV GOPROXY=https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn
ENV GO111MODULE=on
# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build the application
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o main cmd/server/main.go
# Production stage
FROM alpine:latest
# 设置阿里云Alpine镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# Install runtime dependencies
RUN apk --no-cache add ca-certificates tzdata
# 设置时区为中国
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
WORKDIR /root/
# Copy the binary from builder
COPY --from=backend-builder /app/main .
# Copy the frontend build from frontend-builder
COPY --from=frontend-builder /app/web/admin ./web/admin
# Copy migrations directory
COPY --from=backend-builder /app/migrations ./migrations
# Create uploads directory
RUN mkdir -p uploads
# Expose port
EXPOSE 8080
# Run the application
CMD ["./main"]