1- # 阶段一:构建静态站点
1+ # 阶段一:构建静态站点(全架构支持:amd64 / arm64 / armv7)
22FROM ubuntu:22.04 AS builder
33
44RUN apt-get update && apt-get install -y --no-install-recommends \
5- git curl ca-certificates golang-go && \
5+ git curl ca-certificates && \
66 rm -rf /var/lib/apt/lists/*
77
8+ # 自动识别架构并下载对应 Hugo
89ARG TARGETARCH
910RUN case ${TARGETARCH} in \
1011 "amd64" ) HUGO_ARCH="64bit" ;; \
1112 "arm64" ) HUGO_ARCH="ARM64" ;; \
13+ "arm" ) HUGO_ARCH="ARM" ;; \
1214 *) echo "Unsupported architecture: ${TARGETARCH}" ; exit 1 ;; \
1315 esac && \
1416 curl -L "https://github.com/gohugoio/hugo/releases/download/v0.156.0/hugo_extended_0.156.0_Linux-${HUGO_ARCH}.tar.gz" -o /tmp/hugo.tar.gz && \
@@ -18,32 +20,36 @@ RUN case ${TARGETARCH} in \
1820
1921RUN hugo version
2022
23+ # 下载并构建站点
2124RUN git clone --depth 1 https://github.com/hugo-fixit/hugo-fixit-starter.git /build
2225WORKDIR /build
2326
2427RUN hugo --minify --baseURL "/" --destination /public
2528
26- # 修复 HTML 中的子路径残留
29+ # 修复路径
2730RUN find /public -type f -name "*.html" -exec sed -i 's|/hugo-fixit-starter/|/|g' {} \;
2831
29- # 复制所有静态资源(包括缺失的图标)
32+ # 复制静态资源
3033RUN cp -r /build/static/* /public/ 2>/dev/null || true
3134
32- # 如果仍缺少特定图标,创建简单占位(避免 404)
35+ # 创建缺失图标
3336RUN for icon in apple-touch-icon.png favicon-32x32.png favicon-16x16.png; do \
34- if [ ! -f "/public/$icon" ]; then \
35- echo "Creating placeholder $icon" ; \
36- convert -size 32x32 xc:transparent /public/$icon 2>/dev/null || \
37- touch /public/$icon; \
38- fi; \
39- done
40-
41- # 验证首页存在
37+ if [ ! -f "/public/$icon" ]; then \
38+ echo "Creating placeholder: $icon" ; \
39+ touch /public/$icon; \
40+ fi; \
41+ done
42+
43+ # 验证构建结果
4244RUN test -f /public/index.html
4345
46+ # 阶段二:运行(支持所有架构)
4447FROM nginx:1.29-alpine-slim
48+
4549RUN apk upgrade --no-cache && \
4650 apk add --upgrade musl --no-cache
51+
4752COPY --from=builder /public /usr/share/nginx/html
48- EXPOSE 80/tcp
53+
54+ EXPOSE 80
4955CMD ["nginx" , "-g" , "daemon off;" ]
0 commit comments