Added option to configure china's internal mirrors.
This commit is contained in:
@@ -47,6 +47,10 @@ RUN mkdir -p /var/run/sshd
|
||||
# Allow non-root users to run sudo command without password
|
||||
RUN echo "ALL ALL=NOPASSWD:ALL" > /etc/sudoers.d/01-allow-sudo
|
||||
|
||||
# Set system-wide git configs
|
||||
RUN git config --system user.name "ameer" && \
|
||||
git config --system user.email "ameer@ahkhan.me"
|
||||
|
||||
COPY scripts/entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
|
||||
@@ -1,5 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Configure Chinese mirrors if USE_CHINA_MIRRORS is set
|
||||
configure_china_mirrors() {
|
||||
if [[ "$USE_CHINA_MIRRORS" == "1" || "${USE_CHINA_MIRRORS,,}" == "true" ]]; then
|
||||
echo "Configuring Chinese mirrors for apt and pip..."
|
||||
|
||||
# Replace Ubuntu sources
|
||||
if [[ -f /etc/apt/sources.list.d/ubuntu.sources ]]; then
|
||||
sudo sed -i 's|http://archive.ubuntu.com/ubuntu/|https://mirrors.tuna.tsinghua.edu.cn/ubuntu/|g' /etc/apt/sources.list.d/ubuntu.sources
|
||||
sudo sed -i 's|http://security.ubuntu.com/ubuntu/|https://mirrors.tuna.tsinghua.edu.cn/ubuntu/|g' /etc/apt/sources.list.d/ubuntu.sources
|
||||
echo "Updated Ubuntu apt sources to use Chinese mirrors"
|
||||
fi
|
||||
|
||||
# Configure npm registry to use Chinese mirror (npmmirror.com is the recommended mirror)
|
||||
if command -v npm &> /dev/null; then
|
||||
npm config set registry https://registry.npmmirror.com/
|
||||
echo "Configured npm registry to use Chinese mirror (registry.npmmirror.com)"
|
||||
fi
|
||||
# Also set system-wide npm config for all users
|
||||
sudo mkdir -p /etc/npm
|
||||
echo "registry=https://registry.npmmirror.com/" | sudo tee /etc/npm/npmrc > /dev/null
|
||||
# Set for root user as well (for when npm is installed later)
|
||||
sudo mkdir -p /root/.npm
|
||||
echo "registry=https://registry.npmmirror.com/" | sudo tee /root/.npmrc > /dev/null
|
||||
echo "Configured npm registry to use Chinese mirror (registry.npmmirror.com)"
|
||||
|
||||
# Configure pip to use Chinese mirrors
|
||||
sudo mkdir -p /etc/pip
|
||||
echo "[global]
|
||||
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
trusted-host = pypi.tuna.tsinghua.edu.cn" | sudo tee /etc/pip/pip.conf > /dev/null
|
||||
echo "Configured pip to use Chinese mirrors"
|
||||
|
||||
echo "Chinese mirrors configuration completed"
|
||||
fi
|
||||
}
|
||||
|
||||
# Run mirror configuration early, before any apt/pip operations
|
||||
configure_china_mirrors
|
||||
|
||||
if [[ "$UPDATE_APT" == "1" || "${UPDATE_APT,,}" == "true" ]]; then
|
||||
# Gracefully update package lists if network is available
|
||||
echo "Checking network connectivity..."
|
||||
|
||||
Reference in New Issue
Block a user