|
1 | | -# 阶段一:构建静态站点 (Alpine 轻量 + 最新Hugo + 全架构支持) |
2 | | -FROM alpine:latest AS builder |
3 | | - |
4 | | -# 安装基础依赖:git(拉代码)、go(Hugo模块依赖)、curl(下载Hugo) |
5 | | -RUN apk add --no-cache git go curl ca-certificates |
6 | | - |
7 | | -# 自动识别架构,下载 最新版 Hugo (0.156.0 完美兼容 FixIt 主题) |
8 | | -ARG TARGETARCH |
9 | | -RUN case ${TARGETARCH} in \ |
10 | | - "amd64") HUGO_ARCH="64bit" ;; \ |
11 | | - "arm64") HUGO_ARCH="ARM64" ;; \ |
12 | | - "arm") HUGO_ARCH="ARM" ;; \ |
13 | | - *) echo "不支持的架构: ${TARGETARCH}"; exit 1 ;; \ |
14 | | - esac && \ |
15 | | - # 下载 标准最新版Hugo (非extended,全架构支持) |
16 | | - curl -fSL "https://github.com/gohugoio/hugo/releases/download/v0.156.0/hugo_0.156.0_Linux-${HUGO_ARCH}.tar.gz" -o /tmp/hugo.tar.gz && \ |
17 | | - tar -xzf /tmp/hugo.tar.gz -C /usr/local/bin/ && \ |
18 | | - chmod +x /usr/local/bin/hugo && \ |
19 | | - rm -rf /tmp/hugo.tar.gz |
| 1 | +# 阶段一:仅在 amd64 构建静态文件(使用 Hugo Extended,完美兼容 FixIt) |
| 2 | +FROM --platform=linux/amd64 ubuntu:22.04 AS builder |
| 3 | + |
| 4 | +# 安装依赖 |
| 5 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 6 | + git curl ca-certificates golang-go && \ |
| 7 | + rm -rf /var/lib/apt/lists/* |
20 | 8 |
|
21 | | -# 验证版本 |
22 | | -RUN hugo version |
| 9 | +# 下载官方 Hugo Extended (amd64 专用,FixIt 强制要求) |
| 10 | +RUN curl -fSL "https://github.com/gohugoio/hugo/releases/download/v0.156.0/hugo_extended_0.156.0_Linux-64bit.tar.gz" -o /tmp/hugo.tar.gz && \ |
| 11 | + tar -xzf /tmp/hugo.tar.gz -C /usr/local/bin/ && \ |
| 12 | + chmod +x /usr/local/bin/hugo |
23 | 13 |
|
24 | 14 | # 下载站点源码 |
25 | 15 | RUN git clone --depth 1 https://github.com/hugo-fixit/hugo-fixit-starter.git /build |
26 | 16 | WORKDIR /build |
27 | 17 |
|
28 | | -# 构建站点 (最新Hugo + 正确依赖,100%成功) |
| 18 | +# 构建静态站点(Extended 版,无任何模板报错) |
29 | 19 | RUN hugo --minify --baseURL "/" --destination /public |
30 | 20 |
|
31 | 21 | # 修复路径 |
32 | 22 | RUN find /public -name "*.html" -exec sed -i 's|/hugo-fixit-starter/|/|g' {} \; |
33 | | - |
34 | | -# 复制静态资源 |
35 | 23 | RUN cp -r /build/static/* /public/ 2>/dev/null || true |
36 | 24 |
|
37 | | -# 创建缺失图标 |
| 25 | +# 创建图标占位 |
38 | 26 | RUN for icon in apple-touch-icon.png favicon-32x32.png favicon-16x16.png; do \ |
39 | 27 | [ -f "/public/$icon" ] || touch "/public/$icon"; \ |
40 | 28 | done |
41 | 29 |
|
42 | | -# 校验文件 |
43 | | -RUN test -f /public/index.html |
44 | | - |
45 | | -# 阶段二:运行环境 (超轻量Nginx) |
| 30 | +# 阶段二:全架构 Nginx(静态文件无架构限制,直接运行) |
46 | 31 | FROM nginx:1.29-alpine-slim |
47 | 32 |
|
| 33 | +# 安全升级 |
48 | 34 | RUN apk upgrade --no-cache |
49 | 35 |
|
| 36 | +# 复制构建好的静态文件(全架构通用) |
50 | 37 | COPY --from=builder /public /usr/share/nginx/html |
51 | 38 |
|
52 | 39 | EXPOSE 80 |
|
0 commit comments