发布版本字体下载不下来的解决方案

GitHub 的国际带宽在国内服务器确实很慢,但我们可以使用国内镜像源手动提前下载字体打包进 Docker 构建目录的方式来解决这个问题:


✅ 方法一:使用清华大学开源镜像(推荐 ✅)

清华镜像站为 Adobe Source Han Serif 提供了镜像,速度非常快。

Dockerfile 替换为:

RUN apt-get update && apt-get install -y wget unzip fontconfig \
 && mkdir -p /usr/share/fonts/opentype/source-han-serif \
 && wget -O /tmp/SourceHanSerif.ttc.zip https://mirrors.tuna.tsinghua.edu.cn/adobe-fonts/source-han-serif/2.003R/01_SourceHanSerif.ttc.zip \
 && unzip /tmp/SourceHanSerif.ttc.zip -d /usr/share/fonts/opentype/source-han-serif/ \
 && fc-cache -fv \
 && rm -rf /tmp/*

✅ 这个链接速度在国内测试很快,下载基本可以跑满 5MB/s。


✅ 方法二:本地提前下载字体并 COPY 进镜像(完全离线)

  1. 在你的开发机或服务器上手动下载:

    wget https://mirrors.tuna.tsinghua.edu.cn/adobe-fonts/source-han-serif/2.003R/01_SourceHanSerif.ttc.zip
    
  2. 解压缩并放入项目目录,如:

    your_project/fonts/SourceHanSerif.ttc
    
  3. 修改 Dockerfile:

COPY fonts/SourceHanSerif.ttc /usr/share/fonts/opentype/source-han-serif/SourceHanSerif.ttc

RUN apt-get update && apt-get install -y fontconfig \
 && fc-cache -fv

这样构建镜像的时候会直接从本地复制字体文件,不再依赖任何在线下载。


✅ 方法三:使用阿里云 OSS 私有字体资源(适合企业级部署)

如果你有自己的阿里云 OSS 或 CDN,你也可以把字体包传上去,用内网带宽构建更快:

RUN wget -O /tmp/SourceHanSerif.ttc.zip https://your-oss-domain/fonts/SourceHanSerif.ttc.zip

✅ 推荐顺序:

  1. ✅ 使用清华大学镜像(简单、快)
  2. ✅ 手动下载 + COPY(可离线、最稳定)
  3. ⏳ GitHub(慢,不推荐)
  4. ✅ 企业 CDN / OSS(适合部署稳定)

你可能感兴趣的:(github,字体)