Files
urldb/Dockerfile

61 lines
1.1 KiB
Docker
Raw Normal View History

2025-07-18 00:34:27 +08:00
# 前端构建阶段
2025-07-19 09:00:36 +08:00
FROM node:18-alpine AS frontend-builder
# 安装必要的构建工具Rust工具链
RUN apk add --no-cache --virtual .build-deps \
python3 \
make \
g++ \
&& npm config set python python3
2025-07-18 00:34:27 +08:00
# 安装pnpm
RUN npm install -g pnpm
2025-07-10 01:27:35 +08:00
WORKDIR /app/web
COPY web/package*.json ./
2025-07-18 00:34:27 +08:00
COPY web/pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
2025-07-10 01:27:35 +08:00
COPY web/ ./
2025-07-18 00:34:27 +08:00
RUN pnpm run build
# 前端运行阶段
FROM node:18-alpine AS frontend
RUN npm install -g pnpm
WORKDIR /app
COPY --from=frontend-builder /app/web/.output ./.output
COPY --from=frontend-builder /app/web/package*.json ./
EXPOSE 3000
2025-07-10 01:27:35 +08:00
2025-07-18 00:34:27 +08:00
CMD ["node", ".output/server/index.mjs"]
# 后端构建阶段
2025-07-10 01:27:35 +08:00
FROM golang:1.21-alpine AS backend-builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
2025-07-18 00:34:27 +08:00
# 后端运行阶段
FROM alpine:latest AS backend
2025-07-10 01:27:35 +08:00
RUN apk --no-cache add ca-certificates
WORKDIR /root/
# 复制后端二进制文件
COPY --from=backend-builder /app/main .
# 创建uploads目录
RUN mkdir -p uploads
# 暴露端口
EXPOSE 8080
# 运行应用
CMD ["./main"]