Files
ushare/Dockerfile
loveuer 90093f79c9
Some checks failed
/ build ushare (push) Failing after 2m53s
/ clean (push) Successful in 3s
fix: copy frontend dist into backend-builder for go:embed
The backend Go build embeds the frontend via //go:embed frontend/dist
in internal/static/static.go. The Dockerfile was missing a
COPY --from=frontend-builder step to place the built dist at the
expected path before running go build, causing the build to fail.

🤖 Generated with [Qoder][https://qoder.com]
2026-02-27 19:49:50 -08:00

39 lines
1.1 KiB
Docker

# 第一阶段:构建前端
FROM node:20-alpine AS frontend-builder
RUN npm install -g pnpm --registry=https://registry.npmmirror.com
COPY frontend /app/frontend
WORKDIR /app/frontend
RUN pnpm install --registry=https://registry.npmmirror.com
RUN pnpm run build
# 第二阶段:构建 Golang 后端
FROM golang:alpine AS backend-builder
WORKDIR /app
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOPROXY=https://goproxy.cn
COPY go.mod /app/go.mod
COPY go.sum /app/go.sum
RUN go mod download
COPY main.go /app/main.go
COPY internal /app/internal
# 将前端构建产物复制到 go:embed 所需的路径
COPY --from=frontend-builder /app/frontend/dist /app/internal/static/frontend/dist
RUN go build -ldflags '-s -w' -o ushare .
# 第三阶段:生成最终镜像
FROM nginx:alpine
COPY --from=frontend-builder /app/frontend/dist /usr/share/nginx/html
COPY --from=backend-builder /app/ushare /usr/local/bin/ushare
# 配置 Nginx
COPY deployment/nginx.conf /etc/nginx/nginx.conf
COPY deployment/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
# 开放端口
EXPOSE 80
# 启动服务
ENTRYPOINT ["entrypoint.sh"]