From 704d514f97fb4631f8c669c735a985bc653153e4 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar Date: Wed, 17 Nov 2021 13:26:02 +0530 Subject: [PATCH] Add custom docker-compose container name for v2 fix --- src/Site_PHP_Docker.php | 86 +++++++++++++++++-------------- templates/docker-compose.mustache | 3 ++ 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/src/Site_PHP_Docker.php b/src/Site_PHP_Docker.php index 1c4e5bd..9aaf9b4 100644 --- a/src/Site_PHP_Docker.php +++ b/src/Site_PHP_Docker.php @@ -39,20 +39,21 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) { if ( in_array( 'db', $filters, true ) ) { // db configuration. - $db['service_name'] = [ 'name' => 'db' ]; - $db['image'] = [ 'name' => 'easyengine/mariadb:' . $img_versions['easyengine/mariadb'] ]; - $db['restart'] = $restart_default; - $db['labels'] = [ + $db['service_name'] = [ 'name' => 'db' ]; + $db['container_name'] = $filters['site_prefix'] . '_db_1'; + $db['image'] = [ 'name' => 'easyengine/mariadb:' . $img_versions['easyengine/mariadb'] ]; + $db['restart'] = $restart_default; + $db['labels'] = [ 'label' => [ 'name' => 'io.easyengine.site=${VIRTUAL_HOST}', ], ]; - $db['volumes'] = [ + $db['volumes'] = [ [ 'vol' => \EE_DOCKER::get_mounting_volume_array( $volumes['db'] ), ], ]; - $db['environment'] = [ + $db['environment'] = [ 'env' => [ [ 'name' => 'MYSQL_ROOT_PASSWORD' ], [ 'name' => 'MYSQL_DATABASE' ], @@ -60,14 +61,15 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) { [ 'name' => 'MYSQL_PASSWORD' ], ], ]; - $db['sysctls'] = sysctl_parameters(); - $db['networks'] = $network_default; + $db['sysctls'] = sysctl_parameters(); + $db['networks'] = $network_default; } // PHP configuration. $php_image_key = ( 'latest' === $filters['php_version'] ? 'easyengine/php' : 'easyengine/php' . $filters['php_version'] ); - $php['service_name'] = [ 'name' => 'php' ]; - $php['image'] = [ 'name' => $php_image_key . ':' . $img_versions[ $php_image_key ] ]; + $php['service_name'] = [ 'name' => 'php' ]; + $php['container_name'] = $filters['site_prefix'] . '_php_1'; + $php['image'] = [ 'name' => $php_image_key . ':' . $img_versions[ $php_image_key ] ]; if ( in_array( 'db', $filters, true ) ) { $php['depends_on']['dependency'][] = [ 'name' => 'db' ]; @@ -77,19 +79,19 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) { $php['depends_on']['dependency'][] = [ 'name' => 'redis' ]; } - $php['restart'] = $restart_default; - $php['labels'] = [ + $php['restart'] = $restart_default; + $php['labels'] = [ 'label' => [ 'name' => 'io.easyengine.site=${VIRTUAL_HOST}', ], ]; - $php['volumes'] = [ + $php['volumes'] = [ [ 'vol' => \EE_DOCKER::get_mounting_volume_array( $volumes['php'] ), ], ]; - $php['sysctls'] = sysctl_parameters(); - $php['environment'] = [ + $php['sysctls'] = sysctl_parameters(); + $php['environment'] = [ 'env' => [ [ 'name' => 'USER_ID' ], [ 'name' => 'GROUP_ID' ], @@ -98,7 +100,7 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) { [ 'name' => 'NEWRELIC_LICENSE_KEY' ], ], ]; - $php['networks'] = [ + $php['networks'] = [ 'net' => [ [ 'name' => 'site-network', @@ -119,6 +121,7 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) { // nginx configuration. $nginx['service_name'] = [ 'name' => 'nginx' ]; + $nginx['container_name'] = $filters['site_prefix'] . '_nginx_1'; $nginx['image'] = [ 'name' => 'easyengine/nginx:' . $img_versions['easyengine/nginx'] ]; $nginx['depends_on']['dependency'][] = [ 'name' => 'php' ]; $nginx['restart'] = $restart_default; @@ -129,7 +132,7 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) { $v_host .= ',' . $filters['alias_domains']; } - $nginx['environment'] = [ + $nginx['environment'] = [ 'env' => [ [ 'name' => $v_host ], [ 'name' => 'VIRTUAL_PATH=/' ], @@ -148,16 +151,16 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) { $nginx['environment']['env'][] = [ 'name' => "SSL_POLICY=$ssl_policy" ]; } - $nginx['volumes'] = [ + $nginx['volumes'] = [ 'vol' => \EE_DOCKER::get_mounting_volume_array( $volumes['nginx'] ), ]; - $nginx['labels'] = [ + $nginx['labels'] = [ 'label' => [ 'name' => 'io.easyengine.site=${VIRTUAL_HOST}', ], ]; - $nginx['sysctls'] = sysctl_parameters(); - $nginx['networks'] = [ + $nginx['sysctls'] = sysctl_parameters(); + $nginx['networks'] = [ 'net' => [ [ 'name' => 'global-frontend-network' ], [ 'name' => 'site-network' ], @@ -168,23 +171,24 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) { $network['enable_backend_network'] = true; } // mailhog configuration. - $mailhog['service_name'] = [ 'name' => 'mailhog' ]; - $mailhog['image'] = [ 'name' => 'easyengine/mailhog:' . $img_versions['easyengine/mailhog'] ]; - $mailhog['restart'] = $restart_default; - $mailhog['command'] = [ 'name' => '["-invite-jim=false"]' ]; - $mailhog['environment'] = [ + $mailhog['service_name'] = [ 'name' => 'mailhog' ]; + $mailhog['container_name'] = $filters['site_prefix'] . '_mailhog_1'; + $mailhog['image'] = [ 'name' => 'easyengine/mailhog:' . $img_versions['easyengine/mailhog'] ]; + $mailhog['restart'] = $restart_default; + $mailhog['command'] = [ 'name' => '["-invite-jim=false"]' ]; + $mailhog['environment'] = [ 'env' => [ [ 'name' => $v_host ], [ 'name' => 'VIRTUAL_PATH=/ee-admin/mailhog/' ], [ 'name' => 'VIRTUAL_PORT=8025' ], ], ]; - $mailhog['labels'] = [ + $mailhog['labels'] = [ 'label' => [ 'name' => 'io.easyengine.site=${VIRTUAL_HOST}', ], ]; - $mailhog['networks'] = [ + $mailhog['networks'] = [ 'net' => [ [ 'name' => 'site-network' ], [ 'name' => 'global-frontend-network' ], @@ -192,30 +196,32 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) { ]; // postfix configuration. - $postfix['service_name'] = [ 'name' => 'postfix' ]; - $postfix['image'] = [ 'name' => 'easyengine/postfix:' . $img_versions['easyengine/postfix'] ]; - $postfix['hostname'] = [ 'name' => '${VIRTUAL_HOST}' ]; - $postfix['restart'] = $restart_default; - $postfix['labels'] = [ + $postfix['service_name'] = [ 'name' => 'postfix' ]; + $postfix['container_name'] = $filters['site_prefix'] . '_postfix_1'; + $postfix['image'] = [ 'name' => 'easyengine/postfix:' . $img_versions['easyengine/postfix'] ]; + $postfix['hostname'] = [ 'name' => '${VIRTUAL_HOST}' ]; + $postfix['restart'] = $restart_default; + $postfix['labels'] = [ 'label' => [ 'name' => 'io.easyengine.site=${VIRTUAL_HOST}', ], ]; - $postfix['volumes'] = [ + $postfix['volumes'] = [ 'vol' => \EE_DOCKER::get_mounting_volume_array( $volumes['postfix'] ), ]; - $postfix['networks'] = $network_default; + $postfix['networks'] = $network_default; // redis configuration. - $redis['service_name'] = [ 'name' => 'redis' ]; - $redis['image'] = [ 'name' => 'easyengine/redis:' . $img_versions['easyengine/redis'] ]; - $redis['labels'] = [ + $redis['service_name'] = [ 'name' => 'redis' ]; + $redis['container_name'] = $filters['site_prefix'] . '_redis_1'; + $redis['image'] = [ 'name' => 'easyengine/redis:' . $img_versions['easyengine/redis'] ]; + $redis['labels'] = [ 'label' => [ 'name' => 'io.easyengine.site=${VIRTUAL_HOST}', ], ]; - $redis['sysctls'] = sysctl_parameters(); - $redis['networks'] = $network_default; + $redis['sysctls'] = sysctl_parameters(); + $redis['networks'] = $network_default; $base[] = $php; $base[] = $nginx; diff --git a/templates/docker-compose.mustache b/templates/docker-compose.mustache index c5aa5fe..912e6b1 100644 --- a/templates/docker-compose.mustache +++ b/templates/docker-compose.mustache @@ -6,6 +6,9 @@ services: {{#service_name}} {{name}}: {{/service_name}} + {{#container_name}} + container_name: {{container_name}} + {{/container_name}} {{#image}} image: {{name}} {{/image}}