Files
2026-08-17 13:19:15 +08:00

42 lines
1.4 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ============================================================
# 统一构建:uni-app H5 前端 + Go 后端
# 构建上下文必须为仓库根目录(docker build -f server/Dockerfile .
# ============================================================
# ---------- 前端:uni-app H5 构建 ----------
FROM node:20-alpine AS web-builder
WORKDIR /web
COPY app-uni/package.json app-uni/package-lock.json ./
RUN npm ci --registry=https://registry.npmmirror.com
COPY app-uni/ .
RUN npm run build:h5
# ---------- 后端:Go 编译 ----------
FROM golang:alpine AS builder
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk add --no-cache git ca-certificates tzdata
ENV TZ=Asia/Shanghai
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn,direct
ENV CGO_ENABLED=0
ENV GOTOOLCHAIN=auto
WORKDIR /build
COPY server/go.mod server/go.sum ./
RUN go mod download
COPY server/ .
RUN go build -ldflags="-s -w" -o main ./main.go
# ---------- 运行时 ----------
FROM alpine:3.19
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk add --no-cache ca-certificates tzdata libstdc++ libgcc
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR /app
COPY --from=web-builder /web/dist/build/h5 ./web
COPY --from=builder /build/config.yml .
COPY --from=builder /build/main .
RUN mkdir -p /app/workspace /app/data
EXPOSE 8080
ENTRYPOINT ["./main"]