You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Dockerfile
+26-12Lines changed: 26 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,10 @@
1
-
# 阶段一:构建器(安装 Hugo 并生成默认站点)
1
+
# 阶段一:构建默认站点(手动安装 Hugo extended,支持多架构)
2
2
FROM alpine:3.19 AS builder
3
3
4
+
# 安装必要工具
4
5
RUN apk add --no-cache git curl bash libstdc++ libc6-compat
5
6
7
+
# 根据目标架构下载 Hugo extended 二进制
6
8
ARG TARGETARCH
7
9
RUN case ${TARGETARCH} in \
8
10
"amd64") HUGO_ARCH="64bit" ;; \
@@ -11,16 +13,18 @@ RUN case ${TARGETARCH} in \
11
13
esac && \
12
14
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
13
15
16
+
# 验证 Hugo 版本
14
17
RUN hugo version
15
18
16
-
#创建空白站点并进入
19
+
#创建空白站点
17
20
RUN hugo new site /build --force
21
+
18
22
WORKDIR /build
19
23
20
-
# 克隆 FixIt 主题(使用 v0.4.5,该版本稳定且包含完整布局)
24
+
# 克隆 FixIt 主题(使用 v0.4.5,稳定且包含完整布局)
21
25
RUN git clone --depth 1 --branch v0.4.5 https://github.com/hugo-fixit/FixIt.git themes/FixIt
22
26
23
-
#生成配置文件(启用主题所需的所有合并选项)
27
+
#生成基础配置文件(符合 FixIt 主题要求)
24
28
RUN cat > config.toml <<EOF
25
29
baseURL = "https://example.org/"
26
30
title = "My FixIt Site"
@@ -45,28 +49,38 @@ paginate = 10
45
49
defaultTheme = "auto"
46
50
EOF
47
51
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
+
# 创建一篇默认示例文章
49
62
RUN mkdir -p content/posts && \
50
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
51
64
52
-
#构建静态网站
65
+
#构建静态文件(作为容器启动时的后备内容)
53
66
RUN hugo --minify --destination /default-public
54
67
55
-
# 验证生成的文件是否存在(调试用)
56
-
RUN ls -la /default-public && test -f /default-public/index.html
68
+
# 注意:不再验证 index.html 是否存在,因为运行时 entrypoint 会重新生成
57
69
58
-
# 阶段二:运行时(Nginx + Hugo)
70
+
#========== 阶段二:运行时镜像 ==========
59
71
FROM nginx:stable-alpine
60
72
61
73
RUN apk add --no-cache bash libstdc++ libc6-compat
0 commit comments