From 0b346763364bf75c31ee0bccf0e77f02bc78f718 Mon Sep 17 00:00:00 2001 From: zuohuadong Date: Thu, 26 Jun 2025 10:24:14 +0800 Subject: [PATCH 1/6] chore (opencloud) fix docker install --- packages/server/src/setup/server-setup.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/server/src/setup/server-setup.ts b/packages/server/src/setup/server-setup.ts index a5c760fbe..eff17fd37 100644 --- a/packages/server/src/setup/server-setup.ts +++ b/packages/server/src/setup/server-setup.ts @@ -419,14 +419,26 @@ if ! [ -x "$(command -v docker)" ]; then systemctl enable docker >/dev/null 2>&1 ;; "opencloudos") - dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo >/dev/null 2>&1 - dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin >/dev/null 2>&1 + # Special handling for OpenCloud OS + echo " - Installing Docker for OpenCloud OS..." + yum install -y docker >/dev/null 2>&1 if ! [ -x "$(command -v docker)" ]; then echo " - Docker could not be installed automatically. Please visit https://docs.docker.com/engine/install/ and install Docker manually to continue." exit 1 fi - systemctl start docker >/dev/null 2>&1 + + # Remove --live-restore parameter from Docker configuration if it exists + if [ -f "/etc/sysconfig/docker" ]; then + echo " - Removing --live-restore parameter from Docker configuration..." + sed -i 's/--live-restore[^[:space:]]*//' /etc/sysconfig/docker >/dev/null 2>&1 + sed -i 's/--live-restore//' /etc/sysconfig/docker >/dev/null 2>&1 + # Clean up any double spaces that might be left + sed -i 's/ */ /g' /etc/sysconfig/docker >/dev/null 2>&1 + fi + systemctl enable docker >/dev/null 2>&1 + systemctl start docker >/dev/null 2>&1 + echo " - Docker configured for OpenCloud OS" ;; "alpine") apk add docker docker-cli-compose >/dev/null 2>&1 From 207fe6f477c8a28c89e1b6f40871cdf72e857811 Mon Sep 17 00:00:00 2001 From: zuohuadong Date: Thu, 26 Jun 2025 10:32:23 +0800 Subject: [PATCH 2/6] feat(swap): On hosts with less than 2G of memory, increase swap space to prevent installation failure. --- packages/server/src/setup/server-setup.ts | 97 ++++++++++++++++++++--- 1 file changed, 86 insertions(+), 11 deletions(-) diff --git a/packages/server/src/setup/server-setup.ts b/packages/server/src/setup/server-setup.ts index eff17fd37..518045f21 100644 --- a/packages/server/src/setup/server-setup.ts +++ b/packages/server/src/setup/server-setup.ts @@ -141,38 +141,41 @@ ${validatePorts()} -echo -e "3. Installing RClone. " +echo -e "3. Checking memory and configuring swap if needed. " +${checkMemoryAndSetupSwap()} + +echo -e "4. Installing RClone. " ${installRClone()} -echo -e "4. Installing Docker. " +echo -e "5. Installing Docker. " ${installDocker()} -echo -e "5. Setting up Docker Swarm" +echo -e "6. Setting up Docker Swarm" ${setupSwarm()} -echo -e "6. Setting up Network" +echo -e "7. Setting up Network" ${setupNetwork()} -echo -e "7. Setting up Directories" +echo -e "8. Setting up Directories" ${setupMainDirectory()} ${setupDirectories()} -echo -e "8. Setting up Traefik" +echo -e "9. Setting up Traefik" ${createTraefikConfig()} -echo -e "9. Setting up Middlewares" +echo -e "10. Setting up Middlewares" ${createDefaultMiddlewares()} -echo -e "10. Setting up Traefik Instance" +echo -e "11. Setting up Traefik Instance" ${createTraefikInstance()} -echo -e "11. Installing Nixpacks" +echo -e "12. Installing Nixpacks" ${installNixpacks()} -echo -e "12. Installing Buildpacks" +echo -e "13. Installing Buildpacks" ${installBuildpacks()} -echo -e "13. Installing Railpack" +echo -e "14. Installing Railpack" ${installRailpack()} `; @@ -628,3 +631,75 @@ const installBuildpacks = () => ` echo "Buildpacks version $BUILDPACKS_VERSION installed ✅" fi `; + +const checkMemoryAndSetupSwap = () => ` + # Check available memory in MB + MEMORY_MB=$(free -m | awk 'NR==2{print $2}') + MEMORY_GB=$((MEMORY_MB / 1024)) + + echo " - Detected memory: ${MEMORY_MB}MB (${MEMORY_GB}GB)" + + # If memory is less than 2GB (2048MB), setup swap + if [ "$MEMORY_MB" -lt 2048 ]; then + echo " - Memory is less than 2GB, checking swap configuration..." + + # Check if swap is already enabled + SWAP_TOTAL=$(free -m | awk 'NR==3{print $2}') + + if [ "$SWAP_TOTAL" -gt 0 ]; then + echo " - Swap is already enabled (${SWAP_TOTAL}MB) ✅" + else + echo " - No swap detected. Setting up swap file..." + + # Calculate swap size (4GB for systems with less than 2GB RAM) + SWAP_SIZE="4G" + SWAP_FILE="/swapfile" + + # Check if swap file already exists + if [ -f "$SWAP_FILE" ]; then + echo " - Swap file already exists, skipping creation" + else + # Create swap file + echo " - Creating ${SWAP_SIZE} swap file at ${SWAP_FILE}..." + + # Use fallocate if available, otherwise use dd + if command -v fallocate >/dev/null 2>&1; then + fallocate -l $SWAP_SIZE $SWAP_FILE >/dev/null 2>&1 + else + dd if=/dev/zero of=$SWAP_FILE bs=1M count=4096 >/dev/null 2>&1 + fi + + if [ $? -eq 0 ]; then + # Set correct permissions + chmod 600 $SWAP_FILE + + # Setup swap + mkswap $SWAP_FILE >/dev/null 2>&1 + swapon $SWAP_FILE >/dev/null 2>&1 + + # Add to fstab for persistence + if ! grep -q "$SWAP_FILE" /etc/fstab; then + echo "$SWAP_FILE none swap sw 0 0" >> /etc/fstab + fi + + # Verify swap is active + NEW_SWAP_TOTAL=$(free -m | awk 'NR==3{print $2}') + if [ "$NEW_SWAP_TOTAL" -gt 0 ]; then + echo " - Swap file created and activated successfully (${NEW_SWAP_TOTAL}MB) ✅" + + # Optimize swappiness for server use + echo "vm.swappiness=10" >> /etc/sysctl.conf + sysctl vm.swappiness=10 >/dev/null 2>&1 + echo " - Swap swappiness set to 10 for optimal server performance ✅" + else + echo " - Failed to activate swap file ❌" + fi + else + echo " - Failed to create swap file ❌" + fi + fi + fi + else + echo " - Memory is sufficient (≥2GB), swap configuration not required ✅" + fi +`; From 475c45245140ff30c208376e3955bb5d95fd6532 Mon Sep 17 00:00:00 2001 From: zuohuadong Date: Thu, 26 Jun 2025 16:05:56 +0800 Subject: [PATCH 3/6] chore(*): use dnf --- packages/server/src/setup/server-setup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/setup/server-setup.ts b/packages/server/src/setup/server-setup.ts index 518045f21..bfd43bed3 100644 --- a/packages/server/src/setup/server-setup.ts +++ b/packages/server/src/setup/server-setup.ts @@ -424,7 +424,7 @@ if ! [ -x "$(command -v docker)" ]; then "opencloudos") # Special handling for OpenCloud OS echo " - Installing Docker for OpenCloud OS..." - yum install -y docker >/dev/null 2>&1 + dnf install -y docker >/dev/null 2>&1 if ! [ -x "$(command -v docker)" ]; then echo " - Docker could not be installed automatically. Please visit https://docs.docker.com/engine/install/ and install Docker manually to continue." exit 1 From 0c861585ed6c123e94487bf25aead7bb02a3429e Mon Sep 17 00:00:00 2001 From: zuohuadong Date: Tue, 1 Jul 2025 12:19:39 +0800 Subject: [PATCH 4/6] =?UTF-8?q?chore(setup)=EF=BC=9AIncrease=20interactive?= =?UTF-8?q?=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/src/setup/server-setup.ts | 49 ++++++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/packages/server/src/setup/server-setup.ts b/packages/server/src/setup/server-setup.ts index bfd43bed3..5adcf0f38 100644 --- a/packages/server/src/setup/server-setup.ts +++ b/packages/server/src/setup/server-setup.ts @@ -75,6 +75,10 @@ SYS_ARCH=$(uname -m) CURRENT_USER=$USER echo "Installing requirements for: OS: $OS_TYPE" + +# Environment variables for automation: +# DOKPLOY_AUTO_SWAP=true - Automatically create swap file for low memory systems without prompting + if [ $EUID != 0 ]; then echo "Please run this script as root or with sudo ❌" exit @@ -639,7 +643,7 @@ const checkMemoryAndSetupSwap = () => ` echo " - Detected memory: ${MEMORY_MB}MB (${MEMORY_GB}GB)" - # If memory is less than 2GB (2048MB), setup swap + # If memory is less than 2GB (2048MB), offer to setup swap if [ "$MEMORY_MB" -lt 2048 ]; then echo " - Memory is less than 2GB, checking swap configuration..." @@ -649,7 +653,48 @@ const checkMemoryAndSetupSwap = () => ` if [ "$SWAP_TOTAL" -gt 0 ]; then echo " - Swap is already enabled (${SWAP_TOTAL}MB) ✅" else - echo " - No swap detected. Setting up swap file..." + echo " - No swap detected." + echo "" + echo "⚠️ WARNING: Your system has less than 2GB of memory (${MEMORY_MB}MB)." + echo " This may cause issues when building large applications or running multiple containers." + echo " It is recommended to enable swap to improve system stability." + echo "" + + # Check for non-interactive mode or environment variable + if [ "$DOKPLOY_AUTO_SWAP" = "true" ] || [ "$DOKPLOY_AUTO_SWAP" = "1" ]; then + echo " - Auto-swap mode enabled, creating swap file automatically..." + SWAP_CHOICE="y" + elif [ ! -t 0 ]; then + # Non-interactive mode (like CI/CD), default to yes + echo " - Non-interactive mode detected, creating swap file automatically..." + SWAP_CHOICE="y" + else + # Interactive prompt for swap setup + while true; do + echo -n "Would you like to create a 4GB swap file? [Y/n]: " + read -r SWAP_CHOICE + + # Default to yes if empty input + if [ -z "$SWAP_CHOICE" ]; then + SWAP_CHOICE="y" + fi + + case "$SWAP_CHOICE" in + [Yy]* ) + echo " - Setting up swap file..." + break + ;; + [Nn]* ) + echo " - Skipping swap setup. Continuing without swap." + echo " - ⚠️ Note: You may encounter memory issues during builds." + return 0 + ;; + * ) + echo " - Please answer yes (y) or no (n)." + ;; + esac + done + fi # Calculate swap size (4GB for systems with less than 2GB RAM) SWAP_SIZE="4G" From fa7db0dc75645b25196fc022552dcbb944419161 Mon Sep 17 00:00:00 2001 From: zuohuadong Date: Wed, 2 Jul 2025 14:50:39 +0800 Subject: [PATCH 5/6] =?UTF-8?q?Revert=20"chore(setup)=EF=BC=9AIncrease=20i?= =?UTF-8?q?nteractive=20options"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 0c861585ed6c123e94487bf25aead7bb02a3429e. --- packages/server/src/setup/server-setup.ts | 49 +---------------------- 1 file changed, 2 insertions(+), 47 deletions(-) diff --git a/packages/server/src/setup/server-setup.ts b/packages/server/src/setup/server-setup.ts index 5adcf0f38..bfd43bed3 100644 --- a/packages/server/src/setup/server-setup.ts +++ b/packages/server/src/setup/server-setup.ts @@ -75,10 +75,6 @@ SYS_ARCH=$(uname -m) CURRENT_USER=$USER echo "Installing requirements for: OS: $OS_TYPE" - -# Environment variables for automation: -# DOKPLOY_AUTO_SWAP=true - Automatically create swap file for low memory systems without prompting - if [ $EUID != 0 ]; then echo "Please run this script as root or with sudo ❌" exit @@ -643,7 +639,7 @@ const checkMemoryAndSetupSwap = () => ` echo " - Detected memory: ${MEMORY_MB}MB (${MEMORY_GB}GB)" - # If memory is less than 2GB (2048MB), offer to setup swap + # If memory is less than 2GB (2048MB), setup swap if [ "$MEMORY_MB" -lt 2048 ]; then echo " - Memory is less than 2GB, checking swap configuration..." @@ -653,48 +649,7 @@ const checkMemoryAndSetupSwap = () => ` if [ "$SWAP_TOTAL" -gt 0 ]; then echo " - Swap is already enabled (${SWAP_TOTAL}MB) ✅" else - echo " - No swap detected." - echo "" - echo "⚠️ WARNING: Your system has less than 2GB of memory (${MEMORY_MB}MB)." - echo " This may cause issues when building large applications or running multiple containers." - echo " It is recommended to enable swap to improve system stability." - echo "" - - # Check for non-interactive mode or environment variable - if [ "$DOKPLOY_AUTO_SWAP" = "true" ] || [ "$DOKPLOY_AUTO_SWAP" = "1" ]; then - echo " - Auto-swap mode enabled, creating swap file automatically..." - SWAP_CHOICE="y" - elif [ ! -t 0 ]; then - # Non-interactive mode (like CI/CD), default to yes - echo " - Non-interactive mode detected, creating swap file automatically..." - SWAP_CHOICE="y" - else - # Interactive prompt for swap setup - while true; do - echo -n "Would you like to create a 4GB swap file? [Y/n]: " - read -r SWAP_CHOICE - - # Default to yes if empty input - if [ -z "$SWAP_CHOICE" ]; then - SWAP_CHOICE="y" - fi - - case "$SWAP_CHOICE" in - [Yy]* ) - echo " - Setting up swap file..." - break - ;; - [Nn]* ) - echo " - Skipping swap setup. Continuing without swap." - echo " - ⚠️ Note: You may encounter memory issues during builds." - return 0 - ;; - * ) - echo " - Please answer yes (y) or no (n)." - ;; - esac - done - fi + echo " - No swap detected. Setting up swap file..." # Calculate swap size (4GB for systems with less than 2GB RAM) SWAP_SIZE="4G" From 6fc51e02a76e660f2c1b58eb728ea50d36e0b25f Mon Sep 17 00:00:00 2001 From: zuohuadong Date: Wed, 2 Jul 2025 14:51:48 +0800 Subject: [PATCH 6/6] Revert "feat(swap): On hosts with less than 2G of memory, increase swap space to prevent installation failure." This reverts commit 207fe6f477c8a28c89e1b6f40871cdf72e857811. --- packages/server/src/setup/server-setup.ts | 97 +++-------------------- 1 file changed, 11 insertions(+), 86 deletions(-) diff --git a/packages/server/src/setup/server-setup.ts b/packages/server/src/setup/server-setup.ts index bfd43bed3..1a4554084 100644 --- a/packages/server/src/setup/server-setup.ts +++ b/packages/server/src/setup/server-setup.ts @@ -141,41 +141,38 @@ ${validatePorts()} -echo -e "3. Checking memory and configuring swap if needed. " -${checkMemoryAndSetupSwap()} - -echo -e "4. Installing RClone. " +echo -e "3. Installing RClone. " ${installRClone()} -echo -e "5. Installing Docker. " +echo -e "4. Installing Docker. " ${installDocker()} -echo -e "6. Setting up Docker Swarm" +echo -e "5. Setting up Docker Swarm" ${setupSwarm()} -echo -e "7. Setting up Network" +echo -e "6. Setting up Network" ${setupNetwork()} -echo -e "8. Setting up Directories" +echo -e "7. Setting up Directories" ${setupMainDirectory()} ${setupDirectories()} -echo -e "9. Setting up Traefik" +echo -e "8. Setting up Traefik" ${createTraefikConfig()} -echo -e "10. Setting up Middlewares" +echo -e "9. Setting up Middlewares" ${createDefaultMiddlewares()} -echo -e "11. Setting up Traefik Instance" +echo -e "10. Setting up Traefik Instance" ${createTraefikInstance()} -echo -e "12. Installing Nixpacks" +echo -e "11. Installing Nixpacks" ${installNixpacks()} -echo -e "13. Installing Buildpacks" +echo -e "12. Installing Buildpacks" ${installBuildpacks()} -echo -e "14. Installing Railpack" +echo -e "13. Installing Railpack" ${installRailpack()} `; @@ -631,75 +628,3 @@ const installBuildpacks = () => ` echo "Buildpacks version $BUILDPACKS_VERSION installed ✅" fi `; - -const checkMemoryAndSetupSwap = () => ` - # Check available memory in MB - MEMORY_MB=$(free -m | awk 'NR==2{print $2}') - MEMORY_GB=$((MEMORY_MB / 1024)) - - echo " - Detected memory: ${MEMORY_MB}MB (${MEMORY_GB}GB)" - - # If memory is less than 2GB (2048MB), setup swap - if [ "$MEMORY_MB" -lt 2048 ]; then - echo " - Memory is less than 2GB, checking swap configuration..." - - # Check if swap is already enabled - SWAP_TOTAL=$(free -m | awk 'NR==3{print $2}') - - if [ "$SWAP_TOTAL" -gt 0 ]; then - echo " - Swap is already enabled (${SWAP_TOTAL}MB) ✅" - else - echo " - No swap detected. Setting up swap file..." - - # Calculate swap size (4GB for systems with less than 2GB RAM) - SWAP_SIZE="4G" - SWAP_FILE="/swapfile" - - # Check if swap file already exists - if [ -f "$SWAP_FILE" ]; then - echo " - Swap file already exists, skipping creation" - else - # Create swap file - echo " - Creating ${SWAP_SIZE} swap file at ${SWAP_FILE}..." - - # Use fallocate if available, otherwise use dd - if command -v fallocate >/dev/null 2>&1; then - fallocate -l $SWAP_SIZE $SWAP_FILE >/dev/null 2>&1 - else - dd if=/dev/zero of=$SWAP_FILE bs=1M count=4096 >/dev/null 2>&1 - fi - - if [ $? -eq 0 ]; then - # Set correct permissions - chmod 600 $SWAP_FILE - - # Setup swap - mkswap $SWAP_FILE >/dev/null 2>&1 - swapon $SWAP_FILE >/dev/null 2>&1 - - # Add to fstab for persistence - if ! grep -q "$SWAP_FILE" /etc/fstab; then - echo "$SWAP_FILE none swap sw 0 0" >> /etc/fstab - fi - - # Verify swap is active - NEW_SWAP_TOTAL=$(free -m | awk 'NR==3{print $2}') - if [ "$NEW_SWAP_TOTAL" -gt 0 ]; then - echo " - Swap file created and activated successfully (${NEW_SWAP_TOTAL}MB) ✅" - - # Optimize swappiness for server use - echo "vm.swappiness=10" >> /etc/sysctl.conf - sysctl vm.swappiness=10 >/dev/null 2>&1 - echo " - Swap swappiness set to 10 for optimal server performance ✅" - else - echo " - Failed to activate swap file ❌" - fi - else - echo " - Failed to create swap file ❌" - fi - fi - fi - else - echo " - Memory is sufficient (≥2GB), swap configuration not required ✅" - fi -`;