From 7d2de64eedb6cda8aef556b5cbe4512ea1e65418 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 18 Nov 2026 15:23:54 +0530 Subject: [PATCH] fix(site): keep admin-tools mounts when site containers are recreated `ee site update --ssl`, alias domain updates, `ssl-renew`, `ssl-verify` and the `update --php` rollback recreate nginx (and php, its dependency) with only docker-compose.yml, so a site with admin-tools enabled loses the ee-admin mounts: /ee-admin/ returns 403 and pra/ and pma/ 404, while admin_tools stays 1 in the DB. Add up_site_containers(), which runs the same `up -d` as EE_DOCKER::docker_compose_up() but adds docker-compose-admin.yml when admin-tools is enabled on the site, and use it in start_site_containers() and for the direct docker_compose_up() calls. The DB flag decides, since `admin-tools disable` leaves the file behind. Commands for sites without admin-tools are unchanged. --- src/helper/class-ee-site.php | 8 ++++---- src/helper/site-utils.php | 39 +++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/helper/class-ee-site.php b/src/helper/class-ee-site.php index f34b1546..c288fc65 100644 --- a/src/helper/class-ee-site.php +++ b/src/helper/class-ee-site.php @@ -632,7 +632,7 @@ protected function update_alias_domains( $args, $assoc_args ) { // LE sites drop HTTPS here for the HTTP-01 challenge; the renewal below turns it back on, other SSL types keep theirs. $nohttps = ! $is_ssl || $pending_le || ( 'le' === $this->site_data['site_ssl'] && 'dns' !== $preferred_ssl_challenge ); $this->dump_docker_compose_yml( [ 'nohttps' => $nohttps ] ); - \EE_DOCKER::docker_compose_up( $this->site_data['site_fs_path'], [ 'nginx' ] ); + \EE\Site\Utils\up_site_containers( $this->site_data['site_fs_path'], [ 'nginx' ] ); } catch ( \Exception $e ) { if ( $pre_hook_fired ) { /** @@ -702,7 +702,7 @@ function ( $cert, $domain ) use ( $new_certs ) { chdir( $this->site_data['site_fs_path'] ); // Required as env variables have changed. - \EE_DOCKER::docker_compose_up( $this->site_data['site_fs_path'], [ 'nginx' ] ); + \EE\Site\Utils\up_site_containers( $this->site_data['site_fs_path'], [ 'nginx' ] ); EE::success( 'Alias domains updated on site ' . $this->site_data['site_url'] . '.' ); try { @@ -1069,7 +1069,7 @@ private function roll_back_php_update( $rollback, $old_version, $no_https ) { EE::warning( "Could not restore docker-compose.yml to PHP $old_version ({$e->getMessage()}). $manual" ); } - if ( $rollback['stopped'] && ! \EE_DOCKER::docker_compose_up( $site_fs_path, [ 'php' ] ) ) { + if ( $rollback['stopped'] && ! \EE\Site\Utils\up_site_containers( $site_fs_path, [ 'php' ] ) ) { EE::warning( "Could not start the php container again. $manual" ); } } @@ -1401,7 +1401,7 @@ public function enable( $args, $assoc_args, $exit_on_error = true ) { } } - if ( \EE_DOCKER::docker_compose_up( $this->site_data->site_fs_path, $containers_to_start ) ) { + if ( \EE\Site\Utils\up_site_containers( $this->site_data->site_fs_path, $containers_to_start ) ) { $this->site_data->site_enabled = 1; $this->site_data->save(); $success = true; diff --git a/src/helper/site-utils.php b/src/helper/site-utils.php index 2ae2d5c7..8994157d 100644 --- a/src/helper/site-utils.php +++ b/src/helper/site-utils.php @@ -809,11 +809,48 @@ function start_site_containers( $site_fs_path, $containers = [] ) { chdir( $site_fs_path ); EE::log( 'Starting site\'s services.' ); - if ( ! \EE_DOCKER::docker_compose_up( $site_fs_path, $containers ) ) { + if ( ! up_site_containers( $site_fs_path, $containers ) ) { throw new \Exception( 'There was some error in docker-compose up.' ); } } +/** + * Compose files, besides docker-compose.yml and the custom ones, that the site's containers are created from. + * + * @param string $site_fs_path Root directory of the site. + * + * @return string[] File names relative to the site root. + */ +function get_site_compose_files( $site_fs_path ) { + + // `admin-tools disable` leaves docker-compose-admin.yml in place, so the DB flag decides. + foreach ( Site::where( 'site_fs_path', $site_fs_path ) as $site ) { + if ( ! empty( $site->admin_tools ) ) { + return [ 'docker-compose-admin.yml' ]; + } + } + + return []; +} + +/** + * Like EE_DOCKER::docker_compose_up(), but with the site's own compose files, so a recreated container keeps admin-tools' mounts. + * + * @param string $site_fs_path Root directory of the site. + * @param array $containers Services to bring up. Empty brings up all. + * + * @return bool success. + */ +function up_site_containers( $site_fs_path, $containers = [] ) { + + if ( ! chdir( $site_fs_path ) ) { + return false; + } + $services = empty( $containers ) ? '' : ' ' . implode( ' ', $containers ); + + return EE::exec( \EE_DOCKER::docker_compose_with_custom( get_site_compose_files( $site_fs_path ) ) . ' up -d' . $services ); +} + /** * Function to restart given containers for a site and update EasyEngine header. *