From 906c24a4ebc8c3dcad1011841abffe1161484371 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 16 Nov 2021 22:14:34 +0530 Subject: [PATCH] Fix service compose migration caused due to 4.4.0 Signed-off-by: Riddhesh Sanghvi --- ...191554_service-command_refresh_compose.php | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 migrations/container/20211611191554_service-command_refresh_compose.php diff --git a/migrations/container/20211611191554_service-command_refresh_compose.php b/migrations/container/20211611191554_service-command_refresh_compose.php new file mode 100644 index 0000000..b3ce749 --- /dev/null +++ b/migrations/container/20211611191554_service-command_refresh_compose.php @@ -0,0 +1,65 @@ +is_first_execution ) { + $this->skip_this_migration = true; + } + } + + /** + * Execute global service container name update. + * + * @throws EE\ExitException + */ + public function up() { + + if ( $this->skip_this_migration ) { + EE::debug( 'Skipping refresh-compose migration as it is not needed.' ); + + return; + } + + EE::debug( 'Starting refresh-compose' ); + + EE\Service\Utils\ensure_global_network_initialized(); + + // Backup names of all the running service containers + $running_services = []; + $count = 0; + $whitelisted_services = [ 'nginx-proxy', 'db', 'redis' ]; + chdir( EE_SERVICE_DIR ); + + foreach ( $whitelisted_services as $service ) { + $running_services[ $count ]['name'] = $service; + $launch = EE::launch( 'docker-compose ps -q global-' . $service ); + $running_services[ $count ]['state'] = $launch->stdout; + $count++; + } + + \EE\Service\Utils\generate_global_docker_compose_yml( new \Symfony\Component\Filesystem\Filesystem() ); + + // Start all the previously running service containers + foreach ( $running_services as $service ) { + if ( ! empty( $service['state'] ) ) { + EE::exec( \EE_DOCKER::docker_compose_with_custom() . " up -d global-${service['name']}", true, true ); + } + } + } + + /** + * No need for down. + * + * @throws EE\ExitException + */ + public function down() { + } +}