@@ -86,13 +86,20 @@ function init_checks() {
8686 if ( ! ( $ port_80_status && $ port_443_status ) ) {
8787 EE ::error ( 'Cannot create/start proxy container. Please make sure port 80 and 443 are free. ' );
8888 } else {
89- $ EE_CONF_ROOT = EE_CONF_ROOT ;
90- $ img_versions = EE \Utils \get_image_versions ();
91- $ ee_proxy_command = "docker run --name $ proxy_type -e LOCAL_USER_ID=`id -u` -e LOCAL_GROUP_ID=`id -g` --restart=always -d -p 80:80 -p 443:443 -v $ EE_CONF_ROOT /nginx/certs:/etc/nginx/certs -v $ EE_CONF_ROOT /nginx/dhparam:/etc/nginx/dhparam -v $ EE_CONF_ROOT /nginx/conf.d:/etc/nginx/conf.d -v $ EE_CONF_ROOT /nginx/htpasswd:/etc/nginx/htpasswd -v $ EE_CONF_ROOT /nginx/vhost.d:/etc/nginx/vhost.d -v /var/run/docker.sock:/tmp/docker.sock:ro -v $ EE_CONF_ROOT :/app/ee4 -v /usr/share/nginx/html easyengine/nginx-proxy: " . $ img_versions ['easyengine/nginx-proxy ' ];
9289
90+ $ fs = new Filesystem ();
9391
94- if ( EE ::docker ()::boot_container ( $ proxy_type , $ ee_proxy_command ) ) {
95- $ fs = new Filesystem ();
92+ if ( ! $ fs ->exists ( EE_CONF_ROOT . '/docker-compose.yml ' ) ) {
93+ generate_global_docker_compose_yml ( $ fs );
94+ }
95+
96+ $ EE_CONF_ROOT = EE_CONF_ROOT ;
97+ if ( ! EE ::docker ()::docker_network_exists ( 'ee-global-network ' ) ) {
98+ if ( ! EE ::docker ()::create_network ( 'ee-global-network ' ) ) {
99+ EE ::error ( 'Unable to create network ee-global-network ' );
100+ }
101+ }
102+ if ( EE ::docker ()::docker_compose_up ( EE_CONF_ROOT , [ 'nginx-proxy ' ] ) ) {
96103 $ fs ->dumpFile ( "$ EE_CONF_ROOT /nginx/conf.d/custom.conf " , file_get_contents ( EE_ROOT . '/templates/custom.conf.mustache ' ) );
97104 EE ::success ( "$ proxy_type container is up. " );
98105 } else {
@@ -102,6 +109,47 @@ function init_checks() {
102109 }
103110}
104111
112+ /**
113+ * Generates global docker-compose.yml at EE_CONF_ROOT
114+ *
115+ * @param Filesystem $fs Filesystem object to write file
116+ */
117+ function generate_global_docker_compose_yml ( Filesystem $ fs ) {
118+ $ img_versions = EE \Utils \get_image_versions ();
119+
120+ $ data = [
121+ 'services ' => [
122+ 'name ' => 'nginx-proxy ' ,
123+ 'container_name ' => 'ee-nginx-proxy ' ,
124+ 'image ' => 'easyengine/nginx-proxy: ' . $ img_versions ['easyengine/nginx-proxy ' ],
125+ 'restart ' => 'always ' ,
126+ 'ports ' => [
127+ '80:80 ' ,
128+ '443:443 ' ,
129+ ],
130+ 'environment ' => [
131+ 'LOCAL_USER_ID= ' . posix_geteuid (),
132+ 'LOCAL_GROUP_ID= ' . posix_getegid (),
133+ ],
134+ 'volumes ' => [
135+ EE_CONF_ROOT . '/nginx/certs:/etc/nginx/certs ' ,
136+ EE_CONF_ROOT . '/nginx/dhparam:/etc/nginx/dhparam ' ,
137+ EE_CONF_ROOT . '/nginx/conf.d:/etc/nginx/conf.d ' ,
138+ EE_CONF_ROOT . '/nginx/htpasswd:/etc/nginx/htpasswd ' ,
139+ EE_CONF_ROOT . '/nginx/vhost.d:/etc/nginx/vhost.d ' ,
140+ '/usr/share/nginx/html ' ,
141+ '/var/run/docker.sock:/tmp/docker.sock:ro ' ,
142+ ],
143+ 'networks ' => [
144+ 'global-network ' ,
145+ ],
146+ ],
147+ ];
148+
149+ $ contents = EE \Utils \mustache_render ( EE_ROOT . '/templates/global_docker_compose.yml.mustache ' , $ data );
150+ $ fs ->dumpFile ( EE_CONF_ROOT . '/docker-compose.yml ' , $ contents );
151+ }
152+
105153/**
106154 * Creates site root directory if does not exist.
107155 * Throws error if it does exist.
@@ -123,26 +171,6 @@ function create_site_root( $site_root, $site_name ) {
123171 $ fs ->chown ( $ site_root , $ terminal_username );
124172}
125173
126- /**
127- * Function to setup site network.
128- *
129- * @param string $site_name Name of the site.
130- *
131- * @throws \Exception when network start fails.
132- */
133- function setup_site_network ( $ site_name ) {
134-
135- $ proxy_type = EE_PROXY_TYPE ;
136- if ( EE ::docker ()::create_network ( $ site_name ) ) {
137- EE ::success ( 'Network started. ' );
138- } else {
139- throw new \Exception ( 'There was some error in starting the network. ' );
140- }
141-
142- EE ::docker ()::connect_site_network_to ( $ site_name , $ proxy_type );
143-
144- }
145-
146174/**
147175 * Reloads configuration of ee-nginx-proxy container
148176 *
0 commit comments