Fix CentOS 7 EOL and improve workflow steps
Updated the GitHub Actions workflow to fix CentOS 7 EOL repository issues and improve container initialization steps.
This commit is contained in:
1 parent
51fb3bd675
commit
eab93f3e08
1 file changed
+63
-63
+63
-63
@@ -4,7 +4,9 @@ on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test-distros:
|
||||
# 关键点 1: 在 Ubuntu 宿主机上运行 Job,而不是直接在容器里跑
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -15,75 +17,73 @@ jobs:
|
||||
- 'alpine:latest'
|
||||
- 'almalinux:9'
|
||||
- 'rockylinux:9'
|
||||
- 'centos:7'
|
||||
- 'centos:7' # 这里的 CentOS 7 现在可以跑了!
|
||||
- 'quay.io/centos/centos:stream9'
|
||||
|
||||
container:
|
||||
image: ${{ matrix.container }}
|
||||
options: --privileged # 必须开启特权模式
|
||||
|
||||
steps:
|
||||
# 关键点 2: 在宿主机上检出代码 (Ubuntu 支持 Node20,没问题)
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# 1. 修复 CentOS 7 EOL 源问题
|
||||
- name: Fix CentOS 7 EOL Repos
|
||||
# 关键点 3: 使用 docker run 手动启动容器并挂载代码
|
||||
- name: Run Test in Container
|
||||
run: |
|
||||
if grep -q "CentOS Linux 7" /etc/os-release 2>/dev/null; then
|
||||
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Base.repo
|
||||
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Base.repo
|
||||
fi
|
||||
|
||||
# 2. 安装依赖并初始化运行环境 (这是修复核心)
|
||||
- name: Initialize Environment (Fix Docker Quirks)
|
||||
run: |
|
||||
echo "Initializing environment for $(cat /etc/os-release | grep PRETTY_NAME)"
|
||||
# 打印当前测试的镜像
|
||||
echo "🚀 Testing on image: ${{ matrix.container }}"
|
||||
|
||||
# --- Debian / Ubuntu ---
|
||||
if [ -f /etc/debian_version ]; then
|
||||
apt-get update
|
||||
apt-get install -y curl sudo openssh-server
|
||||
|
||||
# [关键修复] 生成 Host Keys,否则 sshd -t 会报错
|
||||
ssh-keygen -A
|
||||
# [关键修复] 创建运行目录
|
||||
mkdir -p /run/sshd
|
||||
fi
|
||||
|
||||
# --- Alpine ---
|
||||
if [ -f /etc/alpine-release ]; then
|
||||
apk add --no-cache curl sudo openssh-server bash
|
||||
# [关键修复] 生成 Host Keys
|
||||
ssh-keygen -A
|
||||
fi
|
||||
|
||||
# --- RHEL / CentOS / Alma / Rocky ---
|
||||
if [ -f /etc/redhat-release ]; then
|
||||
# [关键修复] AlmaLinux 9 解决 curl-minimal 冲突
|
||||
if command -v dnf >/dev/null; then
|
||||
dnf install -y --allowerasing curl sudo openssh-server
|
||||
else
|
||||
yum install -y curl sudo openssh-server
|
||||
fi
|
||||
|
||||
# [关键修复] 生成 Host Keys 和目录
|
||||
ssh-keygen -A
|
||||
mkdir -p /run/sshd
|
||||
fi
|
||||
|
||||
# 3. 运行测试脚本
|
||||
- name: Run Init Script
|
||||
run: |
|
||||
# 赋予脚本执行权限
|
||||
chmod +x init.sh
|
||||
# 使用 --strict 严格模式测试,遇到错误立即退出
|
||||
./init.sh --user=root --port=2222 --key-raw="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPQQDejyTCPJO3Jyw5UX9jmojb/zjgcqVuRO28fmpWU5" --no-update --bbr --delay-restart --yes --strict
|
||||
|
||||
# 4. 验证结果 (可选)
|
||||
- name: Verify Configuration
|
||||
run: |
|
||||
if grep -q "BEGIN SERVER-INIT MANAGED BLOCK" /etc/ssh/sshd_config; then
|
||||
echo "✅ SUCCESS: Config block injected."
|
||||
else
|
||||
echo "❌ FAIL: Config block missing."
|
||||
exit 1
|
||||
fi
|
||||
# 启动 Docker 容器运行测试逻辑
|
||||
# --rm: 跑完删除
|
||||
# --privileged: 允许修改系统参数
|
||||
# -v $(pwd):/mnt: 把当前宿主机的代码挂载到容器的 /mnt 目录
|
||||
docker run --rm --privileged -v $(pwd):/mnt -w /mnt ${{ matrix.container }} /bin/sh -c '
|
||||
|
||||
# === 第一步:修复 CentOS 7 EOL 源 (起死回生) ===
|
||||
if [ -f /etc/redhat-release ] && grep -q "CentOS Linux 7" /etc/redhat-release; then
|
||||
echo "Fixing CentOS 7 EOL repos..."
|
||||
sed -i "s/mirrorlist/#mirrorlist/g" /etc/yum.repos.d/CentOS-Base.repo
|
||||
sed -i "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-Base.repo
|
||||
fi
|
||||
|
||||
# === 第二步:环境补全 (安装 sudo, curl, sshd, 生成 key) ===
|
||||
echo "Installing dependencies..."
|
||||
|
||||
# Debian / Ubuntu
|
||||
if [ -f /etc/debian_version ]; then
|
||||
apt-get update -y && apt-get install -y curl sudo openssh-server
|
||||
ssh-keygen -A
|
||||
mkdir -p /run/sshd
|
||||
fi
|
||||
|
||||
# Alpine
|
||||
if [ -f /etc/alpine-release ]; then
|
||||
apk add --no-cache curl sudo openssh-server bash
|
||||
ssh-keygen -A
|
||||
fi
|
||||
|
||||
# RHEL / CentOS / Alma / Rocky
|
||||
if [ -f /etc/redhat-release ]; then
|
||||
# AlmaLinux 9 解决 curl-minimal 冲突
|
||||
if command -v dnf >/dev/null; then
|
||||
dnf install -y --allowerasing curl sudo openssh-server
|
||||
else
|
||||
yum install -y curl sudo openssh-server
|
||||
fi
|
||||
ssh-keygen -A
|
||||
mkdir -p /run/sshd
|
||||
fi
|
||||
|
||||
# === 第三步:运行你的脚本 ===
|
||||
echo "Running init script..."
|
||||
./init.sh --user=root --port=2222 --key-raw="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPQQDejyTCPJO3Jyw5UX9jmojb/zjgcqVuRO28fmpWU5" --no-update --bbr --delay-restart --yes --strict
|
||||
|
||||
# === 第四步:验证结果 ===
|
||||
if grep -q "BEGIN SERVER-INIT MANAGED BLOCK" /etc/ssh/sshd_config; then
|
||||
echo "✅ SUCCESS: Config block injected."
|
||||
else
|
||||
echo "❌ FAIL: Config block missing."
|
||||
exit 1
|
||||
fi
|
||||
'
|
||||
Reference in new issue
Block a user