Skip to content

Commit 306b884

Browse files
authored
Update Dockerfile
1 parent 153eb0e commit 306b884

1 file changed

Lines changed: 19 additions & 55 deletions

File tree

Dockerfile

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

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

7-
# 根据目标架构下载 Hugo extended 二进制
86
ARG TARGETARCH
97
RUN case ${TARGETARCH} in \
108
"amd64") HUGO_ARCH="64bit" ;; \
@@ -13,78 +11,44 @@ RUN case ${TARGETARCH} in \
1311
esac && \
1412
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
1513

16-
# 验证 Hugo 版本
1714
RUN hugo version
1815

1916
# 创建空白站点
2017
RUN hugo new site /build --force
21-
2218
WORKDIR /build
2319

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

27-
# 生成基础配置文件(符合 FixIt 主题要求)
28-
RUN cat > config.toml <<EOF
29-
baseURL = "https://example.org/"
30-
title = "My FixIt Site"
31-
theme = "FixIt"
32-
defaultContentLanguage = "zh-cn"
33-
enableRobotsTXT = true
34-
paginate = 10
35-
36-
[markup]
37-
_merge = "shallow"
38-
39-
[outputs]
40-
_merge = "shallow"
41-
42-
[taxonomies]
43-
_merge = "shallow"
44-
45-
[params]
46-
version = "4.x"
47-
description = "A site built with Hugo FixIt theme"
48-
keywords = ["Hugo", "FixIt", "Blog"]
49-
defaultTheme = "auto"
50-
EOF
23+
# 复制预先准备好的配置文件
24+
COPY config.toml .
5125

52-
# 创建首页内容(解决无 index.html 的问题
26+
# 创建首页(必须
5327
RUN cat > content/_index.md <<EOF
5428
---
5529
title: "Home"
5630
---
57-
58-
Welcome to my FixIt site!
31+
Welcome to my FixIt site.
5932
EOF
6033

61-
# 创建一篇默认示例文章
34+
# 创建一篇示例文章
6235
RUN mkdir -p content/posts && \
63-
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
36+
printf '%s\n' '---' 'title: "Welcome to FixIt Docker"' "date: $(date +%Y-%m-%d)" 'draft: false' '---' '' 'This is a default post. You can replace it by mounting your own content.' > content/posts/welcome.md
6437

65-
# 构建静态文件(作为容器启动时的后备内容)
66-
RUN hugo --minify --destination /default-public
38+
# 构建静态文件
39+
RUN hugo --minify --destination /public
6740

68-
# 注意:不再验证 index.html 是否存在,因为运行时 entrypoint 会重新生成
41+
# 验证 index.html 存在(关键)
42+
RUN test -f /public/index.html || (echo "index.html not generated" && exit 1)
6943

70-
# ========== 阶段二:运行时镜像 ==========
44+
# 阶段二:提供静态文件的 Nginx
7145
FROM nginx:stable-alpine
7246

73-
RUN apk add --no-cache bash libstdc++ libc6-compat
74-
75-
# 复制 Hugo 二进制
76-
COPY --from=builder /usr/local/bin/hugo /usr/local/bin/hugo
77-
78-
# 复制站点的完整源码(用于运行时动态重建)
79-
COPY --from=builder /build /app/default-site
80-
# 复制预构建的静态文件(作为 Nginx 默认内容)
81-
COPY --from=builder /default-public /usr/share/nginx/html
82-
83-
# 创建可挂载的数据目录
84-
RUN mkdir -p /data/{content,static,layouts,assets,data} /config
47+
COPY --from=builder /build/public /usr/share/nginx/html
8548

86-
COPY docker-entrypoint.sh /usr/local/bin/
87-
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
49+
# 可选:复制一个简单的启动脚本,用于支持未来可能的动态合并(暂不需要复杂逻辑)
50+
COPY docker-entrypoint.sh /docker-entrypoint.sh
51+
RUN chmod +x /docker-entrypoint.sh
8852

8953
EXPOSE 80
90-
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
54+
ENTRYPOINT ["/docker-entrypoint.sh"]

0 commit comments

Comments
 (0)