refactor(docker): remove MIRROR branching, use multi-baseurl failover

- drop ARG MIRROR / MIRROR_HOLDER sed injection across all Dockerfiles
- modify_yum_source.sh: EL5/6 use 4x HTTP centos-vault + 5x HTTP epel
  (ftp.iij, mirrors.aliyun, ftp.yandex, ftp.pasteur / sindad, debian.sbor)
  to avoid TLS/302 on Python2.4; EL7 keep 2x HTTPS vault + 2x epel
- modify_dnf_source.pl: replace single mirror holder with @mirrors array
  (vault.centos.org, mirrors.ustc, mirrors.aliyun) emitting multi baseurl
- Dockerfile.centos-stream: EL9 now unconditional perl, EL8 vault direct
- workflows/README: drop MIRROR docs and build-args
- shfmt fix docker_compile.sh (tabs)
This commit is contained in:
boypt
2026-08-21 10:12:41 +08:00
parent e1da586e03
commit 464f44b1ed
8 changed files with 57 additions and 86 deletions

View File

@@ -19,27 +19,22 @@ jobs:
- tag_suffix: el5
dockerfile: ./docker/Dockerfile.centos5
build_args: |
MIRROR=0
- tag_suffix: el6
dockerfile: ./docker/Dockerfile.centos
build_args: |
VERSION_NUM=6
MIRROR=0
- tag_suffix: el7
dockerfile: ./docker/Dockerfile.centos
build_args: |
VERSION_NUM=7
MIRROR=0
- tag_suffix: el8
dockerfile: ./docker/Dockerfile.centos-stream
build_args: |
VERSION_NUM=8
MIRROR=0
- tag_suffix: el9
dockerfile: ./docker/Dockerfile.centos-stream
build_args: |
VERSION_NUM=9
MIRROR=0
steps:
- name: Checkout repository
@@ -86,17 +81,14 @@ jobs:
dockerfile: ./docker/Dockerfile.centos
build_args: |
VERSION_NUM=7
MIRROR=0
- tag_suffix: aarch64_el8
dockerfile: ./docker/Dockerfile.centos-stream
build_args: |
VERSION_NUM=8
MIRROR=0
- tag_suffix: aarch64_el9
dockerfile: ./docker/Dockerfile.centos-stream
build_args: |
VERSION_NUM=9
MIRROR=0
steps:
- name: Checkout repository

View File

@@ -1,7 +1,6 @@
ARG VERSION_NUM="7"
FROM centos:$VERSION_NUM
ARG VERSION_NUM
ARG MIRROR=0
LABEL Author="Rex Zhou <zrx879582094@gmail.com>"
WORKDIR /data
@@ -9,8 +8,7 @@ WORKDIR /data
# Copy all files
COPY ./docker/ /data/docker/
RUN export MIRROR="$MIRROR" && \
bash ./docker/modify_yum_source.sh && \
RUN bash ./docker/modify_yum_source.sh && \
if [ "$VERSION_NUM" = "7" ]; then \
yum install -y systemd-devel perl perl-IPC-Cmd perl-Time-Piece ;\
elif [ "$VERSION_NUM" = "6" ]; then \

View File

