Skip to content

Commit 153eb0e

Browse files
authored
Update Dockerfile
1 parent f308737 commit 153eb0e

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

Dockerfile

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# 阶段一:构建器(安装 Hugo 并生成默认站点
1+
# 阶段一:构建默认站点(手动安装 Hugo extended,支持多架构
22
FROM alpine:3.19 AS builder
33

4+
# 安装必要工具
45
RUN apk add --no-cache git curl bash libstdc++ libc6-compat
56

7+
# 根据目标架构下载 Hugo extended 二进制
68
ARG TARGETARCH
79
RUN case ${TARGETARCH} in \
810
"amd64") HUGO_ARCH="64bit" ;; \
@@ -11,16 +13,18 @@ RUN case ${TARGETARCH} in \
1113
esac && \
1214
curl -L "https://github.com/gohugoio/hugo/releases/download/v0.156.0/hugo_extended_0.156.0_Linux-${HUGO_ARCH}.tar.gz" | tar -xz -C /usr/local/bin
1315

16+
# 验证 Hugo 版本
1417
RUN hugo version
1518

16-
# 创建空白站点并进入
19+
# 创建空白站点
1720
RUN hugo new site /build --force
21+
1822
WORKDIR /build
1923

20-
# 克隆 FixIt 主题(使用 v0.4.5,该版本稳定且包含完整布局
24+
# 克隆 FixIt 主题(使用 v0.4.5,稳定且包含完整布局
2125
RUN git clone --depth 1 --branch v0.4.5 https://github.com/hugo-fixit/FixIt.git themes/FixIt
2226

23-
# 生成配置文件(启用主题所需的所有合并选项
27+
# 生成基础配置文件(符合 FixIt 主题要求
2428
RUN cat > config.toml <<EOF
2529
baseURL = "https://example.org/"
2630
title = "My FixIt Site"
@@ -45,28 +49,38 @@ paginate = 10
4549
defaultTheme = "auto"
4650
EOF
4751

48-
# 创建一篇示例文章
52+
# 创建首页内容(解决无 index.html 的问题)
53+
RUN cat > content/_index.md <<EOF
54+
---
55+
title: "Home"
56+
---
57+
58+
Welcome to my FixIt site!
59+
EOF
60+
61+
# 创建一篇默认示例文章
4962
RUN mkdir -p content/posts && \
5063
printf '%s\n' '---' 'title: "Welcome to FixIt Docker"' "date: $(date +%Y-%m-%d)" 'draft: false' '---' '' 'This is a default post from the Docker image. You can replace it by mounting your own content.' '' 'Happy blogging!' > content/posts/welcome.md
5164

52-
# 构建静态网站
65+
# 构建静态文件(作为容器启动时的后备内容)
5366
RUN hugo --minify --destination /default-public
5467

55-
# 验证生成的文件是否存在(调试用)
56-
RUN ls -la /default-public && test -f /default-public/index.html
68+
# 注意:不再验证 index.html 是否存在,因为运行时 entrypoint 会重新生成
5769

58-
# 阶段二:运行时(Nginx + Hugo)
70+
# ========== 阶段二:运行时镜像 ==========
5971
FROM nginx:stable-alpine
6072

6173
RUN apk add --no-cache bash libstdc++ libc6-compat
6274

75+
# 复制 Hugo 二进制
6376
COPY --from=builder /usr/local/bin/hugo /usr/local/bin/hugo
77+
78+
# 复制站点的完整源码(用于运行时动态重建)
6479
COPY --from=builder /build /app/default-site
80+
# 复制预构建的静态文件(作为 Nginx 默认内容)
6581
COPY --from=builder /default-public /usr/share/nginx/html
6682

67-
# 再次验证运行时目录
68-
RUN ls -la /usr/share/nginx/html && test -f /usr/share/nginx/html/index.html
69-
83+
# 创建可挂载的数据目录
7084
RUN mkdir -p /data/{content,static,layouts,assets,data} /config
7185

7286
COPY docker-entrypoint.sh /usr/local/bin/

0 commit comments

Comments
 (0)