Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/helper/class-ee-site.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] );
Expand Down
20 changes: 14 additions & 6 deletions src/site-type/Site_HTML_Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = [
Expand All @@ -63,18 +62,27 @@ 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' ],
[ 'name' => 'io.easyengine.site=${VIRTUAL_HOST}' ],
],
],
],
'created_volumes' => $volumes,
];

$docker_compose_yml = mustache_render( SITE_TEMPLATE_ROOT . '/docker-compose.mustache', $binding );
Expand Down
20 changes: 15 additions & 5 deletions src/site-type/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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',
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions templates/config/nginx/main.conf.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,4 @@ server {
{{! /locations.conf }}

client_max_body_size 100m;

include /etc/nginx/custom/*.conf;
}
9 changes: 9 additions & 0 deletions templates/docker-compose.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down