@@ -2,7 +2,6 @@
ARG VERSION_NUM="9"
FROM quay.io/centos/centos:stream$VERSION_NUM
ARG VERSION_NUM
ARG MIRROR=0
LABEL Author="Rex Zhou <zrx879582094@gmail.com>"
WORKDIR /data
@@ -12,20 +11,15 @@ COPY ./docker/ /data/docker/
# CentOS 8 stream had NO valid mirrors.
RUN if [ "$VERSION_NUM" = "8" ]; then \
MIRROR_URL="https://vault.centos.org" && \
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e "s|^#baseurl=http://mirror.centos.org/\$contentdir|baseurl=$MIRROR_URL|g" \
-e "s|^#baseurl=http://mirror.centos.org/\$contentdir|baseurl=https://vault.centos.org|g" \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo && \
yum install -y perl 'dnf-command(config-manager)' && \
yum config-manager --set-enabled powertools; \
else \
if [ "$MIRROR" != "0" ]; then \
MIRROR_URL="https://mirrors.ustc.edu.cn" && \
sed -i "s|MIRROR_HOLDER|$MIRROR_URL/centos-stream|" /data/docker/modify_dnf_source.pl && \
yum install -y perl && \
perl /data/docker/modify_dnf_source.pl /etc/yum.repos.d/*.repo; \
fi; \
yum install -y perl && \
perl /data/docker/modify_dnf_source.pl /etc/yum.repos.d/*.repo; \
fi && \
yum clean all && yum makecache && \
yum install -y wget autoconf automake gcc make perl rpm-build pam-devel krb5-devel zlib-devel openssl-devel systemd-devel e2fsprogs-devel && \

View File

@@ -1,12 +1,10 @@
FROM centos:5 AS builder
ARG MIRROR=1
WORKDIR /data
COPY ./docker/*.sh /data/docker/
COPY ./downloads/perl* /data/
RUN export MIRROR="$MIRROR" && \
bash ./docker/modify_yum_source.sh && \
RUN bash ./docker/modify_yum_source.sh && \
yum install -y gcc44 make
RUN mkdir -p perl && tar xfz perl-*.tar.gz --strip-components=1 -C perl && pushd perl && \
@@ -16,14 +14,12 @@ RUN rm -rf perl-*.tar.gz perl
FROM centos:5
ARG MIRROR=1
ENV PATH=/usr/local/perl/bin:$PATH
WORKDIR /data
COPY --from=builder /usr/local/perl /usr/local/perl
COPY ./docker/*.sh /data/docker/
RUN export MIRROR="$MIRROR" && \
bash ./docker/modify_yum_source.sh && \
RUN bash ./docker/modify_yum_source.sh && \
yum install -y gcc44 autoconf automake make rpm-build setarch pam-devel krb5-devel zlib-devel && \
sed 's|]$|-i386]|;s|\$basearch|i386|g' /etc/yum.repos.d/CentOS-Base.repo > /etc/yum.repos.d/CentOS-Base-i386.repo && \
yum makecache && \

View File

@@ -34,7 +34,7 @@ Choose only the platforms you need and run the corresponding commands.
```bash
# Build Docker image
docker build -t elssh:el5 -f ./docker/Dockerfile.centos5 --build-arg MIRROR=0 .
docker build -t elssh:el5 -f ./docker/Dockerfile.centos5 .
# Build 64-bit packages (recommended)
docker run --rm -v .:/data -e "M32=0" elssh:el5
@@ -46,14 +46,14 @@ docker run --rm -v .:/data -e "M32=1" elssh:el5
#### For EL6 (CentOS 6)
```bash
docker build -t elssh:el6 -f ./docker/Dockerfile.centos --build-arg VERSION_NUM=6 --build-arg MIRROR=0 .
docker build -t elssh:el6 -f ./docker/Dockerfile.centos --build-arg VERSION_NUM=6 .
docker run --rm -v .:/data elssh:el6
```
#### For EL7 (CentOS 7)
```bash
docker build -t elssh:el7 -f ./docker/Dockerfile.centos --build-arg VERSION_NUM=7 --build-arg MIRROR=0 .
docker build -t elssh:el7 -f ./docker/Dockerfile.centos --build-arg VERSION_NUM=7 .
docker run --rm -v .:/data elssh:el7
```
@@ -62,21 +62,21 @@ docker run --rm -v .:/data elssh:el7
Reuse the EL7 image and pass `UOS20=1` to enable the kernel-panic fix in `sshd.c` and prefix `PKGREL` with `uos20-` (so the resulting RPMs are distinguishable from the standard build).
```bash
docker build -t elssh:el7 -f ./docker/Dockerfile.centos --build-arg VERSION_NUM=7 --build-arg MIRROR=0 .
docker build -t elssh:el7 -f ./docker/Dockerfile.centos --build-arg VERSION_NUM=7 .
docker run --rm -v .:/data -e "UOS20=1" elssh:el7
```
#### For EL8 (CentOS 8 / RHEL 8 / Rocky 8 / AlmaLinux 8)
```bash
docker build -t elssh:el8 -f ./docker/Dockerfile.centos-stream --build-arg VERSION_NUM=8 --build-arg MIRROR=0 .
docker build -t elssh:el8 -f ./docker/Dockerfile.centos-stream --build-arg VERSION_NUM=8 .
docker run --rm -v .:/data elssh:el8
```
#### For EL9 (CentOS Stream 9 / RHEL 9 / Rocky 9 / AlmaLinux 9)
```bash
docker build -t elssh:el9 -f ./docker/Dockerfile.centos-stream --build-arg VERSION_NUM=9 --build-arg MIRROR=0 .
docker build -t elssh:el9 -f ./docker/Dockerfile.centos-stream --build-arg VERSION_NUM=9 .
docker run --rm -v .:/data elssh:el9
```
@@ -88,8 +88,7 @@ docker run --rm -v .:/data elssh:el9
docker build -t elssh_aarch64:el8 \
--platform linux/arm64 \
-f ./docker/Dockerfile.centos-stream \
--build-arg VERSION_NUM=8 \
--build-arg MIRROR=0 .
--build-arg VERSION_NUM=8 .
docker run --rm -v .:/data --platform linux/arm64 elssh_aarch64:el8
```
@@ -100,8 +99,7 @@ docker run --rm -v .:/data --platform linux/arm64 elssh_aarch64:el8
docker build -t elssh_aarch64:el9 \
--platform linux/arm64 \
-f ./docker/Dockerfile.centos-stream \
--build-arg VERSION_NUM=9 \
--build-arg MIRROR=0 .
--build-arg VERSION_NUM=9 .
docker run --rm -v .:/data --platform linux/arm64 elssh_aarch64:el9
```
@@ -110,17 +108,12 @@ docker run --rm -v .:/data --platform linux/arm64 elssh_aarch64:el9
| Argument | Values | Description |
|-------------------|--------|-----------|
| `MIRROR` | 0 or 1 | Set to `1` if you are in China and want to use faster domestic mirrors |
| `VERSION_NUM` | 6,7,8,9| Specifies the target EL version (used in most Dockerfiles) |
| `M32` (EL5 only) | 0 or 1 | `0` = 64-bit, `1` = 32-bit |
| `UOS20` | 0 or 1 | `1` = build the UOS 20 variant (EL7 image); enables the kernel-panic patch and prefixes `PKGREL` with `uos20.` |
> Note: Amazon Linux / openEuler / Rocky Linux 的独立 Dockerfile 已合并至通用 EL 镜像(通过 glibc 兼容复用 EL8/EL9不再单独维护。
**Example for users in China:**
Add `--build-arg MIRROR=1` to the `docker build` command.
## Output Location
After each successful build, the RPM packages are copied to:
@@ -153,10 +146,10 @@ Each subdirectory contains the generated `.rpm` files (including debuginfo if av
```bash
env ALL=1 ./pullsrc.sh
docker build -t elssh:el8 -f ./docker/Dockerfile.centos-stream --build-arg VERSION_NUM=8 --build-arg MIRROR=0 .
docker build -t elssh:el8 -f ./docker/Dockerfile.centos-stream --build-arg VERSION_NUM=8 .
docker run --rm -v .:/data elssh:el8
docker build -t elssh:el9 -f ./docker/Dockerfile.centos-stream --build-arg VERSION_NUM=9 --build-arg MIRROR=0 .
docker build -t elssh:el9 -f ./docker/Dockerfile.centos-stream --build-arg VERSION_NUM=9 .
docker run --rm -v .:/data elssh:el9
```
@@ -165,13 +158,12 @@ docker run --rm -v .:/data elssh:el9
```bash
env ALL=1 ./pullsrc.sh
docker build -t elssh_aarch64:el9 --platform linux/arm64 -f ./docker/Dockerfile.centos-stream --build-arg VERSION_NUM=9 --build-arg MIRROR=0 .
docker build -t elssh_aarch64:el9 --platform linux/arm64 -f ./docker/Dockerfile.centos-stream --build-arg VERSION_NUM=9 .
docker run --rm -v .:/data --platform linux/arm64 elssh_aarch64:el9
```
## Troubleshooting
- **Slow downloads**: Use `MIRROR=1`
- **Permission issues**: Run `chown -R $USER output/` after building
- **Docker build fails on first run**: This is normal — it needs to download base images and dependencies
- **ARM64 builds**: Requires a machine with ARM64 support or Docker Buildx multi-platform enabled

View File

@@ -4,16 +4,16 @@ mkdir -p $DOCKER_BUILD_DIR
ELDIR=$(./compile.sh GETEL)
if ! rpm -q openssl-devel; then
WITH_OPENSSL=2
WITH_OPENSSL=2
fi
OPENSSLVER=$(rpm -q openssl --qf "%{VERSION}" | cut -d. -f1)
if [[ ${WITH_OPENSSL+x} == "" ]]; then
if [[ $OPENSSLVER -ge 3 ]]; then
export WITH_OPENSSL=1
else
export WITH_OPENSSL=2
fi
if [[ $OPENSSLVER -ge 3 ]]; then
export WITH_OPENSSL=1
else
export WITH_OPENSSL=2
fi
fi
cp -r $ELDIR $DOCKER_BUILD_DIR

View File

@@ -4,7 +4,11 @@ use strict;
use warnings;
use autodie;
my $mirrors = 'MIRROR_HOLDER';
my @mirrors = (
'https://vault.centos.org/centos-stream',
'https://mirrors.ustc.edu.cn/centos-stream',
'https://mirrors.aliyun.com/centos-stream',
);
if (@ARGV < 1) {
die "Usage: $0 <filename1> <filename2> ...\n";
@@ -25,10 +29,15 @@ while (my $filename = shift @ARGV) {
$repo =~ s/^\s+|\s+$//g;
($arch = defined $arch ? lc($arch) : '') =~ s/^\s+|\s+$//g;
my $path;
if ($repo =~ /^Extras/) {
$_ .= "baseurl=${mirrors}/SIGs/\$releasever-stream/extras" . ($arch eq 'source' ? "/${arch}/" : "/\$basearch/") . "extras-common\n";
$path = "SIGs/\$releasever-stream/extras" . ($arch eq 'source' ? "/${arch}/" : "/\$basearch/") . "extras-common";
} else {
$_ .= "baseurl=${mirrors}/\$releasever-stream/$repo" . ($arch eq 'source' ? "/" : "/\$basearch/") . ($arch ne '' ? "${arch}/tree/" : "os") . "\n";
$path = "\$releasever-stream/$repo" . ($arch eq 'source' ? "/" : "/\$basearch/") . ($arch ne '' ? "${arch}/tree/" : "os");
}
for my $mirror (@mirrors) {
$_ .= "baseurl=${mirror}/${path}\n";
}
}

View File

@@ -1,6 +1,8 @@
#!/bin/bash
# Mirror switching for CentOS 5/6/7 yum repositories.
# Set MIRROR=0 to use official mirrors, otherwise use Chinese mirrors (default).
# Rewrite yum repository baseurls to use multiple (failover) mirrors.
# yum/dnf try each baseurl in order, so listing several provides resilience.
# EL5/EL6 use plain HTTP mirrors only (Python 2.4 / old curl cannot handle
# HTTPS redirects); EL7 keeps HTTPS mirrors.
RELEASE_VER=$(rpm --eval '%{?dist}')
[ -z "$RELEASE_VER" ] && RELEASE_VER=".el5"
@@ -9,40 +11,23 @@ RELEASE_VER=$(rpm --eval '%{?dist}')
ALTARCH=""
[ "$(uname -m)" = "aarch64" ] && ALTARCH="/altarch"
# CentOS 5 does not support HTTPS, always use archive.kernel.org over HTTP
if [ "$RELEASE_VER" != ".el5" ]; then
if [ "$MIRROR" != "0" ]; then
CENTOS_MIRROR="https://mirrors.ustc.edu.cn/centos-vault"
EPEL_MIRROR="http://mirrors.aliyun.com/epel-archive"
else
CENTOS_MIRROR="https://archive.kernel.org/centos-vault"
EPEL_MIRROR="http://archives.fedoraproject.org/pub/archive/epel"
fi
else
# EL5 Python 2.4 cannot handle HTTPS redirects, use HTTP mirrors only
if [ "$MIRROR" != "0" ]; then
CENTOS_MIRROR="http://archive.kernel.org/centos-vault"
EPEL_MIRROR="http://mirrors.aliyun.com/epel-archive"
else
CENTOS_MIRROR="http://archive.kernel.org/centos-vault"
EPEL_MIRROR="http://mirrors.aliyun.com/epel-archive"
fi
fi
disable_fastestmirror() {
sed -e 's|enabled=1|enabled=0|' -i /etc/yum/pluginconf.d/fastestmirror.conf 2>/dev/null || true
}
modify_el7() {
disable_fastestmirror
local baseurl="baseurl=https://archive.kernel.org/centos-vault${ALTARCH}/7.9.2009/\nbaseurl=https://mirrors.ustc.edu.cn/centos-vault${ALTARCH}/7.9.2009/"
local alturl="baseurl=https://archive.kernel.org/centos-vault/altarch/7.9.2009/\nbaseurl=https://mirrors.ustc.edu.cn/centos-vault/altarch/7.9.2009/"
local epelurl="baseurl=http://archives.fedoraproject.org/pub/archive/epel/7/\nbaseurl=http://mirrors.aliyun.com/epel-archive/7/"
sed -e '/^mirrorlist=/s|^|#|g' \
-e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever/|baseurl=${CENTOS_MIRROR}${ALTARCH}/7.9.2009/|g" \
-e "s|^#baseurl=http://mirror.centos.org/altarch/\$releasever/|baseurl=${CENTOS_MIRROR}/altarch/7.9.2009/|g" \
-e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever/|${baseurl}|g" \
-e "s|^#baseurl=http://mirror.centos.org/altarch/\$releasever/|${alturl}|g" \
-i.bak /etc/yum.repos.d/CentOS-*.repo
yum install -y epel-release
sed -e '/^mirrorlist=/s|^|#|g' \
-e 's|^metalink|#metalink|' \
-e "s|^#baseurl=http://download.fedoraproject.org/pub/epel/7/|baseurl=${EPEL_MIRROR}/7/|g" \
-e "s|^#baseurl=http://download.fedoraproject.org/pub/epel/7/|${epelurl}|g" \
-i.bak /etc/yum.repos.d/epel*.repo 2>/dev/null || true
rm -rf /var/cache/yum/
yum makecache fast
@@ -50,15 +35,18 @@ modify_el7() {
modify_el6() {
disable_fastestmirror
local baseurl="baseurl=http://ftp.iij.ad.jp/pub/linux/centos-vault/6.10\nbaseurl=http://mirrors.aliyun.com/centos-vault/6.10\nbaseurl=http://ftp.yandex.ru/centos/6.10\nbaseurl=http://ftp.pasteur.fr/mirrors/centos-vault/6.10"
local sclourl="baseurl=http://ftp.iij.ad.jp/pub/linux/centos-vault/6.10/sclo\nbaseurl=http://mirrors.aliyun.com/centos-vault/6.10/sclo\nbaseurl=http://ftp.yandex.ru/centos/6.10/sclo\nbaseurl=http://ftp.pasteur.fr/mirrors/centos-vault/6.10/sclo"
local epelurl="baseurl=http://mirrors.aliyun.com/epel-archive/6/\nbaseurl=http://ftp.iij.ad.jp/pub/linux/Fedora/archive/epel/6/\nbaseurl=http://mirrors.sindad.cloud/epel-archive/6/\nbaseurl=http://ftp.yandex.ru/epel-archive/6/\nbaseurl=http://debian.sbor.net/epel-archive/6/"
sed -e "s|^mirrorlist=|#mirrorlist=|g" \
-e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=${CENTOS_MIRROR}/6.10|g" \
-e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=${CENTOS_MIRROR}/6.10|g" \
-e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|${baseurl}|g" \
-e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|${baseurl}|g" \
-i.bak /etc/yum.repos.d/CentOS-*.repo
yum install -y epel-release centos-release-scl-rh centos-release-scl
sed -e "s|^mirrorlist=|#mirrorlist=|g" \
-e 's|^metalink|#metalink|' \
-e "s|^# *baseurl=http://mirror.centos.org/centos/6/sclo|baseurl=${CENTOS_MIRROR}/6.10/sclo|g" \
-e "s|^#baseurl=http://download.fedoraproject.org/pub/epel/6/|baseurl=${EPEL_MIRROR}/6/|g" \
-e "s|^# *baseurl=http://mirror.centos.org/centos/6/sclo|${sclourl}|g" \
-e "s|^#baseurl=http://download.fedoraproject.org/pub/epel/6/|${epelurl}|g" \
-i.bak /etc/yum.repos.d/epel*.repo /etc/yum.repos.d/*scl*.repo 2>/dev/null || true
rm -rf /var/cache/yum/
yum makecache fast
@@ -66,14 +54,16 @@ modify_el6() {
modify_el5() {
disable_fastestmirror
local baseurl="baseurl=http://ftp.iij.ad.jp/pub/linux/centos-vault/5.11\nbaseurl=http://mirrors.aliyun.com/centos-vault/5.11\nbaseurl=http://ftp.yandex.ru/centos/5.11\nbaseurl=http://ftp.pasteur.fr/mirrors/centos-vault/5.11"
local epelurl="baseurl=http://mirrors.aliyun.com/epel-archive/5/\$basearch\nbaseurl=http://ftp.iij.ad.jp/pub/linux/Fedora/archive/epel/5/\$basearch\nbaseurl=http://mirrors.sindad.cloud/epel-archive/5/\$basearch\nbaseurl=http://ftp.yandex.ru/epel-archive/5/\$basearch\nbaseurl=http://debian.sbor.net/epel-archive/5/\$basearch"
sed -e "s|^mirrorlist=|#mirrorlist=|g" \
-e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=${CENTOS_MIRROR}/5.11|g" \
-e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=${CENTOS_MIRROR}/5.11|g" \
-e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|${baseurl}|g" \
-e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|${baseurl}|g" \
-i.bak /etc/yum.repos.d/*.repo
yum install -y epel-release
sed -e "/^mirrorlist/s|^|#|g" \
-e 's|^metalink|#metalink|' \
-e "s|^#baseurl=.\+\$|baseurl=${EPEL_MIRROR}/5/\$basearch|g" \
-e "s|^#baseurl=.\+\$|${epelurl}|g" \
-i.bak /etc/yum.repos.d/epel*.repo 2>/dev/null || true
rm -rf /var/cache/yum/
yum makecache