From fe3ca9c20695462d3e83ad9cf864ce237d323e3f Mon Sep 17 00:00:00 2001 From: Mohamed Sakr Date: Fri, 9 Aug 2024 15:22:07 +0300 Subject: [PATCH] [1.x] added elasticsearch as service to sail --- .../InteractsWithDockerComposeServices.php | 8 ++++- stubs/elasticsearch.stub | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 stubs/elasticsearch.stub diff --git a/src/Console/Concerns/InteractsWithDockerComposeServices.php b/src/Console/Concerns/InteractsWithDockerComposeServices.php index 0404525b..b6a80b60 100644 --- a/src/Console/Concerns/InteractsWithDockerComposeServices.php +++ b/src/Console/Concerns/InteractsWithDockerComposeServices.php @@ -20,6 +20,7 @@ trait InteractsWithDockerComposeServices 'memcached', 'meilisearch', 'typesense', + 'elasticsearch', 'minio', 'mailpit', 'selenium', @@ -99,7 +100,7 @@ protected function buildDockerCompose(array $services) // Merge volumes... collect($services) ->filter(function ($service) { - return in_array($service, ['mysql', 'pgsql', 'mariadb', 'redis', 'meilisearch', 'typesense', 'minio']); + return in_array($service, ['mysql', 'pgsql', 'mariadb', 'redis', 'meilisearch', 'typesense', 'minio', 'elasticsearch']); })->filter(function ($service) use ($compose) { return ! array_key_exists($service, $compose['volumes'] ?? []); })->each(function ($service) use (&$compose) { @@ -185,6 +186,11 @@ protected function replaceEnvVariables(array $services) $environment .= "\nTYPESENSE_API_KEY=xyz\n"; } + if (in_array('elasticsearch', $services)) { + $environment .= "\nSCOUT_DRIVER=elastic"; + $environment .= "\nELASTICSEARCH_HOST=http://elasticsearch:9200\n"; + } + if (in_array('soketi', $services)) { $environment = preg_replace("/^BROADCAST_DRIVER=(.*)/m", "BROADCAST_DRIVER=pusher", $environment); $environment = preg_replace("/^PUSHER_APP_ID=(.*)/m", "PUSHER_APP_ID=app-id", $environment); diff --git a/stubs/elasticsearch.stub b/stubs/elasticsearch.stub new file mode 100644 index 00000000..688ce2a2 --- /dev/null +++ b/stubs/elasticsearch.stub @@ -0,0 +1,30 @@ +elasticsearch: + image: docker.elastic.co/elasticsearch/elasticsearch:8.7.1 + ports: + - '${FORWARD_ELASTICSEARCH_PORT:-9200}:9200' + environment: + - discovery.type=single-node + - bootstrap.memory_lock=true + - "ES_JAVA_OPTS=-Xms1g -Xmx1g" + - xpack.security.enabled=false + - xpack.security.enrollment.enabled=false + volumes: + - sail-elasticsearch:/usr/share/elasticsearch/data + networks: + - sail + ulimits: + memlock: + soft: -1 + hard: -1 + deploy: + resources: + limits: + cpus: '2.0' + reservations: + cpus: '1.0' + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9200/_cluster/health"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 30s \ No newline at end of file