From 647881647ad7940d0c213694ec4534c105c908ea Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar Date: Wed, 30 Sep 2020 17:03:02 +0530 Subject: [PATCH 1/4] Add custom docker-compose support --- src/helper/site-utils.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/helper/site-utils.php b/src/helper/site-utils.php index 1bc3511c..087d7e23 100644 --- a/src/helper/site-utils.php +++ b/src/helper/site-utils.php @@ -5,6 +5,7 @@ use EE; use EE\Model\Site; use Symfony\Component\Filesystem\Filesystem; +use function EE\Utils\docker_compose_with_custom; use function EE\Utils\get_flag_value; use function EE\Utils\get_config_value; use function EE\Utils\sanitize_file_folder_name; @@ -456,7 +457,7 @@ function restart_site_containers( $site_fs_path, $containers ) { chdir( $site_fs_path ); $all_containers = is_array( $containers ) ? implode( ' ', $containers ) : $containers; - EE::exec( "docker-compose restart $all_containers" ); + EE::exec( docker_compose_with_custom() . " restart $all_containers" ); } /** @@ -469,8 +470,8 @@ function stop_site_containers( $site_fs_path, $containers ) { chdir( $site_fs_path ); $all_containers = is_array( $containers ) ? implode( ' ', $containers ) : $containers; - EE::exec( "docker-compose stop $all_containers" ); - EE::exec( "docker-compose rm -f $all_containers" ); + EE::exec( docker_compose_with_custom() . " stop $all_containers" ); + EE::exec( docker_compose_with_custom() . " rm -f $all_containers" ); } /** @@ -487,7 +488,7 @@ function run_compose_command( $action, $container, $action_to_display = null, $s $display_service = $service_to_display ? $service_to_display : $container; EE::log( ucfirst( $display_action ) . 'ing ' . $display_service ); - EE::exec( "docker-compose $action $container", true, true ); + EE::exec( docker_compose_with_custom() . " $action $container", true, true ); } /** From 3425054f235574c6b336dba0e01a058e1d1d2b38 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar Date: Mon, 5 Oct 2020 15:27:05 +0530 Subject: [PATCH 2/4] Add custom docker-compose support in mailhog --- src/helper/site-utils.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/helper/site-utils.php b/src/helper/site-utils.php index 087d7e23..f0139880 100644 --- a/src/helper/site-utils.php +++ b/src/helper/site-utils.php @@ -518,14 +518,14 @@ function set_postfix_files( $site_url, $site_service_dir ) { function configure_postfix( $site_url, $site_fs_path ) { chdir( $site_fs_path ); - EE::exec( 'docker-compose exec postfix postconf -e \'relayhost =\'' ); - EE::exec( 'docker-compose exec postfix postconf -e \'smtpd_recipient_restrictions = permit_mynetworks\'' ); + EE::exec( docker_compose_with_custom() . ' exec postfix postconf -e \'relayhost =\'' ); + EE::exec( docker_compose_with_custom() . ' exec postfix postconf -e \'smtpd_recipient_restrictions = permit_mynetworks\'' ); $launch = EE::launch( sprintf( 'docker inspect -f \'{{ with (index .IPAM.Config 0) }}{{ .Subnet }}{{ end }}\' %s', $site_url ) ); $subnet_cidr = trim( $launch->stdout ); - EE::exec( sprintf( 'docker-compose exec postfix postconf -e \'mynetworks = %s 127.0.0.0/8\'', $subnet_cidr ) ); - EE::exec( sprintf( 'docker-compose exec postfix postconf -e \'myhostname = %s\'', $site_url ) ); - EE::exec( 'docker-compose exec postfix postconf -e \'syslog_name = $myhostname\'' ); - EE::exec( 'docker-compose restart postfix' ); + EE::exec( sprintf( docker_compose_with_custom() . ' exec postfix postconf -e \'mynetworks = %s 127.0.0.0/8\'', $subnet_cidr ) ); + EE::exec( sprintf( docker_compose_with_custom() . ' exec postfix postconf -e \'myhostname = %s\'', $site_url ) ); + EE::exec( docker_compose_with_custom() . ' exec postfix postconf -e \'syslog_name = $myhostname\'' ); + EE::exec( docker_compose_with_custom() . ' restart postfix' ); } /** From 2467079fef0fda8baf50a51760c53b51a74a088b Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar Date: Mon, 5 Oct 2020 15:39:52 +0530 Subject: [PATCH 3/4] Add custom docker-compose support in remaining places --- src/helper/class-ee-site.php | 3 ++- src/site-type/html.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/helper/class-ee-site.php b/src/helper/class-ee-site.php index 766d414b..2395423a 100644 --- a/src/helper/class-ee-site.php +++ b/src/helper/class-ee-site.php @@ -9,6 +9,7 @@ use function EE\Site\Utils\get_domains_of_site; use function EE\Site\Utils\get_preferred_ssl_challenge; use function EE\Site\Utils\update_site_db_entry; +use function EE\Utils\docker_compose_with_custom; use function EE\Utils\download; use function EE\Utils\extract_zip; use function EE\Utils\get_flag_value; @@ -1062,7 +1063,7 @@ public function restart( $args, $assoc_args, $whitelisted_containers = [] ) { foreach ( $containers as $container ) { if ( 'nginx' === $container ) { - if ( EE::exec( "docker-compose exec $container nginx -t", true, true ) ) { + if ( EE::exec( docker_compose_with_custom() . " exec $container nginx -t", true, true ) ) { \EE\Site\Utils\run_compose_command( 'restart', $container ); } else { \EE\Utils\delem_log( 'site restart stop due to Nginx test failure' ); diff --git a/src/site-type/html.php b/src/site-type/html.php index 3b6ad0ce..ba7a0b4e 100644 --- a/src/site-type/html.php +++ b/src/site-type/html.php @@ -276,7 +276,7 @@ private function configure_site_files() { // Assign www-data user ownership. chdir( $this->site_data['site_fs_path'] ); - EE::exec( sprintf( 'docker-compose exec --user="root" nginx bash -c "chown -R www-data: %s"', $this->site_data['site_container_fs_path'] ) ); + EE::exec( sprintf( docker_compose_with_custom() . ' exec --user="root" nginx bash -c "chown -R www-data: %s"', $this->site_data['site_container_fs_path'] ) ); \EE::success( 'Configuration files copied.' ); } catch ( \Exception $e ) { From dcc70628e684ad5b34bfe9eced32f0a25158a5a4 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar Date: Tue, 27 Oct 2020 19:28:13 +0530 Subject: [PATCH 4/4] Move docker_compose_with_custom to class EE_DOCKER --- src/helper/class-ee-site.php | 3 +-- src/helper/site-utils.php | 21 ++++++++++----------- src/site-type/html.php | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/helper/class-ee-site.php b/src/helper/class-ee-site.php index 2395423a..56b5f91b 100644 --- a/src/helper/class-ee-site.php +++ b/src/helper/class-ee-site.php @@ -9,7 +9,6 @@ use function EE\Site\Utils\get_domains_of_site; use function EE\Site\Utils\get_preferred_ssl_challenge; use function EE\Site\Utils\update_site_db_entry; -use function EE\Utils\docker_compose_with_custom; use function EE\Utils\download; use function EE\Utils\extract_zip; use function EE\Utils\get_flag_value; @@ -1063,7 +1062,7 @@ public function restart( $args, $assoc_args, $whitelisted_containers = [] ) { foreach ( $containers as $container ) { if ( 'nginx' === $container ) { - if ( EE::exec( docker_compose_with_custom() . " exec $container nginx -t", true, true ) ) { + if ( EE::exec( \EE_DOCKER::docker_compose_with_custom() . " exec $container nginx -t", true, true ) ) { \EE\Site\Utils\run_compose_command( 'restart', $container ); } else { \EE\Utils\delem_log( 'site restart stop due to Nginx test failure' ); diff --git a/src/helper/site-utils.php b/src/helper/site-utils.php index f0139880..030f13e7 100644 --- a/src/helper/site-utils.php +++ b/src/helper/site-utils.php @@ -5,7 +5,6 @@ use EE; use EE\Model\Site; use Symfony\Component\Filesystem\Filesystem; -use function EE\Utils\docker_compose_with_custom; use function EE\Utils\get_flag_value; use function EE\Utils\get_config_value; use function EE\Utils\sanitize_file_folder_name; @@ -457,7 +456,7 @@ function restart_site_containers( $site_fs_path, $containers ) { chdir( $site_fs_path ); $all_containers = is_array( $containers ) ? implode( ' ', $containers ) : $containers; - EE::exec( docker_compose_with_custom() . " restart $all_containers" ); + EE::exec( \EE_DOCKER::docker_compose_with_custom() . " restart $all_containers" ); } /** @@ -470,8 +469,8 @@ function stop_site_containers( $site_fs_path, $containers ) { chdir( $site_fs_path ); $all_containers = is_array( $containers ) ? implode( ' ', $containers ) : $containers; - EE::exec( docker_compose_with_custom() . " stop $all_containers" ); - EE::exec( docker_compose_with_custom() . " rm -f $all_containers" ); + EE::exec( \EE_DOCKER::docker_compose_with_custom() . " stop $all_containers" ); + EE::exec( \EE_DOCKER::docker_compose_with_custom() . " rm -f $all_containers" ); } /** @@ -488,7 +487,7 @@ function run_compose_command( $action, $container, $action_to_display = null, $s $display_service = $service_to_display ? $service_to_display : $container; EE::log( ucfirst( $display_action ) . 'ing ' . $display_service ); - EE::exec( docker_compose_with_custom() . " $action $container", true, true ); + EE::exec( \EE_DOCKER::docker_compose_with_custom() . " $action $container", true, true ); } /** @@ -518,14 +517,14 @@ function set_postfix_files( $site_url, $site_service_dir ) { function configure_postfix( $site_url, $site_fs_path ) { chdir( $site_fs_path ); - EE::exec( docker_compose_with_custom() . ' exec postfix postconf -e \'relayhost =\'' ); - EE::exec( docker_compose_with_custom() . ' exec postfix postconf -e \'smtpd_recipient_restrictions = permit_mynetworks\'' ); + EE::exec( \EE_DOCKER::docker_compose_with_custom() . ' exec postfix postconf -e \'relayhost =\'' ); + EE::exec( \EE_DOCKER::docker_compose_with_custom() . ' exec postfix postconf -e \'smtpd_recipient_restrictions = permit_mynetworks\'' ); $launch = EE::launch( sprintf( 'docker inspect -f \'{{ with (index .IPAM.Config 0) }}{{ .Subnet }}{{ end }}\' %s', $site_url ) ); $subnet_cidr = trim( $launch->stdout ); - EE::exec( sprintf( docker_compose_with_custom() . ' exec postfix postconf -e \'mynetworks = %s 127.0.0.0/8\'', $subnet_cidr ) ); - EE::exec( sprintf( docker_compose_with_custom() . ' exec postfix postconf -e \'myhostname = %s\'', $site_url ) ); - EE::exec( docker_compose_with_custom() . ' exec postfix postconf -e \'syslog_name = $myhostname\'' ); - EE::exec( docker_compose_with_custom() . ' restart postfix' ); + EE::exec( sprintf( \EE_DOCKER::docker_compose_with_custom() . ' exec postfix postconf -e \'mynetworks = %s 127.0.0.0/8\'', $subnet_cidr ) ); + EE::exec( sprintf( \EE_DOCKER::docker_compose_with_custom() . ' exec postfix postconf -e \'myhostname = %s\'', $site_url ) ); + EE::exec( \EE_DOCKER::docker_compose_with_custom() . ' exec postfix postconf -e \'syslog_name = $myhostname\'' ); + EE::exec( \EE_DOCKER::docker_compose_with_custom() . ' restart postfix' ); } /** diff --git a/src/site-type/html.php b/src/site-type/html.php index ba7a0b4e..eb265f8c 100644 --- a/src/site-type/html.php +++ b/src/site-type/html.php @@ -276,7 +276,7 @@ private function configure_site_files() { // Assign www-data user ownership. chdir( $this->site_data['site_fs_path'] ); - EE::exec( sprintf( docker_compose_with_custom() . ' exec --user="root" nginx bash -c "chown -R www-data: %s"', $this->site_data['site_container_fs_path'] ) ); + EE::exec( sprintf( \EE_DOCKER::docker_compose_with_custom() . ' exec --user="root" nginx bash -c "chown -R www-data: %s"', $this->site_data['site_container_fs_path'] ) ); \EE::success( 'Configuration files copied.' ); } catch ( \Exception $e ) {