-
Notifications
You must be signed in to change notification settings - Fork 7
Add global-services to service command #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rahulsprajapati
merged 12 commits into
EasyEngine:develop
from
sagarnasit:fix-service-command-enable
Sep 25, 2018
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1b21ea9
Move nginx-proxy check to service command
sagarnasit a960cf4
Move docker template from site-command to service-command
sagarnasit ab05ef7
Move static commands to utills
sagarnasit 2d25910
Change EE_CONF_ROOT to EE_ROOT_DIR
sagarnasit f5c2a6c
Add constants
mrrobot47 94855ed
Update utility functions and add global-redis
mrrobot47 7abddd3
Update functional calls according to new utility
mrrobot47 18658ed
Fix reloading of containers
mrrobot47 c7aa0ea
Rename file
mrrobot47 cabb677
Update template according to network changes
mrrobot47 f792ed7
Remove elastic search service for now
mrrobot47 8b0dd36
merge two if condition into one
sagarnasit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| <?php | ||
|
|
||
| namespace EE\Service\Utils; | ||
|
|
||
| use EE; | ||
| use Symfony\Component\Filesystem\Filesystem; | ||
|
|
||
| /** | ||
| * Boots up the container if it is stopped or not running. | ||
| * @throws EE\ExitException | ||
| */ | ||
| function nginx_proxy_check() { | ||
|
|
||
| $proxy_type = EE_PROXY_TYPE; | ||
| if ( 'running' !== EE::docker()::container_status( $proxy_type ) ) { | ||
| /** | ||
| * Checking ports. | ||
| */ | ||
| $port_80_status = get_curl_info( 'localhost', 80, true ); | ||
| $port_443_status = get_curl_info( 'localhost', 443, true ); | ||
|
|
||
| // if any/both the port/s is/are occupied. | ||
| if ( ! ( $port_80_status && $port_443_status ) ) { | ||
| EE::error( 'Cannot create/start proxy container. Please make sure port 80 and 443 are free.' ); | ||
| } else { | ||
|
|
||
| $fs = new Filesystem(); | ||
|
|
||
| if ( ! $fs->exists( EE_CONF_ROOT . '/docker-compose.yml' ) ) { | ||
| generate_global_docker_compose_yml( $fs ); | ||
| } | ||
|
|
||
| $EE_CONF_ROOT = EE_CONF_ROOT; | ||
| if ( ! EE::docker()::docker_network_exists( GLOBAL_BACKEND_NETWORK ) && | ||
| ! EE::docker()::create_network( GLOBAL_BACKEND_NETWORK ) ) { | ||
| EE::error( 'Unable to create network ' . GLOBAL_BACKEND_NETWORK ); | ||
| } | ||
| if ( ! EE::docker()::docker_network_exists( GLOBAL_FRONTEND_NETWORK ) && | ||
| ! EE::docker()::create_network( GLOBAL_FRONTEND_NETWORK ) ) { | ||
| EE::error( 'Unable to create network ' . GLOBAL_FRONTEND_NETWORK ); | ||
| } | ||
| if ( EE::docker()::docker_compose_up( EE_CONF_ROOT, [ 'global-nginx-proxy' ] ) ) { | ||
| $fs->dumpFile( "$EE_CONF_ROOT/nginx/conf.d/custom.conf", file_get_contents( EE_ROOT . '/templates/custom.conf.mustache' ) ); | ||
| EE::success( "$proxy_type container is up." ); | ||
| } else { | ||
| EE::error( "There was some error in starting $proxy_type container. Please check logs." ); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Function to start global conainer if it is not running. | ||
| * | ||
| * @param string $container Global container to be brought up. | ||
| */ | ||
| function init_global_container( $service, $container = '' ) { | ||
|
|
||
| if ( empty( $container ) ) { | ||
| $container = 'ee-' . $service; | ||
| } | ||
| if ( ! EE::docker()::docker_network_exists( GLOBAL_BACKEND_NETWORK ) && | ||
| ! EE::docker()::create_network( GLOBAL_BACKEND_NETWORK ) ) { | ||
| EE::error( 'Unable to create network ' . GLOBAL_BACKEND_NETWORK ); | ||
| } | ||
|
|
||
| $fs = new Filesystem(); | ||
|
|
||
| if ( ! $fs->exists( EE_CONF_ROOT . '/docker-compose.yml' ) ) { | ||
| generate_global_docker_compose_yml( $fs ); | ||
| } | ||
|
|
||
| if ( 'running' !== EE::docker()::container_status( $container ) ) { | ||
| chdir( EE_CONF_ROOT ); | ||
| EE::docker()::boot_container( $container, 'docker-compose up -d ' . $container ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Generates global docker-compose.yml at EE_CONF_ROOT | ||
| * | ||
| * @param Filesystem $fs Filesystem object to write file | ||
| */ | ||
| function generate_global_docker_compose_yml( Filesystem $fs ) { | ||
| $img_versions = EE\Utils\get_image_versions(); | ||
|
|
||
| $data = [ | ||
| 'services' => [ | ||
| [ | ||
| 'name' => 'global-nginx-proxy', | ||
| 'container_name' => EE_PROXY_TYPE, | ||
| 'image' => 'easyengine/nginx-proxy:' . $img_versions['easyengine/nginx-proxy'], | ||
| 'restart' => 'always', | ||
| 'ports' => [ | ||
| '80:80', | ||
| '443:443', | ||
| ], | ||
| 'environment' => [ | ||
| 'LOCAL_USER_ID=' . posix_geteuid(), | ||
| 'LOCAL_GROUP_ID=' . posix_getegid(), | ||
| ], | ||
| 'volumes' => [ | ||
| EE_CONF_ROOT . '/nginx/certs:/etc/nginx/certs', | ||
| EE_CONF_ROOT . '/nginx/dhparam:/etc/nginx/dhparam', | ||
| EE_CONF_ROOT . '/nginx/conf.d:/etc/nginx/conf.d', | ||
| EE_CONF_ROOT . '/nginx/htpasswd:/etc/nginx/htpasswd', | ||
| EE_CONF_ROOT . '/nginx/vhost.d:/etc/nginx/vhost.d', | ||
| EE_CONF_ROOT . '/nginx/html:/usr/share/nginx/html', | ||
| '/var/run/docker.sock:/tmp/docker.sock:ro', | ||
| ], | ||
| 'networks' => [ | ||
| 'global-frontend-network', | ||
| ], | ||
| ], | ||
| [ | ||
| 'name' => GLOBAL_DB, | ||
| 'container_name' => GLOBAL_DB_CONTAINER, | ||
| 'image' => 'easyengine/mariadb:' . $img_versions['easyengine/mariadb'], | ||
| 'restart' => 'always', | ||
| 'environment' => [ | ||
| 'MYSQL_ROOT_PASSWORD=' . \EE\Utils\random_password(), | ||
| ], | ||
| 'volumes' => [ './app/db:/var/lib/mysql' ], | ||
| 'networks' => [ | ||
| 'global-backend-network', | ||
| ], | ||
| ], | ||
| [ | ||
| 'name' => GLOBAL_REDIS, | ||
| 'container_name' => GLOBAL_REDIS_CONTAINER, | ||
| 'image' => 'easyengine/redis:' . $img_versions['easyengine/redis'], | ||
| 'restart' => 'always', | ||
| 'volumes' => [ EE_CONF_ROOT . '/services/redis:/data' ], | ||
| 'networks' => [ | ||
| 'global-backend-network', | ||
| ], | ||
| ], | ||
| ], | ||
| ]; | ||
|
|
||
| $contents = EE\Utils\mustache_render( SERVICE_TEMPLATE_ROOT . '/global_docker_compose.yml.mustache', $data ); | ||
| $fs->dumpFile( EE_CONF_ROOT . '/docker-compose.yml', $contents ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| version: '3.5' | ||
|
|
||
| services: | ||
|
|
||
| {{#services}} | ||
| {{name}}: | ||
| container_name: {{container_name}} | ||
| image: {{image}} | ||
| {{#ports.0}} | ||
| ports: | ||
| {{#ports}} | ||
| - "{{.}}" | ||
| {{/ports}} | ||
| {{/ports.0}} | ||
| {{#depends_on}} | ||
| depends_on: | ||
| - {{.}} | ||
| {{/depends_on}} | ||
| {{#restart}} | ||
| restart: {{.}} | ||
| {{/restart}} | ||
| {{#command}} | ||
| command: {{.}} | ||
| {{/command}} | ||
| {{#labels.0}} | ||
| labels: | ||
| {{#labels}} | ||
| - "{{.}}" | ||
| {{/labels}} | ||
| {{/labels.0}} | ||
| {{#volumes.0}} | ||
| volumes: | ||
| {{#volumes}} | ||
| - "{{.}}" | ||
| {{/volumes}} | ||
| {{/volumes.0}} | ||
| {{#environment.0}} | ||
| environment: | ||
| {{#environment}} | ||
| - {{.}} | ||
| {{/environment}} | ||
| {{/environment.0}} | ||
| {{#networks.0}} | ||
| networks: | ||
| {{#networks}} | ||
| - {{.}} | ||
| {{/networks}} | ||
| {{/networks.0}} | ||
| {{/services}} | ||
|
|
||
| networks: | ||
| global-frontend-network: | ||
| external: | ||
| name: ee-global-frontend-network | ||
| global-backend-network: | ||
| external: | ||
| name: ee-global-backend-network | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.