fix(ci): Preflight 直接跑 docker://node:22-bookworm-slim 跳过 setup-node 下载(国内 GitHub release 超时)
This commit is contained in:
+24
-18
@@ -39,7 +39,9 @@ jobs:
|
|||||||
# ============================================================
|
# ============================================================
|
||||||
preflight:
|
preflight:
|
||||||
name: Preflight 语法 & 构建检查
|
name: Preflight 语法 & 构建检查
|
||||||
runs-on: ubuntu-latest
|
# 国内访问 GitHub actions/node-versions release 经常超时(443 ETIMEDOUT)
|
||||||
|
# 所以直接用官方 node:22 镜像跑这个 Job,绕过 setup-node 下载 step
|
||||||
|
runs-on: [ubuntu-latest:docker://node:22-bookworm-slim]
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
steps:
|
steps:
|
||||||
- name: 📥 Checkout 代码
|
- name: 📥 Checkout 代码
|
||||||
@@ -47,11 +49,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
|
|
||||||
- name: 🔧 安装 Node.js 22
|
# ── 我们已经用 runs-on: docker://node:22 了,所以这里不需要 actions/setup-node ──
|
||||||
uses: actions/setup-node@v4
|
# 避免国内 Runner 从 github.com 下载 Node tar.gz 出现 ETIMEDOUT
|
||||||
with:
|
- name: 🔎 环境自检(node/npm 版本)
|
||||||
node-version: "22"
|
shell: bash
|
||||||
cache: "npm"
|
run: |
|
||||||
|
set -euxo pipefail
|
||||||
|
node -v
|
||||||
|
npm -v
|
||||||
|
which node npm
|
||||||
|
|
||||||
- name: 🧪 安装依赖(npm ci,严格按锁文件)
|
- name: 🧪 安装依赖(npm ci,严格按锁文件)
|
||||||
run: |
|
run: |
|
||||||
@@ -92,12 +98,12 @@ jobs:
|
|||||||
image_full: ${{ steps.meta.outputs.full }}
|
image_full: ${{ steps.meta.outputs.full }}
|
||||||
image_latest: ${{ steps.meta.outputs.latest }}
|
image_latest: ${{ steps.meta.outputs.latest }}
|
||||||
steps:
|
steps:
|
||||||
- name: 📥 Checkout 代码
|
- name: Checkout 代码
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
|
|
||||||
- name: 🏷️ 计算镜像 tag(日期 + 短 SHA)
|
- name: 计算镜像 tag(日期 + 短 SHA)
|
||||||
id: meta
|
id: meta
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
@@ -116,17 +122,17 @@ jobs:
|
|||||||
echo "🪪 镜像 latest : ${IMG_LATEST}"
|
echo "🪪 镜像 latest : ${IMG_LATEST}"
|
||||||
echo "======================================"
|
echo "======================================"
|
||||||
|
|
||||||
- name: 🔧 启用 QEMU(跨架构小概率用得到,保险)
|
- name: 启用 QEMU(跨架构小概率用得到,保险)
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
with:
|
with:
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
|
|
||||||
- name: 🔧 启用 Docker Buildx
|
- name: 启用 Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
with:
|
with:
|
||||||
install: true
|
install: true
|
||||||
|
|
||||||
- name: 🔐 登录 Gitea 容器仓库(Packages)
|
- name: 登录 Gitea 容器仓库(Packages)
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.GITEA_HOST }}
|
registry: ${{ env.GITEA_HOST }}
|
||||||
@@ -135,7 +141,7 @@ jobs:
|
|||||||
# Secrets 里 REGISTRY_TOKEN 优先,没填就用 Gitea Actions 自动注入的仓库级 token
|
# Secrets 里 REGISTRY_TOKEN 优先,没填就用 Gitea Actions 自动注入的仓库级 token
|
||||||
password: ${{ secrets.REGISTRY_TOKEN || github.token }}
|
password: ${{ secrets.REGISTRY_TOKEN || github.token }}
|
||||||
|
|
||||||
- name: 🐳 构建 & 推送(BuildKit 分层缓存,skip_build_cache=true 时禁用)
|
- name: 构建 & 推送(BuildKit 分层缓存,skip_build_cache=true 时禁用)
|
||||||
id: build_push
|
id: build_push
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
env:
|
env:
|
||||||
@@ -159,7 +165,7 @@ jobs:
|
|||||||
org.opencontainers.image.revision=${{ github.sha }}
|
org.opencontainers.image.revision=${{ github.sha }}
|
||||||
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
|
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
|
||||||
|
|
||||||
- name: 🧮 镜像体积 & 层信息(日志里看一下,避免镜像越来越大)
|
- name: 镜像体积 & 层信息(日志里看一下,避免镜像越来越大)
|
||||||
run: |
|
run: |
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
docker pull "${{ steps.meta.outputs.full }}" || true
|
docker pull "${{ steps.meta.outputs.full }}" || true
|
||||||
@@ -181,7 +187,7 @@ jobs:
|
|||||||
name: production
|
name: production
|
||||||
url: ${{ secrets.NUXT_PUBLIC_SITE_URL }}
|
url: ${{ secrets.NUXT_PUBLIC_SITE_URL }}
|
||||||
steps:
|
steps:
|
||||||
- name: ⚠️ 检查部署所需 Secrets 是否都配置了
|
- name: 检查部署所需 Secrets 是否都配置了
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -196,7 +202,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
echo "✅ 部署 Secrets 配置完整"
|
echo "✅ 部署 Secrets 配置完整"
|
||||||
|
|
||||||
- name: 🚀 一键滚动部署(SSH)
|
- name: 一键滚动部署(SSH)
|
||||||
uses: appleboy/ssh-action@v1.2.0
|
uses: appleboy/ssh-action@v1.2.0
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.DEPLOY_HOST }}
|
host: ${{ secrets.DEPLOY_HOST }}
|
||||||
@@ -217,9 +223,9 @@ jobs:
|
|||||||
COMPOSE="docker compose"
|
COMPOSE="docker compose"
|
||||||
|
|
||||||
echo "=============================================="
|
echo "=============================================="
|
||||||
echo "🚢 本次部署镜像: ${IMAGE_NEW}"
|
echo "本次部署镜像: ${IMAGE_NEW}"
|
||||||
echo "🗂️ 部署目录 : ${DEPLOY_DIR}"
|
echo "部署目录 : ${DEPLOY_DIR}"
|
||||||
echo "👤 执行用户 : $(whoami)"
|
echo "执行用户 : $(whoami)"
|
||||||
echo "=============================================="
|
echo "=============================================="
|
||||||
|
|
||||||
# ---------- 1. 确保部署目录存在 ----------
|
# ---------- 1. 确保部署目录存在 ----------
|
||||||
|
|||||||
Reference in New Issue
Block a user