diff --git a/src/helper/class-ee-site.php b/src/helper/class-ee-site.php index 25a6833b..0d67396b 100644 --- a/src/helper/class-ee-site.php +++ b/src/helper/class-ee-site.php @@ -197,6 +197,11 @@ protected function delete_site( $level, $site_url, $site_fs_path, $db_data = [] } } + $volumes = \EE::docker()::get_volumes_by_label( $site_url ); + foreach ( $volumes as $volume ) { + \EE::exec( 'docker volume rm ' . $volume ); + } + if ( ! empty( $db_data['db_host'] ) ) { \EE\Site\Utils\cleanup_db( $db_data['db_host'], $db_data['db_name'] ); \EE\Site\Utils\cleanup_db_user( $db_data['db_host'], $db_data['db_user'] ); diff --git a/src/site-type/Site_HTML_Docker.php b/src/site-type/Site_HTML_Docker.php index 150508e6..0a2d6397 100644 --- a/src/site-type/Site_HTML_Docker.php +++ b/src/site-type/Site_HTML_Docker.php @@ -38,10 +38,9 @@ public function generate_docker_compose_yml( array $filters = [] ) { } $nginx['volumes'] = [ 'vol' => [ - [ 'name' => './app:/var/www' ], - [ 'name' => './config/nginx/main.conf:/etc/nginx/conf.d/default.conf' ], - [ 'name' => './config/nginx/custom:/etc/nginx/custom' ], - [ 'name' => './logs/nginx:/var/log/nginx' ], + [ 'name' => 'htdocs:/var/www' ], + [ 'name' => 'config_nginx:/etc/nginx' ], + [ 'name' => 'log_nginx:/var/log/nginx' ], ], ]; $nginx['labels'] = [ @@ -63,11 +62,19 @@ public function generate_docker_compose_yml( array $filters = [] ) { ] ]; + $volumes = [ + 'external_vols' => [ + [ 'prefix' => $filters['site_prefix'], 'ext_vol_name' => 'htdocs' ], + [ 'prefix' => $filters['site_prefix'], 'ext_vol_name' => 'config_nginx' ], + [ 'prefix' => $filters['site_prefix'], 'ext_vol_name' => 'log_nginx' ], + ], + ]; + $base[] = $nginx; $binding = [ - 'services' => $base, - 'network' => [ + 'services' => $base, + 'network' => [ 'networks_labels' => [ 'label' => [ [ 'name' => 'org.label-schema.vendor=EasyEngine' ], @@ -75,6 +82,7 @@ public function generate_docker_compose_yml( array $filters = [] ) { ], ], ], + 'created_volumes' => $volumes, ]; $docker_compose_yml = mustache_render( SITE_TEMPLATE_ROOT . '/docker-compose.mustache', $binding ); diff --git a/src/site-type/html.php b/src/site-type/html.php index 33d0fa80..e023bed3 100644 --- a/src/site-type/html.php +++ b/src/site-type/html.php @@ -161,9 +161,17 @@ private function configure_site_files() { $custom_conf_dest = $site_conf_dir . '/nginx/custom/user.conf'; $custom_conf_source = SITE_TEMPLATE_ROOT . '/config/nginx/user.conf.mustache'; + $volumes = [ + [ 'name' => 'htdocs', 'path_to_symlink' => $this->site_data['site_fs_path'] . '/app' ], + [ 'name' => 'config_nginx', 'path_to_symlink' => dirname( $site_nginx_default_conf ) ], + [ 'name' => 'log_nginx', 'path_to_symlink' => $this->site_data['site_fs_path'] . '/logs/nginx' ], + ]; + \EE::log( sprintf( 'Creating site %s.', $this->site_data['site_url'] ) ); \EE::log( 'Copying configuration files.' ); + $this->docker->create_volumes( $this->site_data['site_url'], $volumes ); + $default_conf_content = \EE\Utils\mustache_render( SITE_TEMPLATE_ROOT . '/config/nginx/main.conf.mustache', [ 'server_name' => $this->site_data['site_url'] ] ); $env_data = [ @@ -176,9 +184,12 @@ private function configure_site_files() { try { $this->dump_docker_compose_yml( [ 'nohttps' => true ] ); $this->fs->dumpFile( $site_conf_env, $env_content ); + \EE\Site\Utils\start_site_containers( $this->site_data['site_fs_path'] ); $this->fs->dumpFile( $site_nginx_default_conf, $default_conf_content ); $this->fs->copy( $custom_conf_source, $custom_conf_dest ); - + $this->fs->remove( $this->site_data['site_fs_path'] . '/app/html' ); + $this->fs->remove( $this->site_data['site_fs_path'] . '/config/nginx/conf.d' ); + \EE::exec( 'docker-compose restart nginx' ); $index_data = [ 'version' => 'v' . EE_VERSION, 'site_src_root' => $this->site_data['site_fs_path'] . '/app/htdocs', @@ -201,8 +212,9 @@ protected function dump_docker_compose_yml( $additional_filters = [] ) { $site_docker_yml = $this->site_data['site_fs_path'] . '/docker-compose.yml'; - $filter = []; - $filter[] = $this->site_data['site_type']; + $filter = []; + $filter[] = $this->site_data['site_type']; + $filter['site_prefix'] = $this->docker->get_docker_style_prefix( $this->site_data['site_url'] ); foreach ( $additional_filters as $key => $addon_filter ) { $filter[ $key ] = $addon_filter; @@ -225,8 +237,6 @@ private function create_site() { $this->level = 3; $this->configure_site_files(); - \EE\Site\Utils\start_site_containers( $this->site_data['site_fs_path'] ); - \EE\Site\Utils\create_etc_hosts_entry( $this->site_data['site_url'] ); if ( ! $this->skip_status_check ) { $this->level = 4; diff --git a/templates/config/nginx/main.conf.mustache b/templates/config/nginx/main.conf.mustache index 37d7a6fc..a44627c4 100644 --- a/templates/config/nginx/main.conf.mustache +++ b/templates/config/nginx/main.conf.mustache @@ -65,6 +65,4 @@ server { {{! /locations.conf }} client_max_body_size 100m; - - include /etc/nginx/custom/*.conf; } diff --git a/templates/docker-compose.mustache b/templates/docker-compose.mustache index 1683d3f5..a03e5fa1 100644 --- a/templates/docker-compose.mustache +++ b/templates/docker-compose.mustache @@ -51,6 +51,15 @@ services: {{/networks}} {{/services}} +{{#created_volumes}} +volumes: + {{#external_vols}} + {{ext_vol_name}}: + external: + name: {{prefix}}_{{ext_vol_name}} + {{/external_vols}} +{{/created_volumes}} + {{#network}} networks: site-network: