diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 7b24e17..0a2ad2f 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -14,7 +14,16 @@ 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 +67,28 @@ class FeatureContext implements Context public $webroot_path; public $ee_path; + /** + * Contain all test sites name. + * + * @var array + */ + public static $test_sites = [ + 'php.test', + 'example.test', + 'www.example1.test', + 'labels.test', + 'php-local-db.test', + 'php-local-redis.test', + 'php-local-db-redis.test', + ]; + + /** + * Variable contain all fail sites details. + * + * @var array + */ + public $fail_sites = []; + /** * Initializes context. */ @@ -255,19 +286,10 @@ public function cleanupScenario( AfterScenarioScope $scope ) */ public static function cleanup( AfterFeatureScope $scope ) { - $test_sites = [ - 'php.test', - 'example.test', - 'www.example1.test', - 'labels.test', - 'php-local-db.test', - 'php-local-redis.test', - 'php-local-db-redis.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" ); @@ -406,4 +428,60 @@ public function checkMysqlConnection(string $site, string $db_type) } } + /** + * @when Create :nth php 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->createPhpSite($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 createPhpSite($domain) + { + $command = sprintf( + 'bin/ee site create %s --type=php', + $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 7886f04..33f6c8a 100644 --- a/features/site.feature +++ b/features/site.feature @@ -186,3 +186,7 @@ Feature: Site Command | db | | redis | | phpmyadmin | + + @site50 + Scenario: Create 50 sites to test Docker limit + When Create '50' php site to fix docker issue diff --git a/src/PHP.php b/src/PHP.php index 815d573..4c14c6d 100644 --- a/src/PHP.php +++ b/src/PHP.php @@ -145,7 +145,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/src/Site_PHP_Docker.php b/src/Site_PHP_Docker.php index 1f27405..f6ba1c9 100644 --- a/src/Site_PHP_Docker.php +++ b/src/Site_PHP_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_PHP_Docker { @@ -27,6 +28,8 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) { ], ]; + $ip = get_subnet_ip(); + $network = [ 'networks_labels' => [ 'label' => [ @@ -34,6 +37,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/templates/docker-compose.mustache b/templates/docker-compose.mustache index 2578fe5..559c981 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: