diff --git a/Dockerfile b/Dockerfile index cc1a05d..7025563 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,18 +10,19 @@ RUN apk add --no-cache yarn WORKDIR /app/chuan-next -# 前端依赖和构建 -COPY chuan-next/package.json chuan-next/yarn.lock ./ -RUN yarn install --frozen-lockfile --network-timeout 300000 - +# 复制所有源代码(确保获取最新代码) COPY chuan-next/ ./ # 清理构建文件(模拟 build-fullstack.sh 的 clean_all 函数) RUN rm -rf .next out +# 前端依赖和构建 +COPY chuan-next/package.json chuan-next/yarn.lock ./ +RUN yarn install --frozen-lockfile --network-timeout 300000 + # 临时移除 API 目录进行 SSG 构建(模拟 build-fullstack.sh 的 build_frontend 函数) RUN if [ -d "src/app/api" ]; then mv src/app/api /tmp/api-backup; fi && \ - NEXT_EXPORT=true NODE_ENV=production NEXT_PUBLIC_BACKEND_URL= NEXT_PUBLIC_WS_URL= NEXT_PUBLIC_API_BASE_URL= SKIP_TYPESCRIPT_CHECK=true yarn build && \ + NEXT_EXPORT=true NODE_ENV=production NEXT_PUBLIC_BACKEND_URL= NEXT_PUBLIC_WS_URL= NEXT_PUBLIC_API_BASE_URL= yarn build && \ if [ -d "/tmp/api-backup" ]; then mv /tmp/api-backup src/app/api; fi # ============================================== @@ -39,21 +40,16 @@ ENV GOARCH=amd64 WORKDIR /app +# 先复制所有源代码(确保获取最新代码) +COPY . . + # Go 依赖 COPY go.mod go.sum ./ RUN go mod download -# 清理嵌入的前端文件(模拟 build-fullstack.sh 的 copy_frontend_files 函数) -RUN mkdir -p ./internal/web/frontend && \ - find ./internal/web/frontend -type f ! -name ".gitkeep" -delete 2>/dev/null || true - # 拷贝前端构建结果 COPY --from=frontend-builder /app/chuan-next/out ./internal/web/frontend/ -# Go 源码 -COPY cmd/ ./cmd/ -COPY internal/ ./internal/ - # 构建 Go 应用 - AMD64 架构(模拟 build-fullstack.sh 的 build_backend 函数) RUN go build -ldflags='-s -w -extldflags '-static'' -o server ./cmd diff --git a/README.md b/README.md index 23d6bb2..691172f 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ cd file-transfer-go docker-compose up -d # 或者直接使用 Docker 镜像 -docker run -d -p 8080:8080 --name file-transfer-go matrixseven/file-transfer:latest +docker run -d -p 8080:8080 --name file-transfer-go matrixseven/file-transfer-go:latest ``` ### 方式二:本地构建部署 diff --git a/docker-compose.yml b/docker-compose.yml index e2248fe..addd32f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,23 +1,21 @@ version: '3.8' services: - file-transfer-go: - build: . - ports: - - "8080:8080" - environment: - - NODE_ENV=production - restart: unless-stopped - healthcheck: - test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:8080"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 40s - - # 可选:使用已发布的镜像 - # file-transfer-go: - # image: matrixseven/file-transfer:latest + # file-transfer-go: + # build: . # ports: # - "8080:8080" + # environment: + # - NODE_ENV=production # restart: unless-stopped + # healthcheck: + # test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:8080"] + # interval: 30s + # timeout: 10s + # retries: 3 + # start_period: 40s + file-transfer-go: + image: matrixseven/file-transfer-go:latest + ports: + - "8080:8080" + restart: unless-stopped diff --git a/internal/web/frontend/.gitkeep b/internal/web/frontend/.gitkeep new file mode 100644 index 0000000..ee68a30 --- /dev/null +++ b/internal/web/frontend/.gitkeep @@ -0,0 +1,3 @@ +# Static Files Directory + +This directory contains static files that will be embedded into the Go binary. diff --git a/internal/web/frontend/404.html b/internal/web/frontend/404.html deleted file mode 100644 index c899825..0000000 --- a/internal/web/frontend/404.html +++ /dev/null @@ -1 +0,0 @@ -