Skip to content

Commit

Permalink
initial elasticsearch commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybellwood committed Nov 2, 2023
1 parent 301ee63 commit 97e2748
Show file tree
Hide file tree
Showing 11 changed files with 436 additions and 247 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Local project name - setting this here aligns container names with routes
COMPOSE_PROJECT_NAME=drupal-opensearch
COMPOSE_PROJECT_NAME=drupal-elasticsearch
4 changes: 2 additions & 2 deletions .github/workflows/drupal-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on:
branches:
- 'main'
- 'dev'
- 'opensearch'
- 'elasticsearch'
pull_request:
branches:
- 'main'
- 'opensearch'
- 'elasticsearch'

jobs:
test-suite:
Expand Down
2 changes: 1 addition & 1 deletion .lagoon.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
docker-compose-yaml: docker-compose.yml

project: drupal-opensearch
project: drupal-elasticsearch

tasks:
# pre-rollout:
Expand Down
2 changes: 1 addition & 1 deletion .lando.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: drupal-opensearch
name: drupal-elasticsearch
recipe: lagoon
config:
flavor: drupal
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Base template for Drupal projects hosted on Lagoon
# Base template for Drupal Elasticsearch projects hosted on Lagoon

This template includes everything necessary to run on [Lagoon](https://www.github.com/uselagoon/lagoon) (in both the local development environments or on hosted Lagoon clusters.)

Expand All @@ -12,6 +12,7 @@ This example contains the following services:
* PHP 8
* NGINX
* MariaDB 10.11
* ElasticSearch 7.10 - Note that this image is no longer supported or maintained

To see similar projects with additional services, please visit https://github.com/lagoon-examples and to find out more about the services, please visit the documentation at https://docs.lagoon.sh/lagoon

Expand All @@ -29,7 +30,7 @@ To see similar projects with additional services, please visit https://github.co
1. Checkout this project repo and confirm the path is in Docker's file sharing config - https://docs.docker.com/docker-for-mac/#file-sharing

```bash
git clone https://github.com/lagoon-examples/drupal-opensearch.git drupal-opensearch && cd $_
git clone https://github.com/lagoon-examples/drupal-elasticsearch.git drupal-elasticsearch && cd $_
```

2. Make sure you don't have anything running on port 80 on the host machine (like a web server) then run `pygmy-go up`
Expand All @@ -41,7 +42,7 @@ To see similar projects with additional services, please visit https://github.co
docker-compose exec cli composer install
```
4. Visit the new site @ `http://drupal-opensearch.docker.amazee.io`
4. Visit the new site @ `http://drupal-elasticsearch.docker.amazee.io`
* If any steps fail, you're safe to rerun from any point.
Starting again from the beginning will just reconfirm the changes.
Expand All @@ -55,7 +56,7 @@ This repository is set up with a `.lando.yml` file, which allows you to use Land
2. Checkout the project repo and confirm the path is in Docker's file sharing config - https://docs.docker.com/docker-for-mac/#file-sharing
```bash
git clone https://github.com/lagoon-examples/drupal-opensearch.git drupal-opensearch && cd $_
git clone --branch elasticsearch https://github.com/lagoon-examples/drupal-opensearch.git drupal-elasticsearch && cd $_
```
3. Make sure you have pygmy-go stopped. Run `pygmy stop` to be sure.
Expand All @@ -72,7 +73,7 @@ lando start
lando drush si -y
```
6. Visit the new site @ `http://drupal-opensearch.lndo.site`
6. Visit the new site @ `http://drupal-elasticsearch.lndo.site`
7. For more information on how to configure your site, check out the [documentation](https://docs.lando.dev/config/lagoon.html).
Expand Down
74 changes: 37 additions & 37 deletions TESTING_dockercompose.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Docker Compose Drupal Opensearch option - php8, nginx, mariadb, opensearch
============================================================================
Docker Compose Drupal Elasticsearch option - php8, nginx, mariadb, elasticsearch
================================================================================

This is a docker-compose version of the Lando example tests:
This is a docker compose version of the Lando example tests:

Start up tests
--------------
Expand All @@ -12,13 +12,13 @@ Run the following commands to get up and running with this example.
# Should remove any previous runs and poweroff
sed -i -e "/###/d" docker-compose.yml
docker network inspect amazeeio-network >/dev/null || docker network create amazeeio-network
docker-compose down
docker compose down

# Should start up our Lagoon Drupal site successfully
docker-compose build && docker-compose up -d
docker compose build && docker compose up -d

# Ensure mariadb pod is ready to connect
docker run --rm --net drupal-opensearch_default amazeeio/dockerize dockerize -wait tcp://mariadb:3306 -timeout 1m
docker run --rm --net drupal-elasticsearch-default amazeeio/dockerize dockerize -wait tcp://mariadb:3306 -timeout 1m
```

Verification commands
Expand All @@ -28,66 +28,66 @@ Run the following commands to validate things are rolling as they should.

```bash
# Should be able to site install via Drush
docker-compose exec -T cli bash -c "drush si -y"
docker-compose exec -T cli bash -c "drush cr -y"
docker-compose exec -T cli bash -c "drush status" | grep "Drupal bootstrap" | grep "Successful"
docker compose exec -T cli bash -c "drush si -y"
docker compose exec -T cli bash -c "drush cr -y"
docker compose exec -T cli bash -c "drush status" | grep "Drupal bootstrap" | grep "Successful"

# Should have all the services we expect
docker ps --filter label=com.docker.compose.project=drupal-opensearch | grep Up | grep drupal-opensearch_nginx_1
docker ps --filter label=com.docker.compose.project=drupal-opensearch | grep Up | grep drupal-opensearch_mariadb_1
docker ps --filter label=com.docker.compose.project=drupal-opensearch | grep Up | grep drupal-opensearch_php_1
docker ps --filter label=com.docker.compose.project=drupal-opensearch | grep Up | grep drupal-opensearch_cli_1
docker ps --filter label=com.docker.compose.project=drupal-opensearch | grep Up | grep drupal-opensearch_opensearch_1
docker ps --filter label=com.docker.compose.project=drupal-elasticsearch | grep Up | grep drupal-elasticsearch-nginx-1
docker ps --filter label=com.docker.compose.project=drupal-elasticsearch | grep Up | grep drupal-elasticsearch-mariadb-1
docker ps --filter label=com.docker.compose.project=drupal-elasticsearch | grep Up | grep drupal-elasticsearch-php-1
docker ps --filter label=com.docker.compose.project=drupal-elasticsearch | grep Up | grep drupal-elasticsearch-cli-1
docker ps --filter label=com.docker.compose.project=drupal-elasticsearch | grep Up | grep drupal-elasticsearch-elasticsearch-1

# Should ssh against the cli container by default
docker-compose exec -T cli bash -c "env | grep LAGOON=" | grep cli-drupal
docker compose exec -T cli bash -c "env | grep LAGOON=" | grep cli-drupal

# Should have the correct environment set
docker-compose exec -T cli bash -c "env" | grep LAGOON_ROUTE | grep drupal-opensearch.docker.amazee.io
docker-compose exec -T cli bash -c "env" | grep LAGOON_ENVIRONMENT_TYPE | grep development
docker compose exec -T cli bash -c "env" | grep LAGOON_ROUTE | grep drupal-elasticsearch.docker.amazee.io
docker compose exec -T cli bash -c "env" | grep LAGOON_ENVIRONMENT_TYPE | grep development

# Should be running PHP 8
docker-compose exec -T cli bash -c "php -v" | grep "PHP 8"
docker compose exec -T cli bash -c "php -v" | grep "PHP 8"

# Should have composer
docker-compose exec -T cli bash -c "composer --version"
docker compose exec -T cli bash -c "composer --version"

# Should have php cli
docker-compose exec -T cli bash -c "php --version"
docker compose exec -T cli bash -c "php --version"

# Should have drush
docker-compose exec -T cli bash -c "drush --version"
docker compose exec -T cli bash -c "drush --version"

# Should have npm
docker-compose exec -T cli bash -c "npm --version"
docker compose exec -T cli bash -c "npm --version"

# Should have node
docker-compose exec -T cli bash -c "node --version"
docker compose exec -T cli bash -c "node --version"

# Should have yarn
docker-compose exec -T cli bash -c "yarn --version"
docker compose exec -T cli bash -c "yarn --version"

# Should have a running Drupal site served by nginx on port 8080
docker-compose exec -T cli bash -c "curl -kL http://nginx:8080" | grep "Drush Site-Install"
docker compose exec -T cli bash -c "curl -kL http://nginx:8080" | grep "Drush Site-Install"

# Should have Opensearch running
docker-compose exec -T cli bash -c "curl -kL http://opensearch:9200" | grep "docker-cluster"
# Should have Elasticsearch running
docker compose exec -T cli bash -c "curl -kL http://elasticsearch:9200" | grep "docker-cluster"

# Should have Opensearch cluster healthy
docker-compose exec -T cli bash -c "curl -kL http://opensearch:9200/_cluster/health" | json_pp | grep status | grep -v red
# Should have Elasticsearch cluster healthy
docker compose exec -T cli bash -c "curl -kL http://elasticsearch:9200/_cluster/health" | json_pp | grep status | grep -v red

# Should be able to db-export and db-import the database
docker-compose exec -T cli bash -c "drush sql-dump --result-file /app/test.sql"
docker-compose exec -T cli bash -c "drush sql-drop -y"
docker-compose exec -T cli bash -c "drush sql-cli < /app/test.sql"
docker-compose exec -T cli bash -c "rm test.sql*"
docker compose exec -T cli bash -c "drush sql-dump --result-file /app/test.sql"
docker compose exec -T cli bash -c "drush sql-drop -y"
docker compose exec -T cli bash -c "drush sql-cli < /app/test.sql"
docker compose exec -T cli bash -c "rm test.sql*"

# Should be able to show the drupal tables
docker-compose exec -T cli bash -c "drush sqlq \'show tables;\'" | grep users
docker compose exec -T cli bash -c "drush sqlq \'show tables;\'" | grep users

# Should be able to rebuild and persist the database
docker-compose build && docker-compose up -d
docker-compose exec -T cli bash -c "drush sqlq \'show tables;\'" | grep users
docker compose build && docker compose up -d
docker compose exec -T cli bash -c "drush sqlq \'show tables;\'" | grep users
```

Destroy tests
Expand All @@ -97,5 +97,5 @@ Run the following commands to trash this app like nothing ever happened.

```bash
# Should be able to destroy our Drupal site with success
docker-compose down --volumes --remove-orphans
docker compose down --volumes --remove-orphans
```
2 changes: 1 addition & 1 deletion TESTING_lando.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ docker ps --filter label=com.docker.compose.project=drupalopensearch | grep Up |
lando ssh -c "env | grep LAGOON=" | grep cli-drupal

# Should have the correct environment set
lando ssh -c "env" | grep LAGOON_ROUTE | grep drupal-opensearch.lndo.site
lando ssh -c "env" | grep LAGOON_ROUTE | grep drupal-elasticsearch.lndo.site
lando ssh -c "env" | grep LAGOON_ENVIRONMENT_TYPE | grep development

# Should be running PHP 8
Expand Down
19 changes: 11 additions & 8 deletions assets/all.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
$settings['skip_permissions_hardening'] = TRUE;
}

### Lagoon Opensearch connection.
// WARNING: you have to create a search_api server having "opensearch" machine name at
// /admin/config/search/search-api/add-server to make this work.
### Lagoon Elasticsearch connection.
// WARNING: you have to create an elasticsearch cluster called "elastic" at
// /admin/config/search/elasticsearch-connector and a search_api server called
// "elastic" at /admin/config/search/search-api/add-server to make this work.
if (getenv('LAGOON')) {
$config['search_api.server.opensearch']['backend_config']['connector_config']['url'] = getenv('OPENSEARCH_HOST') ?: 'http://opensearch';
$config['search_api.server.opensearch']['backend_config']['connector']= 'standard';
$config['search_api.server.opensearch']['backend'] = 'opensearch';
$config['search_api.server.opensearch']['name'] = 'Lagoon opensearch - Environment: ' . getenv('LAGOON_PROJECT');
}
$config['elasticsearch_connector.cluster.elastic']['cluster_id'] = 'elastic';
$config['elasticsearch_connector.cluster.elastic']['name'] = 'elastic';
$config['elasticsearch_connector.cluster.elastic']['status'] = '1';
$config['elasticsearch_connector.cluster.elastic']['url'] = 'http://elasticsearch:9200';
$config['search_api.server.elastic']['backend_config']['cluster_settings']['cluster'] = 'elastic';
$config['search_api.server.elastic']['name'] = 'Lagoon Elastic - Environment: ' . getenv('LAGOON_PROJECT');
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "lagoon-examples/drupal-opensearch",
"name": "lagoon-examples/drupal-elasticsearch",
"description": "Project template for Drupal projects with MariaDB, hosted on Lagoon",
"type": "project",
"license": "GPL-2.0-or-later",
Expand All @@ -23,9 +23,9 @@
"drupal/core-composer-scaffold": "10.1.6",
"drupal/core-project-message": "10.1.6",
"drupal/core-recommended": "10.1.6",
"drupal/elasticsearch_connector": "7.0-alpha4",
"drupal/lagoon_logs": "3.0.0",
"drupal/search_api": "1.30.0",
"drupal/search_api_opensearch": "2.0.0-beta3",
"drush/drush": "12.4.2",
"zaporylie/composer-drupal-optimizations": "1.2.0"
},
Expand Down
Loading

0 comments on commit 97e2748

Please sign in to comment.