|
1 | | -# 阶段一:构建静态站点(amd64 / arm64 / armv7 全支持) |
2 | | -FROM ubuntu:22.04 AS builder |
3 | | - |
4 | | -RUN apt-get update && apt-get install -y --no-install-recommends \ |
5 | | - git curl ca-certificates golang-go && \ |
6 | | - rm -rf /var/lib/apt/lists/* |
7 | | - |
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 "Unsupported architecture: ${TARGETARCH}"; exit 1 ;; \ |
14 | | - esac && \ |
15 | | - 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 && \ |
16 | | - tar -xzf /tmp/hugo.tar.gz -C /tmp && \ |
17 | | - mv /tmp/hugo /usr/local/bin/hugo && \ |
18 | | - chmod +x /usr/local/bin/hugo |
19 | | - |
20 | | -RUN hugo version |
| 1 | +# 阶段一:构建站点(Alpine 自动支持 amd64/arm64/armv7,无需手动下载 Hugo) |
| 2 | +FROM alpine:latest AS builder |
21 | 3 |
|
| 4 | +# 直接安装 hugo + git,自动适配所有架构 |
| 5 | +RUN apk add --no-cache hugo git |
| 6 | + |
| 7 | +# 下载源码 |
22 | 8 | RUN git clone --depth 1 https://github.com/hugo-fixit/hugo-fixit-starter.git /build |
23 | 9 | WORKDIR /build |
24 | 10 |
|
| 11 | +# 构建静态文件 |
25 | 12 | RUN hugo --minify --baseURL "/" --destination /public |
26 | 13 |
|
27 | | -RUN find /public -type f -name "*.html" -exec sed -i 's|/hugo-fixit-starter/|/|g' {} \; |
| 14 | +# 修复路径 |
| 15 | +RUN find /public -name "*.html" -exec sed -i 's|/hugo-fixit-starter/|/|g' {} \; |
| 16 | + |
| 17 | +# 复制静态资源 |
28 | 18 | RUN cp -r /build/static/* /public/ 2>/dev/null || true |
29 | 19 |
|
| 20 | +# 创建缺失图标 |
30 | 21 | RUN for icon in apple-touch-icon.png favicon-32x32.png favicon-16x16.png; do \ |
31 | 22 | [ -f "/public/$icon" ] || touch "/public/$icon"; \ |
32 | 23 | done |
33 | 24 |
|
| 25 | +# 验证 |
34 | 26 | RUN test -f /public/index.html |
35 | 27 |
|
36 | | -# 阶段二:运行(跨架构) |
| 28 | +# 阶段二:运行(超小跨架构 Nginx) |
37 | 29 | FROM nginx:1.29-alpine-slim |
38 | 30 |
|
39 | | -RUN apk upgrade --no-cache && \ |
40 | | - apk add --upgrade musl --no-cache |
| 31 | +RUN apk upgrade --no-cache |
41 | 32 |
|
42 | 33 | COPY --from=builder /public /usr/share/nginx/html |
43 | 34 |
|
|
0 commit comments