diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index cb07d22..997e0f1 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -14,7 +14,15 @@ define( 'EE', true ); define( 'EE_VERSION', trim( file_get_contents( EE_ROOT . '/VERSION' ) ) ); -define( 'EE_ROOT_DIR', '/opt/easyengine' ); + +$root_alias = '/opt'; +if ( 'Darwin' === php_uname( 's' ) ) { + $sys_name = posix_getpwuid(posix_geteuid())['name']; + if ( ! empty( $sys_name ) ) { + $root_alias = '/Users/' . $sys_name; + } +} +define( 'EE_ROOT_DIR', $root_alias . '/easyengine' ); require_once EE_ROOT . '/php/bootstrap.php'; @@ -58,6 +66,30 @@ class FeatureContext implements Context public $webroot_path; public $ee_path; + /** + * Contain all test sites name. + * + * @var array + */ + public static $test_sites = [ + 'wp.test', + 'wpsubdom.test', + 'wpsubdir.test', + 'example.test', + 'www.example1.test', + 'example2.test', + 'www.example3.test', + 'labels.test', + 'wpcache.test', + ]; + + /** + * Variable contain all fail sites details. + * + * @var array + */ + public $fail_sites = []; + /** * Initializes context. */ @@ -395,21 +427,10 @@ public function thereShouldBeContainersWithLabel($expected_running_containers, P */ public static function cleanup(AfterFeatureScope $scope) { - $test_sites = [ - 'wp.test', - 'wpsubdom.test', - 'wpsubdir.test', - 'example.test', - 'www.example1.test', - 'example2.test', - 'www.example3.test', - 'labels.test', - 'wpcache.test', - ]; $result = EE::launch( 'sudo bin/ee site list --format=text',false, true ); $running_sites = explode( "\n", $result->stdout ); - $sites_to_delete = array_intersect( $test_sites, $running_sites ); + $sites_to_delete = array_intersect( self::$test_sites, $running_sites ); foreach ( $sites_to_delete as $site ) { exec("sudo bin/ee site delete $site --yes" ); @@ -422,4 +443,61 @@ public static function cleanup(AfterFeatureScope $scope) unlink('ee-old.phar'); } } + + /** + * @when Create :nth WordPress site to fix docker issue + */ + public function createNNumberOfSite($nth) + { + for ( $i=1; $i <= $nth; $i++ ) { + $domain = 'example'.$i.'.test'; + self::$test_sites[] = $domain; // Add site name to cleanup. + $this->createWPSite($domain); // Create html site. + } + // Show list of fail sites. + foreach( $this->fail_sites as $site_name => $fail_site ) { + echo $site_name . "\n" . $fail_site . "\n"; + } + } + + /** + * Function to create n number of html sites + * + * @param string $domain The site name to create site. + * @return void + */ + public function createWPSite($domain) + { + $command = sprintf( + 'bin/ee site create %s --type=wp --skip-status-check', + $domain + ); + EE::launch($command, false, true); + $this->checkSiteIsRunningOrNot($domain); + } + + /** + * Function to check site is running or not + * + * @param string $site Site domain name. + * @return void + */ + public function checkSiteIsRunningOrNot($site) + { + $url = 'http://' . $site; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HEADER, true); + curl_setopt($ch, CURLOPT_NOBODY, true); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_VERBOSE, true); + $headers = curl_exec($ch); + + curl_close($ch); + if ( false === strpos( $headers, 'HTTP/1.1 200 OK' ) ) { + $this->fail_sites[$site] = "Unable to find `HTTP/1.1 200 OK` \nActual output is : " . $headers; + } + } + } diff --git a/features/site.feature b/features/site.feature index f996305..b065d68 100644 --- a/features/site.feature +++ b/features/site.feature @@ -34,7 +34,7 @@ Feature: Site Command And Request on 'wpcache.test' should contain following headers: | header | | HTTP/1.1 200 OK | - + Scenario: Create wpsubdir site successfully When I run 'bin/ee site create wpsubdir.test --type=wp --mu=subdir' And I create subsite '1' in 'wpsubdir.test' @@ -85,3 +85,7 @@ Feature: Site Command | db | | redis | | phpmyadmin | + + @site50 + Scenario: Create 50 sites to test Docker limit + When Create '50' WordPress site to fix docker issue diff --git a/src/Site_WP_Docker.php b/src/Site_WP_Docker.php index a3ff624..fd8f49d 100644 --- a/src/Site_WP_Docker.php +++ b/src/Site_WP_Docker.php @@ -4,6 +4,7 @@ use function EE\Utils\mustache_render; use function EE\Site\Utils\get_ssl_policy; +use function EE\Site\Utils\get_subnet_ip; class Site_WP_Docker { @@ -28,6 +29,8 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) { ], ]; + $ip = get_subnet_ip(); + $network = [ 'networks_labels' => [ 'label' => [ @@ -35,6 +38,7 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) { [ 'name' => 'io.easyengine.site=${VIRTUAL_HOST}' ], ], ], + 'subnet_ip' => $ip, ]; if ( in_array( 'db', $filters, true ) ) { diff --git a/src/WordPress.php b/src/WordPress.php index 6d603df..69a42c2 100644 --- a/src/WordPress.php +++ b/src/WordPress.php @@ -215,7 +215,6 @@ public function __construct() { */ public function create( $args, $assoc_args ) { - $this->check_site_count(); \EE\Utils\delem_log( 'site create start' ); $this->logger->debug( 'args:', $args ); $this->logger->debug( 'assoc_args:', empty( $assoc_args ) ? array( 'NULL' ) : $assoc_args ); diff --git a/templates/docker-compose.mustache b/templates/docker-compose.mustache index 73d11f4..1ee9318 100644 --- a/templates/docker-compose.mustache +++ b/templates/docker-compose.mustache @@ -77,6 +77,9 @@ networks: {{#label}} - "{{name}}" {{/label}} + ipam: + config: + - subnet: '{{subnet_ip}}' {{/networks_labels}} global-frontend-network: external: