-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
33 lines (31 loc) · 983 Bytes
/
Dockerfile
File metadata and controls
33 lines (31 loc) · 983 Bytes
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
# --- 第一阶段:构建前端 ---
FROM node:22-slim AS frontend-builder
WORKDIR /app/web
# 开启 pnpm 支持
RUN corepack enable
COPY web/package.json web/pnpm-lock.yaml ./
RUN pnpm install
COPY web/ .
RUN pnpm build
# --- 第二阶段:构建后端 ---
FROM golang:1.25-alpine AS backend-builder
WORKDIR /app
# 安装构建必要的工具
RUN apk add --no-cache gcc musl-dev
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# 将第一阶段生成的静态文件拷贝过来供 Go 嵌入
COPY --from=frontend-builder /app/web/build ./web/build
# 编译单体文件
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o website-pb ./cmd/web/main.go
# --- 第三阶段:运行环境 ---
FROM alpine:latest
RUN apk add --no-cache ca-certificates tzdata
WORKDIR /app
# 从构建阶段拷贝二进制文件
COPY --from=backend-builder /app/website-pb .
# 暴露 PocketBase 默认端口
EXPOSE 8090
# 启动命令
ENTRYPOINT ["./website-pb", "serve", "--http=0.0.0.0:8090"]