Files
blog/deploy/Dockerfile
T

47 lines
2.2 KiB
Docker
Raw Normal View History

# CNB 构建环境:固定 hugo 0.128.2 extended(与现网一致)+ 又拍云 upx + EdgeOne CLI
#
# ★ 为什么 hugo 二进制随仓库携带,而不是构建时在线下载:
# 实测国内节点直连 github.com 拉这 22MB 的 release 需要 127 秒(本机仅 7 秒),
# 而这是每次构建都要付的成本。随仓库携带后构建零跨境下载、100% 可复现。
# 二进制体积 84MB,进 git 后仅 24MB(zlib),对 CNB 100GiB 免费额度可忽略。
#
# ★ 注意架构:CNB 构建节点是 linux/amd64。
# 本机 E:\Hugo\hugo.exe 是 windows/amd64,在容器里跑不了(会报 cannot execute
# binary file),所以必须是 linux 版。文件在 bin/linux/hugo。
FROM node:22-bookworm-slim
# ★ 换国内 apt 源:CNB 官方只明示加速「Docker / NPM / Maven 镜像」,
# Debian 的默认 apt 源(deb.debian.org)不在承诺范围内,而构建节点在国内,
# 直连默认源可能慢或超时 → 换成阿里云镜像兜底。
# bookworm 镜像存在两代源文件格式(旧 /etc/apt/sources.list 与
# 新 deb822 /etc/apt/sources.list.d/debian.sources),两个都改,避免格式差异踩空。
RUN set -eux; \
for f in /etc/apt/sources.list /etc/apt/sources.list.d/debian.sources; do \
if [ -f "$f" ]; then \
sed -i -e 's|deb.debian.org|mirrors.aliyun.com|g' \
-e 's|security.debian.org|mirrors.aliyun.com|g' "$f"; \
fi; \
done; \
apt-get update && apt-get install -y --no-install-recommends \
ca-certificates curl tar zstd python3 xz-utils git \
&& rm -rf /var/lib/apt/lists/*
# Hugo extended 0.128.2(linux/amd64),随仓库提供
COPY bin/linux/hugo /usr/local/bin/hugo
RUN chmod +x /usr/local/bin/hugo && hugo version
# 又拍云 upx(源在国内 CDN,直连稳定,保留在线安装)
RUN set -eux; \
curl -fsSL -o /tmp/upx.tgz \
"https://collection.b0.upaiyun.com/softwares/upx/upx_0.4.9_linux_amd64.tar.gz"; \
tar -xzf /tmp/upx.tgz -C /usr/local/bin upx; \
chmod +x /usr/local/bin/upx; \
rm /tmp/upx.tgz; \
upx --version | head -1
# EdgeOne CLI(用于境内外两个 Pages 项目部署)
RUN npm i -g edgeone@latest
WORKDIR /workspace
CMD ["hugo", "version"]