Streamlined the entrypoint script.
This commit is contained in:
@@ -51,6 +51,13 @@ RUN echo "ALL ALL=NOPASSWD:ALL" > /etc/sudoers.d/01-allow-sudo
|
|||||||
RUN git config --system user.name "ameer" && \
|
RUN git config --system user.name "ameer" && \
|
||||||
git config --system user.email "ameer@ahkhan.me"
|
git config --system user.email "ameer@ahkhan.me"
|
||||||
|
|
||||||
|
# Copy utility scripts to /bin/ for independent execution
|
||||||
|
COPY scripts/bin/configure-china-mirrors /bin/configure-china-mirrors
|
||||||
|
COPY scripts/bin/update-apt-cache /bin/update-apt-cache
|
||||||
|
COPY scripts/bin/setup-user-home /bin/setup-user-home
|
||||||
|
RUN chmod +x /bin/configure-china-mirrors /bin/update-apt-cache /bin/setup-user-home
|
||||||
|
|
||||||
|
# Copy entrypoint script to root
|
||||||
COPY scripts/entrypoint.sh /entrypoint.sh
|
COPY scripts/entrypoint.sh /entrypoint.sh
|
||||||
RUN chmod +x /entrypoint.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
|
|
||||||
|
|||||||
47
scripts/bin/configure-china-mirrors
Normal file
47
scripts/bin/configure-china-mirrors
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Configure Chinese mirrors (Aliyun) for apt, pip, and npm
|
||||||
|
# Can be called independently or during container initialization
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "Configuring Chinese mirrors (Aliyun) for apt, pip, and npm..."
|
||||||
|
|
||||||
|
# Replace Ubuntu sources with Aliyun mirror
|
||||||
|
if [[ -f /etc/apt/sources.list.d/ubuntu.sources ]]; then
|
||||||
|
sudo sed -i 's|http://archive.ubuntu.com/ubuntu/|https://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list.d/ubuntu.sources
|
||||||
|
sudo sed -i 's|http://security.ubuntu.com/ubuntu/|https://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list.d/ubuntu.sources
|
||||||
|
echo "Updated Ubuntu apt sources to use Aliyun 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 Aliyun mirror
|
||||||
|
sudo mkdir -p /etc/pip
|
||||||
|
echo "[global]
|
||||||
|
index-url = https://mirrors.aliyun.com/pypi/simple/
|
||||||
|
|
||||||
|
[install]
|
||||||
|
trusted-host = mirrors.aliyun.com" | sudo tee /etc/pip/pip.conf > /dev/null
|
||||||
|
echo "Configured pip to use Aliyun mirror"
|
||||||
|
|
||||||
|
# Update apt package cache after changing mirrors
|
||||||
|
echo "Updating apt package cache from new mirrors..."
|
||||||
|
if sudo apt update; then
|
||||||
|
echo "Apt package cache updated successfully from Aliyun mirrors"
|
||||||
|
else
|
||||||
|
echo "Warning: apt update failed, but mirrors are configured"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Chinese mirrors (Aliyun) configuration completed"
|
||||||
16
scripts/bin/setup-user-home
Normal file
16
scripts/bin/setup-user-home
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Setup home directory for the current user
|
||||||
|
# Useful for attaching vscode with container
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
user_name=$(whoami)
|
||||||
|
user_home="/home/$user_name"
|
||||||
|
|
||||||
|
echo "Setting up home directory for user: $user_name"
|
||||||
|
sudo mkdir -p "$user_home"
|
||||||
|
sudo chown -R "$(id -u):$(id -g)" "$user_home"
|
||||||
|
cp -r /etc/skel/. "$user_home" 2>/dev/null || true
|
||||||
|
|
||||||
|
echo "Home directory setup completed: $user_home"
|
||||||
20
scripts/bin/update-apt-cache
Normal file
20
scripts/bin/update-apt-cache
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Update apt package cache with network check
|
||||||
|
# Can be called independently or during container initialization
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Gracefully update package lists if network is available
|
||||||
|
echo "Checking network connectivity..."
|
||||||
|
if ping -c 1 -W 5 8.8.8.8 >/dev/null 2>&1 || ping -c 1 -W 5 1.1.1.1 >/dev/null 2>&1; then
|
||||||
|
echo "Network detected, refreshing package lists..."
|
||||||
|
if sudo apt update; then
|
||||||
|
echo "Package lists updated successfully"
|
||||||
|
else
|
||||||
|
echo "Warning: apt update failed despite network connectivity"
|
||||||
|
echo "Falling back to cached package lists"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "No network connectivity detected, using cached package lists"
|
||||||
|
fi
|
||||||
@@ -1,58 +1,13 @@
|
|||||||
#!/usr/bin/env bash
|
#!/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
|
# Run mirror configuration early, before any apt/pip operations
|
||||||
configure_china_mirrors
|
if [[ "$USE_CHINA_MIRRORS" == "1" || "${USE_CHINA_MIRRORS,,}" == "true" ]]; then
|
||||||
|
/bin/configure-china-mirrors
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update apt package cache if requested
|
||||||
if [[ "$UPDATE_APT" == "1" || "${UPDATE_APT,,}" == "true" ]]; then
|
if [[ "$UPDATE_APT" == "1" || "${UPDATE_APT,,}" == "true" ]]; then
|
||||||
# Gracefully update package lists if network is available
|
/bin/update-apt-cache
|
||||||
echo "Checking network connectivity..."
|
|
||||||
if ping -c 1 -W 5 8.8.8.8 >/dev/null 2>&1 || ping -c 1 -W 5 1.1.1.1 >/dev/null 2>&1; then
|
|
||||||
echo "Network detected, refreshing package lists..."
|
|
||||||
if sudo apt update; then
|
|
||||||
echo "Package lists updated successfully"
|
|
||||||
else
|
|
||||||
echo "Warning: apt update failed despite network connectivity"
|
|
||||||
echo "Falling back to cached package lists"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "No network connectivity detected, using cached package lists"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Global variables to track background processes
|
# Global variables to track background processes
|
||||||
@@ -112,12 +67,8 @@ trap 'term_handler' SIGTERM SIGINT SIGQUIT
|
|||||||
# Test signal handling is working
|
# Test signal handling is working
|
||||||
echo "Signal handlers registered. Testing with kill -0..."
|
echo "Signal handlers registered. Testing with kill -0..."
|
||||||
|
|
||||||
# setup home directory for the current user. It is useful for attaching vscode with container.
|
# Setup home directory for the current user
|
||||||
user_name=$(whoami)
|
/bin/setup-user-home
|
||||||
user_home="/home/$user_name"
|
|
||||||
sudo mkdir -p "$user_home"
|
|
||||||
sudo chown -R "$(id -u):$(id -g)" "$user_home"
|
|
||||||
cp -r /etc/skel/. "$user_home" 2>/dev/null || true
|
|
||||||
|
|
||||||
if [[ $LOG_FILE != "/dev/null" ]]; then
|
if [[ $LOG_FILE != "/dev/null" ]]; then
|
||||||
sudo touch "$LOG_FILE"
|
sudo touch "$LOG_FILE"
|
||||||
|
|||||||
Reference in New Issue
Block a user