Skip to content

Commit

Permalink
Merge branch 'develop' into add_postfix
Browse files Browse the repository at this point in the history
  • Loading branch information
mrrobot47 committed Aug 6, 2018
2 parents 3118b97 + 0a8e1f9 commit 4724bb2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 36 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ Performs basic site functions in easyengine.
Runs the site creation.

```bash
ee site create example.com # install wordpress without any page caching (default)
ee site create example.com --type=wp # install wordpress without any page caching
ee site create example.com --type=wp --wpredis # install wordpress with page caching
ee site create example.com --type=wp --wpsubir # install wpmu-subdirectory without any page caching
ee site create example.com --type=wp --wpsubir --wpredis # install wpmu-subdirectory with page caching
ee site create example.com --type=wp --wpsubdom # install wpmu-subdomain without any page caching
ee site create example.com --type=wp --wpsubdom --wpredis # install wpmu-subdomain with page cache
ee site create example.com # install wordpress without any page caching (default)
ee site create example.com --type=wp # install wordpress without any page caching
ee site create example.com --type=wp --cache # install wordpress with page caching
ee site create example.com --type=wp --mu=wpsubdir # install wpmu-subdirectory without any page caching
ee site create example.com --type=wp --mu=wpsubdir --cache # install wpmu-subdirectory with page caching
ee site create example.com --type=wp --mu=subdom # install wpmu-subdomain without any page caching
ee site create example.com --type=wp --mu=subdom --cache # install wpmu-subdomain with page cache
```

Let's Encrypt SSL
```bash
# Enable SSL using Let’s Encrypt (You can add --letsencrypt along with any other flag.)
ee site create example.com [--letsencrypt|--le]
ee site create example.com --le # install wordpress without any page caching + letsencrypt ssl
ee site create example.com --wpredis --le # install wordpress with page caching + letsencrypt ssl
ee site create example.com --wpsubdom --le # install wordpress wpmu-subdomain + wildcard letsencrypt ssl
ee site create example.com --type=wp [--letsencrypt|--le]
ee site create example.com --type=wp --le # install wordpress without any page caching + letsencrypt ssl
ee site create example.com --type=wp --cache --le # install wordpress with page caching + letsencrypt ssl
ee site create example.com --type=wp --mu=subdom --le # install wordpress wpmu-subdomain + wildcard letsencrypt ssl
```

## delete
Expand Down
4 changes: 2 additions & 2 deletions features/site.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Feature: Site Command
| HTTP/1.1 200 OK |

Scenario: Create wpsubdir site successfully
When I run 'bin/ee site create wpsubdir.test --type=wp --wpsubdir'
When I run 'bin/ee site create wpsubdir.test --type=wp --mu=subdir'
And I create subsite '1' in 'wpsubdir.test'
Then The site 'wpsubdir.test' should have webroot
And The site 'wpsubdir.test' should have WordPress
Expand All @@ -36,7 +36,7 @@ Feature: Site Command
| HTTP/1.1 200 OK |

