ci: 加速 ssh 工具安装(已存在则跳过 + 阿里云源)
deploy / deploy (push) Successful in 1m4s

Gitea Actions 每个 job 都在全新容器执行,装过的包不会保留,只能
每次重装。原来 apt-get update 连境外源经常拖到几分钟,改为:
先检测 sshpass/ssh 是否已存在(部分 runner 镜像自带,命中即 0 秒),
否则把 apt/apk 源换成 mirrors.aliyun.com 再装。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-25 17:22:05 +08:00
parent 8507d5060b
commit 11c85da65d
+17 -3
View File
@@ -34,12 +34,26 @@ jobs:
- name: 导出镜像为压缩包
run: docker save "$IMAGE" | gzip > image.tar.gz
# 每次 job 都是全新容器,装过的东西不会留下。这里做两件事提速:
# 1) 已经有就直接跳过;2) 换阿里云镜像源,避免连境外源拖到几分钟。
- name: 安装 ssh 工具
run: |
if command -v apt-get >/dev/null; then
apt-get update && apt-get install -y sshpass openssh-client
elif command -v apk >/dev/null; then
if command -v sshpass >/dev/null && command -v ssh >/dev/null; then
echo "sshpass/ssh 已存在,跳过安装"; exit 0
fi
if command -v apk >/dev/null; then
sed -i 's#dl-cdn.alpinelinux.org#mirrors.aliyun.com#g' /etc/apk/repositories
apk add --no-cache sshpass openssh-client
elif command -v apt-get >/dev/null; then
sed -i -e 's#deb.debian.org#mirrors.aliyun.com#g' \
-e 's#security.debian.org#mirrors.aliyun.com#g' \
-e 's#archive.ubuntu.com#mirrors.aliyun.com#g' \
-e 's#security.ubuntu.com#mirrors.aliyun.com#g' \
/etc/apt/sources.list 2>/dev/null || true
sed -i -e 's#deb.debian.org#mirrors.aliyun.com#g' \
-e 's#archive.ubuntu.com#mirrors.aliyun.com#g' \
/etc/apt/sources.list.d/*.sources /etc/apt/sources.list.d/*.list 2>/dev/null || true
apt-get update -qq && apt-get install -y -qq --no-install-recommends sshpass openssh-client
fi
- name: 传镜像包与 compose 到服务器