diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..76add87 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7857604..7537b90 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,28 @@ # 第一阶段:构建前端 FROM node:20-alpine AS frontend-builder -WORKDIR /app -RUN npm install -g pnpm -COPY frontend/package.json frontend/pnpm-lock.yaml* ./ -RUN pnpm install -COPY frontend . +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 -COPY go.mod go.sum ./ +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 internal ./ -RUN CGO_ENABLED=0 GOOS=linux go build -o main . +COPY main.go /app/main.go +COPY internal /app/internal +RUN go build -ldflags '-s -w' -o ushare . # 第三阶段:生成最终镜像 FROM nginx:alpine -COPY --from=frontend-builder /app/dist /usr/share/nginx/html -COPY --from=backend-builder /app/main /app/main +COPY --from=frontend-builder /app/frontend/dist /usr/share/nginx/html +COPY --from=backend-builder /app/ushare /usr/local/bin/ushare # 配置 Nginx RUN rm /etc/nginx/conf.d/default.conf @@ -28,4 +32,4 @@ COPY deployment/nginx.conf /etc/nginx/conf.d EXPOSE 80 # 启动服务 -CMD sh -c "/app/main & nginx -g 'daemon off;'" \ No newline at end of file +CMD sh -c "ushare & nginx -g 'daemon off;'" \ No newline at end of file diff --git a/frontend/index.html b/frontend/index.html index e4b78ea..8f7f31a 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1,13 +1,23 @@ -
- - - -