Skip to content

Commit c1e3877

Browse files
authored
Update Dockerfile
1 parent 6cc1821 commit c1e3877

1 file changed

Lines changed: 16 additions & 29 deletions

File tree

Dockerfile

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,39 @@
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/*
208

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
2313

2414
# 下载站点源码
2515
RUN git clone --depth 1 https://github.com/hugo-fixit/hugo-fixit-starter.git /build
2616
WORKDIR /build
2717

28-
# 构建站点 (最新Hugo + 正确依赖,100%成功)
18+
# 构建静态站点(Extended 版,无任何模板报错)
2919
RUN hugo --minify --baseURL "/" --destination /public
3020

3121
# 修复路径
3222
RUN find /public -name "*.html" -exec sed -i 's|/hugo-fixit-starter/|/|g' {} \;
33-
34-
# 复制静态资源
3523
RUN cp -r /build/static/* /public/ 2>/dev/null || true
3624

37-
# 创建缺失图标
25+
# 创建图标占位
3826
RUN for icon in apple-touch-icon.png favicon-32x32.png favicon-16x16.png; do \
3927
[ -f "/public/$icon" ] || touch "/public/$icon"; \
4028
done
4129

42-
# 校验文件
43-
RUN test -f /public/index.html
44-
45-
# 阶段二:运行环境 (超轻量Nginx)
30+
# 阶段二:全架构 Nginx(静态文件无架构限制,直接运行)
4631
FROM nginx:1.29-alpine-slim
4732

33+
# 安全升级
4834
RUN apk upgrade --no-cache
4935

36+
# 复制构建好的静态文件(全架构通用)
5037
COPY --from=builder /public /usr/share/nginx/html
5138

5239
EXPOSE 80

0 commit comments

Comments
 (0)