diff --git a/inc/composer/class-docker-compose-generator.php b/inc/composer/class-docker-compose-generator.php index f8b2477..f495e0d 100644 --- a/inc/composer/class-docker-compose-generator.php +++ b/inc/composer/class-docker-compose-generator.php @@ -225,20 +225,40 @@ protected function get_php_reusable() : array { return $services; } + /** + * Default memory limit for all services that don't specify one. + * + * @param $args + * + * @return array + */ + protected function apply_service_defaults( $args ) : array { + $mem_limit = getenv( 'LS_MEM_LIMIT' ) ?: '1g'; + foreach ( $args as $service => $service_args ) { + if ( isset( $service_args['mem_limit'] ) ) { + continue; + } + $args[ $service ]['mem_limit'] = $mem_limit; + } + + return $args; + } + + /** * Get the PHP container service. * * @return array */ protected function get_service_php() : array { - return [ + return $this->apply_service_defaults( [ 'php' => array_merge( [ 'container_name' => "{$this->project_name}-php", ], $this->get_php_reusable() ), - ]; + ] ); } /** @@ -253,7 +273,7 @@ protected function get_service_nodejs() : array { $package_json = json_decode( file_get_contents( "{$config['nodejs']['path']}/package.json" ), true ); $version = $package_json['engines']['node'] ?? '20'; - return [ + return $this->apply_service_defaults( [ 'nodejs' => [ 'image' => "node:{$version}-bookworm-slim", 'container_name' => "{$this->project_name}-nodejs", @@ -282,7 +302,7 @@ protected function get_service_nodejs() : array { 'ALTIS_ENVIRONMENT_TYPE' => 'local', ], ], - ]; + ] ); } /** @@ -291,7 +311,7 @@ protected function get_service_nodejs() : array { * @return array */ protected function get_service_webgrind() : array { - return [ + return $this->apply_service_defaults( [ 'webgrind' => [ 'container_name' => "{$this->project_name}-webgrind", 'image' => 'wodby/webgrind:1.9', @@ -318,7 +338,7 @@ protected function get_service_webgrind() : array { 'WEBGRIND_DEFAULT_TIMEZONE' => 'UTC', ], ], - ]; + ] ); } /** @@ -327,7 +347,7 @@ protected function get_service_webgrind() : array { * @return array */ protected function get_service_cavalcade() : array { - return [ + return $this->apply_service_defaults( [ 'cavalcade' => array_merge( [ 'container_name' => "{$this->project_name}-cavalcade", @@ -339,7 +359,7 @@ protected function get_service_cavalcade() : array { ], $this->get_php_reusable() ), - ]; + ] ); } /** @@ -352,7 +372,7 @@ protected function get_service_nginx() : array { $domains = $config['domains'] ?? []; $domains = $domains ? ',' . implode( ',', $domains ) : ''; - return [ + return $this->apply_service_defaults( [ 'nginx' => [ 'image' => 'humanmade/altis-local-server-nginx:3.6.0', 'container_name' => "{$this->project_name}-nginx", @@ -387,7 +407,7 @@ protected function get_service_nginx() : array { 'PHP_PUBLIC_POOL_ENABLE_RATE_LIMIT' => 'false', ], ], - ]; + ] ); } /** @@ -396,7 +416,7 @@ protected function get_service_nginx() : array { * @return array */ protected function get_service_redis() : array { - return [ + return $this->apply_service_defaults( [ 'redis' => [ 'image' => 'redis:7.0-alpine', 'container_name' => "{$this->project_name}-redis", @@ -404,7 +424,7 @@ protected function get_service_redis() : array { '6379', ], ], - ]; + ] ); } /** @@ -433,7 +453,7 @@ protected function get_service_db() : array { $image = $version_map[ $version ]; - return [ + return $this->apply_service_defaults( [ 'db' => [ 'image' => $image, // Suppress mysql_native_password deprecation warning @@ -468,7 +488,7 @@ protected function get_service_db() : array { 'retries' => 10, ], ], - ]; + ] ); } /** @@ -477,7 +497,7 @@ protected function get_service_db() : array { * @return array */ protected function get_service_s3() : array { - return [ + return $this->apply_service_defaults( [ 's3' => [ 'image' => 'minio/minio:RELEASE.2021-09-18T18-09-59Z', 'container_name' => "{$this->project_name}-s3", @@ -560,7 +580,7 @@ protected function get_service_s3() : array { ], 'entrypoint' => "/bin/sh -c \"mc mirror --watch --overwrite -a local/{$this->bucket_name} /content\"", ], - ]; + ] ); } /** @@ -569,7 +589,7 @@ protected function get_service_s3() : array { * @return array */ protected function get_service_tachyon() : array { - return [ + return $this->apply_service_defaults( [ 'tachyon' => [ 'image' => 'humanmade/tachyon:v3.0.7', 'container_name' => "{$this->project_name}-tachyon", @@ -596,7 +616,7 @@ protected function get_service_tachyon() : array { "proxy:s3-{$this->hostname}", ], ], - ]; + ] ); } /** @@ -605,7 +625,7 @@ protected function get_service_tachyon() : array { * @return array */ protected function get_service_mailhog() : array { - return [ + return $this->apply_service_defaults( [ 'mailhog' => [ 'image' => 'cd2team/mailhog:latest', 'container_name' => "{$this->project_name}-mailhog", @@ -627,7 +647,7 @@ protected function get_service_mailhog() : array { 'MH_UI_WEB_PATH' => 'mailhog', ], ], - ]; + ] ); } /** @@ -636,7 +656,7 @@ protected function get_service_mailhog() : array { * @return array */ protected function get_service_analytics() : array { - return [ + return $this->apply_service_defaults( [ 'cognito' => [ 'container_name' => "{$this->project_name}-cognito", 'ports' => [ @@ -678,7 +698,7 @@ protected function get_service_analytics() : array { 'INDEX_ROTATION' => 'OneDay', ], ], - ]; + ] ); } /** @@ -687,7 +707,7 @@ protected function get_service_analytics() : array { * @return array */ protected function get_service_xray() : array { - return [ + return $this->apply_service_defaults( [ 'xray' => [ 'image' => 'amazon/aws-xray-daemon:3.3.3', 'container_name' => "{$this->project_name}-xray", @@ -700,7 +720,7 @@ protected function get_service_xray() : array { 'AWS_REGION' => 'us-east-1', ], ], - ]; + ] ); } /** @@ -751,7 +771,6 @@ public function get_array() : array { // Default compose configuration. $config = [ - // 'version' => '2.5', 'services' => $services, 'networks' => [ 'default' => null,