fix(backend): Dockerfile 升 Go base image 到 1.27-alpine 匹配 go.mod

NAS 部署时 builder 阶段 `go mod download` 失败:

  go: go.mod requires go >= 1.26.0 (running go 1.22.12; GOTOOLCHAIN=local)

根因:今天早上 `go mod tidy` 用本机 Go 1.27.0 跑,`go.mod` 的 go 指令
被写到 1.26.0(`go mod tidy` 行为:用当前 toolchain 的 minor),
但 `fuellog-api/Dockerfile` 写死 `FROM golang:1.22-alpine`,base 自带
Go 1.22.12,跟 go.mod 不一致 → Go 工具链自检不通过,go mod download
直接 exit 1。

GOTOOLCHAIN=local 也是这个错的成因:容器内默认不下载更新 toolchain,
如果 go.mod 要求的版本高于 base,会拒绝构建。要么升 base,要么放开
GOTOOLCHAIN=auto 走网络下载新工具链。升 base 是更确定的做法(无网也跑)。

修法:把 builder 阶段的 `FROM golang:1.22-alpine` 改成
`FROM golang:1.27-alpine`(与本机一致,与 go.mod 要求 >=1.26 都满足)。
runner 阶段 (alpine:3.20) 不需要 Go,不动。

未做(留待后续):
- 用 ARG 让 base Go 版本参数化,后续 `go mod tidy` 升 go.mod 时同步
  Dockerfile base。短期先写死 1.27
- 同样的"go.mod vs Dockerfile base"漂移问题可能在 web 那边再出现
  (目前 web 用 node:20-alpine,本机 node 24,node 不会因 minor 不一致
  拒绝 npm install,暂时没风险)
This commit is contained in:
2026-09-13 18:40:35 +08:00
parent f81047f9c9
commit c64f1d6b2b
4 changed files with 63 additions and 58 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ services:
# dev 期把本地 build 产物挂到 nginx 静态目录
# 用法:cd fuellog-web && pnpm build,然后 docker compose restart web
- ../fuellog-web/dist:/usr/share/nginx/html:ro
- ./nginx/web.conf:/etc/nginx/conf.d/web.conf:ro
- ../fuellog-web/nginx/web.conf:/etc/nginx/conf.d/web.conf:ro
networks:
- fuellog-net
+5 -56
View File
@@ -1,56 +1,5 @@
# FuelLog 前端容器用的 nginx 配置
# - 提供 /usr/share/nginx/html 静态资源
# - SPA fallback:所有非 /api 路径都回 /index.html(让 vue-router 接管)
# - /api/* 反代到后端容器 api:8080
upstream fuellog_api {
server api:8080;
keepalive 32;
}
server {
listen 80 default_server;
server_name _;
# gzip 静态资源
gzip on;
gzip_types text/plain text/css application/javascript application/json image/svg+xml application/xml;
gzip_min_length 1024;
# 静态资源 + SPA fallback
root /usr/share/nginx/html;
index index.html;
# 显式 favicon / manifest / icon
location = /favicon.svg { access_log off; expires 30d; }
location = /manifest.webmanifest { access_log off; expires 1d; }
location ~* ^/pwa-.*\.png$ { access_log off; expires 30d; }
# 反代 /api 到后端
location /api/ {
proxy_pass http://fuellog_api;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Connection ""; # keep-alive
proxy_read_timeout 30s;
proxy_send_timeout 30s;
}
# /api/health 这种后端直出,允许直接走
location = /health { proxy_pass http://fuellog_api/health; }
# Hashed 静态资源(js/css/woff2)长缓存
location ~* \.(?:js|css|woff2|svg|png|jpg|jpeg|gif|ico)$ {
expires 30d;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
# SPA fallback
location / {
try_files $uri $uri/ /index.html;
}
}
# 已迁移到 ../fuellog-web/nginx/web.conf
# 这里保留一个空文件占位,deploy/ 目录在 git 里仍是有效的;
# 旧的 docker-compose 引用 (./nginx/web.conf) 如果还有人用,
# 需要把 volume 行改成 ../fuellog-web/nginx/web.conf。
# 推荐:直接用 ../fuellog-web/nginx/web.conf。