Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove site limit for php sites #58

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 89 additions & 11 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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;
}
}

}
4 changes: 4 additions & 0 deletions features/site.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion src/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
4 changes: 4 additions & 0 deletions src/Site_PHP_Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -27,13 +28,16 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) {
],
];

$ip = get_subnet_ip();

$network = [
'networks_labels' => [
'label' => [
[ 'name' => 'org.label-schema.vendor=EasyEngine' ],
[ 'name' => 'io.easyengine.site=${VIRTUAL_HOST}' ],
],
],
'subnet_ip' => $ip,
];

if ( in_array( 'db', $filters, true ) ) {
Expand Down
3 changes: 3 additions & 0 deletions templates/docker-compose.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ networks:
{{#label}}
- "{{name}}"
{{/label}}
ipam:
config:
- subnet: '{{subnet_ip}}'
{{/networks_labels}}
global-frontend-network:
external:
Expand Down