Scenario: Create wpsubdom site successfully
When I run 'bin/ee site create wpsubdom.test --type=wp --wpsubdom'
When I run 'bin/ee site create wpsubdom.test --type=wp --mu=subdom'
And I create subsite '1' in 'wpsubdom.test'
Then The site 'wpsubdom.test' should have webroot
And The site 'wpsubdom.test' should have WordPress
Expand Down
47 changes: 26 additions & 21 deletions src/Site_WP_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ public function __construct() {
* [--wp]
* : WordPress website.
*
* [--wpredis]
* : Use redis for WordPress.
* [--cache]
* : Use redis cache for WordPress.
*
* [--wpsubdir]
*
* [--mu=<subdir>]
* : WordPress sub-dir Multi-site.
*
* [--wpsubdom]
* [--mu=<subdom>]
* : WordPress sub-domain Multi-site.
*
* [--title=<title>]
Expand Down Expand Up @@ -191,17 +192,20 @@ public function create( $args, $assoc_args ) {
$this->logger->debug( 'args:', $args );
$this->logger->debug( 'assoc_args:', empty( $assoc_args ) ? array( 'NULL' ) : $assoc_args );
$this->site['name'] = strtolower( EE\Utils\remove_trailing_slash( $args[0] ) );
$this->site['type'] = EE\Utils\get_type( $assoc_args, [ 'wp', 'wpsubdom', 'wpsubdir' ], 'wp' );
if ( false === $this->site['type'] ) {
EE::error( 'Invalid arguments' );

$mu = EE\Utils\get_flag_value( $assoc_args, 'mu' );

if ( isset( $assoc_args['mu'] ) && ! in_array( $mu, [ 'subdom', 'subdir' ], true ) ) {
EE::error( "Unrecognized multi-site parameter: $mu. Only `--mu=subdom` and `--mu=subdir` are supported." );
}
$this->site['type'] = $mu ?? 'wp';

if ( EE::db()::site_in_db( $this->site['name'] ) ) {
EE::error( sprintf( "Site %1\$s already exists. If you want to re-create it please delete the older one using:\n`ee site delete %1\$s`", $this->site['name'] ) );
}

$this->proxy_type = EE_PROXY_TYPE;
$this->cache_type = empty( $assoc_args['wpredis'] ) ? 'none' : 'wpredis';
$this->cache_type = EE\Utils\get_flag_value( $assoc_args, 'cache' );
$this->le = EE\Utils\get_flag_value( $assoc_args, 'letsencrypt' );
$this->site['title'] = EE\Utils\get_flag_value( $assoc_args, 'title', $this->site['name'] );
$this->site['user'] = EE\Utils\get_flag_value( $assoc_args, 'admin_user', 'admin' );
Expand Down Expand Up @@ -260,7 +264,7 @@ public function info( $args ) {
[ 'DB User', $this->db['user'] ],
[ 'DB Password', $this->db['pass'] ],
[ 'E-Mail', $this->site['email'] ],
[ 'Cache Type', $this->cache_type ],
[ 'Cache', $this->cache_type ? 'Enabled' : 'none' ],
[ 'SSL', $ssl ],
];

Expand All @@ -284,15 +288,15 @@ private function configure_site_files() {
$site_conf_env = $this->site['root'] . '/.env';
$site_nginx_default_conf = $site_conf_dir . '/nginx/default.conf';
$site_php_ini = $site_conf_dir . '/php-fpm/php.ini';
$server_name = ( 'wpsubdom' === $this->site['type'] ) ? $this->site['name'] . ' *.' . $this->site['name'] : $this->site['name'];
$server_name = ( 'subdom' === $this->site['type'] ) ? $this->site['name'] . ' *.' . $this->site['name'] : $this->site['name'];
$process_user = posix_getpwuid( posix_geteuid() );

EE::log( 'Creating WordPress site ' . $this->site['name'] );
EE::log( 'Copying configuration files.' );

$filter = [];
$filter[] = $this->site['type'];
$filter[] = $this->cache_type;
$filter[] = $this->cache_type ? 'redis' : 'none';
$filter[] = $this->le;
$filter[] = $this->db['host'];
$site_docker = new Site_WP_Docker();
Expand Down Expand Up @@ -342,19 +346,19 @@ private function configure_site_files() {
/**
* Function to generate default.conf from mustache templates.
*
* @param string $site_type Type of site (wpsubdom, wpredis etc..).
* @param string $cache_type Type of cache(wpredis or none).
* @param string $server_name Name of server to use in virtual_host.
* @param string $site_type Type of site (subdom, subdir etc..).
* @param boolean $cache_type Cache enabled or not.
* @param string $server_name Name of server to use in virtual_host.
*
* @return string Parsed mustache template string output.
*/
private function generate_default_conf( $site_type, $cache_type, $server_name ) {

$default_conf_data['site_type'] = $site_type;
$default_conf_data['server_name'] = $server_name;
$default_conf_data['include_php_conf'] = $cache_type !== 'wpredis';
$default_conf_data['include_wpsubdir_conf'] = $site_type === 'wpsubdir';
$default_conf_data['include_redis_conf'] = $cache_type === 'wpredis';
$default_conf_data['include_php_conf'] = ! $cache_type;
$default_conf_data['include_wpsubdir_conf'] = $site_type === 'subdir';
$default_conf_data['include_redis_conf'] = $cache_type;

return EE\Utils\mustache_render( SITE_WP_TEMPLATE_ROOT . '/config/nginx/default.conf.mustache', $default_conf_data );
}
Expand Down Expand Up @@ -418,7 +422,8 @@ private function create_site( $assoc_args ) {
}

if ( $this->le ) {
$this->init_le();
$wildcard = 'subdom' === $this->site['type'] ? true : false;
$this->init_le( $this->site['name'], $this->site['root'], $wildcard );
}
$this->info( [ $this->site['name'] ], [] );
$this->create_site_db_entry();
Expand Down Expand Up @@ -523,9 +528,9 @@ private function install_wp() {
$wp_install_command = 'install';
$maybe_multisite_type = '';

if ( 'wpsubdom' === $this->site['type'] || 'wpsubdir' === $this->site['type'] ) {
if ( 'subdom' === $this->site['type'] || 'subdir' === $this->site['type'] ) {
$wp_install_command = 'multisite-install';
$maybe_multisite_type = $this->site['type'] === 'wpsubdom' ? '--subdomains' : '';
$maybe_multisite_type = $this->site['type'] === 'subdom' ? '--subdomains' : '';
}

$install_command = sprintf( 'docker-compose exec --user=\'www-data\' php wp core %s --url=\'%s\' --title=\'%s\' --admin_user=\'%s\'', $wp_install_command, $this->site['name'], $this->site['title'], $this->site['user'] );
Expand Down Expand Up @@ -553,7 +558,7 @@ private function create_site_db_entry() {
'site_title' => $this->site['title'],
'site_command' => $this->command,
'proxy_type' => $this->proxy_type,
'cache_type' => $this->cache_type,
'cache_type' => (int) $this->cache_type,
'site_path' => $this->site['root'],
'db_name' => $this->db['name'],
'db_user' => $this->db['user'],
Expand Down
4 changes: 2 additions & 2 deletions src/Site_WP_Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function generate_docker_compose_yml( array $filters = [] ) {
$nginx['depends_on'] = [ 'name' => 'php' ];
$nginx['restart'] = $restart_default;

$v_host = in_array( 'wpsubdom', $filters, true ) ? 'VIRTUAL_HOST=${VIRTUAL_HOST},*.${VIRTUAL_HOST}' : 'VIRTUAL_HOST';
$v_host = in_array( 'subdom', $filters, true ) ? 'VIRTUAL_HOST=${VIRTUAL_HOST},*.${VIRTUAL_HOST}' : 'VIRTUAL_HOST';

$nginx['environment'] = [
'env' => [
Expand Down Expand Up @@ -182,7 +182,7 @@ public function generate_docker_compose_yml( array $filters = [] ) {
$base[] = $phpmyadmin;
$base[] = $postfix;

if ( in_array( 'wpredis', $filters, true ) ) {
if ( in_array( 'redis', $filters, true ) ) {
$base[] = $redis;
}

Expand Down

0 comments on commit 4724bb2

Please sign in to comment.