Skip to content

Conversation

@michielgerritsen
Copy link

This removes the composer.json variant in favor of a bash script. The script does the following checks:

  • Explicitly asks the user that this is not a production environment
  • Checks if the folder holds a Magento installation (check if app/etc/env.php and bin/magento exist)
  • Validates that PHP is available, and warns if that's not the case
  • Validates that Composer is available, and warns if that's not the case
  • Validates that the migration isn't already done
  • Check the Magento version, only 2.4.8 and higher are supported
  • Checks that Magento is in developer mode

If all checks pass, the migration is executed. After the migration is complete, it is instructed to destroy the Redis cache or the var/cache folder, and run bin/magento setup:upgrade. Composer show is also run so the user can accept the new Composer plugins that get installed.

The whole migration is tested through GitHub Actions. A Magento environment is spun up, and the migration is executed. After the migration, the installation is checked with an end-to-end test to verify that we can log in to the backend and that we see the Mage-OS footer notice. This is tested against 2.4.8 and the p1, p2, and p3 patch versions. I initially tried to add th e2.4.6 and 2.4.7 versions too but I've run into weird issues (setup:upgrade not defined, for example).

@rhoerr
Copy link
Contributor

rhoerr commented Nov 14, 2025

Nice!

Maybe we can add code to handle the cache flush directly, and maybe also prompt if they want to run setup at the end.

I wrote this recently to extract the redis connection info from Magento config to bash:

get_env_config() {
  local key_path=$1
  
  php -r "
    \$config = require 'app/etc/env.php';
    \$keys = explode('.', '${key_path}');
    \$value = \$config;
    foreach (\$keys as \$key) {
      if (isset(\$value[\$key])) {
        \$value = \$value[\$key];
      } else {
        \$value = ''; break;
      }
    }
    echo is_array(\$value) ? json_encode(\$value) : \$value;
  " 2>/dev/null
}

build_redis_connection_string() {
  local server=$1
  local port=$2
  local password=$3
  local db=$4
  local args=""
  
  # Return early if both server and host are empty
  if [ -z "${server}" ] && [ -z "${port}" ]; then
    echo ""
    return
  fi

  if [ -n "${port}" ] && [ "${port}" != "0" ]; then
    args="-h ${server} -p ${port}"
  else
    args="-s ${server}"
  fi

  # Add password if present
  [ -n "${password}" ] && args="${args} -a ${password}"

  echo "${args} -n ${db}"
}

# Extract Redis connection info from build env.php
redisCacheServer=$(get_env_config "cache.frontend.default.backend_options.server")
redisCachePort=$(get_env_config "cache.frontend.default.backend_options.port")
redisCachePassword=$(get_env_config "cache.frontend.default.backend_options.password")
redisCacheDB=$(get_env_config "cache.frontend.default.backend_options.database")
redisCache=$(build_redis_connection_string "${redisCacheServer}" "${redisCachePort}" "${redisCachePassword}" "${redisCacheDB}")

# Flush file or redis cache
if [ -n "${redisCache}" ]
  redis-cli ${redisCache} FLUSHDB
else
  rm -rf var/cache/*
fi

@michielgerritsen
Copy link
Author

@rhoerr Nice one! I added that, and now we can run the setup:upgrade step immediately. So in theory, the script should be totally hands-off now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants