Skip to content

Commit 4c41316

Browse files
authored
Update Dockerfile
1 parent 5c22318 commit 4c41316

1 file changed

Lines changed: 15 additions & 24 deletions

File tree

Dockerfile

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,34 @@
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
213

4+
# 直接安装 hugo + git,自动适配所有架构
5+
RUN apk add --no-cache hugo git
6+
7+
# 下载源码
228
RUN git clone --depth 1 https://github.com/hugo-fixit/hugo-fixit-starter.git /build
239
WORKDIR /build
2410

11+
# 构建静态文件
2512
RUN hugo --minify --baseURL "/" --destination /public
2613

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+
# 复制静态资源
2818
RUN cp -r /build/static/* /public/ 2>/dev/null || true
2919

20+
# 创建缺失图标
3021
RUN for icon in apple-touch-icon.png favicon-32x32.png favicon-16x16.png; do \
3122
[ -f "/public/$icon" ] || touch "/public/$icon"; \
3223
done
3324

25+
# 验证
3426
RUN test -f /public/index.html
3527

36-
# 阶段二:运行(跨架构
28+
# 阶段二:运行(超小跨架构 Nginx
3729
FROM nginx:1.29-alpine-slim
3830

39-
RUN apk upgrade --no-cache && \
40-
apk add --upgrade musl --no-cache
31+
RUN apk upgrade --no-cache
4132

4233
COPY --from=builder /public /usr/share/nginx/html
4334

0 commit comments

Comments
 (0)