From 3e045fc636999bbd5395ab4adeda4e2225ca70a4 Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Thu, 21 Oct 2021 20:44:30 -0700 Subject: [PATCH 1/6] #3: Initial ES test. --- .github/workflows/pr-elasticsearch-tests.yml | 75 +++++ examples/elasticsearch-6.5/.editorconfig | 20 ++ examples/elasticsearch-6.5/.gitignore | 11 + examples/elasticsearch-6.5/.lando.yml | 10 + examples/elasticsearch-6.5/.platform.app.yaml | 11 + .../elasticsearch-6.5/.platform/routes.yaml | 8 + .../elasticsearch-6.5/.platform/services.yaml | 2 + examples/elasticsearch-6.5/README.md | 61 ++++ examples/elasticsearch-6.5/composer.json | 16 + examples/elasticsearch-6.5/composer.lock | 316 ++++++++++++++++++ examples/elasticsearch-6.5/esearch.php | 98 ++++++ examples/elasticsearch-6.5/index.php | 1 + 12 files changed, 629 insertions(+) create mode 100644 .github/workflows/pr-elasticsearch-tests.yml create mode 100644 examples/elasticsearch-6.5/.editorconfig create mode 100644 examples/elasticsearch-6.5/.gitignore create mode 100644 examples/elasticsearch-6.5/.lando.yml create mode 100644 examples/elasticsearch-6.5/.platform.app.yaml create mode 100644 examples/elasticsearch-6.5/.platform/routes.yaml create mode 100644 examples/elasticsearch-6.5/.platform/services.yaml create mode 100644 examples/elasticsearch-6.5/README.md create mode 100644 examples/elasticsearch-6.5/composer.json create mode 100644 examples/elasticsearch-6.5/composer.lock create mode 100644 examples/elasticsearch-6.5/esearch.php create mode 100644 examples/elasticsearch-6.5/index.php diff --git a/.github/workflows/pr-elasticsearch-tests.yml b/.github/workflows/pr-elasticsearch-tests.yml new file mode 100644 index 0000000..308d3f2 --- /dev/null +++ b/.github/workflows/pr-elasticsearch-tests.yml @@ -0,0 +1,75 @@ +name: Elasticsearch Tests + +on: + pull_request: + +jobs: + leia-tests: + runs-on: ${{ matrix.os }} + env: + TERM: xterm + strategy: + matrix: + leia-tests: + - examples/elasticsearch-6.5 + # - examples/elasticsearch-6.8 + # - examples/elasticsearch-7.2 + # - examples/elasticsearch-7.5 + # - examples/elasticsearch-7.7 + # - examples/elasticsearch-7.9 + # - examples/elasticsearch-7.10 + lando-versions: + - edge + os: + - ubuntu-20.04 + node-version: + - '14' + + steps: + # Install deps and cache + - name: Checkout code + uses: actions/checkout@v2 + - name: Install node ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + cache: yarn + - name: Install Yarn dependencies + run: yarn install --prefer-offline --frozen-lockfile + + # This block should eventually become use lando/actions-hyperdrive@v2 + - name: Verify Docker dependencies + run: | + docker --version | grep "20.10." + docker-compose --version | grep "1.29." + - name: Grab latest edge Lando CLI + run: | + sudo curl -fsSL -o /usr/local/bin/lando "https://files.lando.dev/cli/lando-linux-x64-${{ matrix.lando-versions }}" + sudo chmod +x /usr/local/bin/lando + - name: Move in lando config appropriate for testing + run: | + mkdir -p ~/.lando/cache + cp -f actions-lando-config.yml ~/.lando/config.yml + echo false > ~/.lando/cache/report_errors + lando --clear + - name: Verify Lando works and we are dogfooding this plugin for tests + run: | + lando version + lando config --path plugins | grep platformsh | grep /home/runner/work/platformsh/platformsh || echo "::error:: Not dogfooding this plugin correctly! " + cd ${{ matrix.leia-tests }} + lando config --path plugins | grep platformsh | grep dir | grep /home/runner/work/platformsh/platformsh || echo "::error:: Not dogfooding this plugin correctly! " + + # This block should eventually become use lando/actions-leia@v2 + # @NOTE? Do we want a way for our leia-action to configure apparmor since + # this might break a whole bunch of tests? or is this literally just a thing + # for the platform.sh mysql/mariadb container? + - name: Configure apparmor + run: | + set -x + sudo apt-get remove mysql-server --purge + sudo apt-get install apparmor-profiles + sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld + - name: Run leia tests + shell: bash + run: yarn leia "./${{ matrix.leia-tests }}/README.md" -c 'Destroy tests' --stdin --shell bash + diff --git a/examples/elasticsearch-6.5/.editorconfig b/examples/elasticsearch-6.5/.editorconfig new file mode 100644 index 0000000..9371936 --- /dev/null +++ b/examples/elasticsearch-6.5/.editorconfig @@ -0,0 +1,20 @@ +# Drupal editor configuration normalization +# @see http://editorconfig.org/ + +# This is the top-most .editorconfig file; do not search in parent directories. +root = true + +# All files. +[*] +end_of_line = LF +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[composer.{json,lock}] +indent_size = 4 + +[.platform.app.yaml] +indent_size = 4 diff --git a/examples/elasticsearch-6.5/.gitignore b/examples/elasticsearch-6.5/.gitignore new file mode 100644 index 0000000..84200aa --- /dev/null +++ b/examples/elasticsearch-6.5/.gitignore @@ -0,0 +1,11 @@ +vendor +files +data +private +.platform/local + +*.sql +*.tar.gz +*.tar + +.DS_Store diff --git a/examples/elasticsearch-6.5/.lando.yml b/examples/elasticsearch-6.5/.lando.yml new file mode 100644 index 0000000..4819862 --- /dev/null +++ b/examples/elasticsearch-6.5/.lando.yml @@ -0,0 +1,10 @@ +name: lando-platformsh-elasticsearch-6.5 +recipe: platformsh +config: + id: DISCONNECTED + + +# This is important because it lets lando know to test against the plugin in this repo +# DO NOT REMOVE THIS! +plugins: + "@lando/platformsh": ./../../ diff --git a/examples/elasticsearch-6.5/.platform.app.yaml b/examples/elasticsearch-6.5/.platform.app.yaml new file mode 100644 index 0000000..08e711d --- /dev/null +++ b/examples/elasticsearch-6.5/.platform.app.yaml @@ -0,0 +1,11 @@ +name: app +type: "php:7.3" +build: + flavor: composer +web: + locations: + "/": + root: "." + passthru: "/index.php" +relationships: + elasticsearch: "searchelastic:elasticsearch" diff --git a/examples/elasticsearch-6.5/.platform/routes.yaml b/examples/elasticsearch-6.5/.platform/routes.yaml new file mode 100644 index 0000000..b588ae0 --- /dev/null +++ b/examples/elasticsearch-6.5/.platform/routes.yaml @@ -0,0 +1,8 @@ +# The routes of the project. +# +# Each route describes how an incoming URL is going +# to be processed by Platform.sh. + +"https://{default}/": + type: upstream + upstream: "app:http" diff --git a/examples/elasticsearch-6.5/.platform/services.yaml b/examples/elasticsearch-6.5/.platform/services.yaml new file mode 100644 index 0000000..64548a1 --- /dev/null +++ b/examples/elasticsearch-6.5/.platform/services.yaml @@ -0,0 +1,2 @@ +searchelastic: + type: elasticsearch:6.5 diff --git a/examples/elasticsearch-6.5/README.md b/examples/elasticsearch-6.5/README.md new file mode 100644 index 0000000..626e73d --- /dev/null +++ b/examples/elasticsearch-6.5/README.md @@ -0,0 +1,61 @@ +Platform.sh elasticsearch 6.5 Example +================================= + +This example exists to test this plugin's implementation of Platform.sh's `elasticsearch:6.5` service. + +* [`elasticsearch:6.5`](https://docs.platform.sh/configuration/services/elasticsearch.html) + +Start up tests +-------------- + +Run the following commands to get up and running with this example. + +```bash +# Should poweroff +lando poweroff + +# Should start up successfully +lando start +``` + +Verification commands +--------------------- + +Run the following commands to validate things are rolling as they should. + +```bash +# Should have the expected platformsh containers and images +docker ps --filter label=com.docker.compose.project=landoplatformshelasticsearch65 | grep docker.registry.platform.sh/php-7.3 | grep landoplatformshelasticsearch65_app_1 +docker ps --filter label=com.docker.compose.project=landoplatformshelasticsearch65 | grep docker.registry.platform.sh/elasticsearch-6.5 | grep landoplatformshelasticsearch65_searchelastic_1 + +# Should be running all application containers as web +lando ssh -s app -c "id" | grep web + +# Should have the platform cli in all application containers +lando ssh -s app -c "platform -V" + +# Should be running the correct php version +lando ssh -s app -c "php --version" | grep 7.3. + +# Should be running all elasticsearch containers as elasticsearch +lando ssh -s searchelastic -c "id" | grep elasticsearch + +# Should be running the correct elasticsearch versions +lando ssh -s searchelastic -c "curl -XGET 'http://localhost:9200'" | grep 6.5 + +# Should be able to connect to elasticsearch from the application containers +lando ssh -s app -c "curl localhost/esearch.php" | grep "Barbara Liskov" +``` + +Destroy tests +------------- + +Run the following commands to trash this app like nothing ever happened. + +```bash +# Should be able to destroy our app +lando destroy -y + +# Should poweroff +lando poweroff +``` diff --git a/examples/elasticsearch-6.5/composer.json b/examples/elasticsearch-6.5/composer.json new file mode 100644 index 0000000..cf20530 --- /dev/null +++ b/examples/elasticsearch-6.5/composer.json @@ -0,0 +1,16 @@ +{ + "name": "lando/platformsh-elasticsearch-6.5", + "description": "A basic application to test Lando's implementation of platformsh's elasticsearch 6.5 service.", + "license": "MIT", + "type" : "project", + "require": { + "php": ">7.2", + "platformsh/config-reader": "~2.0", + "elasticsearch/elasticsearch": "~6.5.0" + }, + "autoload": { + "psr-4": { + "App\\": "src/" + } + } +} diff --git a/examples/elasticsearch-6.5/composer.lock b/examples/elasticsearch-6.5/composer.lock new file mode 100644 index 0000000..fe43232 --- /dev/null +++ b/examples/elasticsearch-6.5/composer.lock @@ -0,0 +1,316 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "11516b95c0b5b9282f5aee43f1ddba76", + "packages": [ + { + "name": "elasticsearch/elasticsearch", + "version": "v6.5.1", + "source": { + "type": "git", + "url": "https://github.com/elastic/elasticsearch-php.git", + "reference": "0c93d0e5b852634159d9f349b1848acde845400b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/elastic/elasticsearch-php/zipball/0c93d0e5b852634159d9f349b1848acde845400b", + "reference": "0c93d0e5b852634159d9f349b1848acde845400b", + "shasum": "" + }, + "require": { + "ext-json": ">=1.3.7", + "guzzlehttp/ringphp": "~1.0", + "php": "^7.0", + "psr/log": "~1.0" + }, + "require-dev": { + "cpliakas/git-wrapper": "~1.0", + "doctrine/inflector": "^1.1", + "mockery/mockery": "^1.2", + "phpstan/phpstan-shim": "^0.9 || ^0.11", + "phpunit/phpunit": "^5.7 || ^6.5", + "squizlabs/php_codesniffer": "^3.4", + "symfony/finder": "^2.8", + "symfony/yaml": "^2.8" + }, + "suggest": { + "ext-curl": "*", + "monolog/monolog": "Allows for client-level logging and tracing" + }, + "type": "library", + "autoload": { + "psr-4": { + "Elasticsearch\\": "src/Elasticsearch/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Zachary Tong" + }, + { + "name": "Enrico Zimuel" + } + ], + "description": "PHP Client for Elasticsearch", + "keywords": [ + "client", + "elasticsearch", + "search" + ], + "time": "2019-07-19T13:34:35+00:00" + }, + { + "name": "guzzlehttp/ringphp", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/RingPHP.git", + "reference": "5e2a174052995663dd68e6b5ad838afd47dd615b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/5e2a174052995663dd68e6b5ad838afd47dd615b", + "reference": "5e2a174052995663dd68e6b5ad838afd47dd615b", + "shasum": "" + }, + "require": { + "guzzlehttp/streams": "~3.0", + "php": ">=5.4.0", + "react/promise": "~2.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "ext-curl": "Guzzle will use specific adapters if cURL is present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Ring\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.", + "abandoned": true, + "time": "2018-07-31T13:22:33+00:00" + }, + { + "name": "guzzlehttp/streams", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/streams.git", + "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/streams/zipball/47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", + "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Stream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Provides a simple abstraction over streams of data", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "stream" + ], + "abandoned": true, + "time": "2014-10-12T19:18:40+00:00" + }, + { + "name": "platformsh/config-reader", + "version": "2.4.0", + "source": { + "type": "git", + "url": "https://github.com/platformsh/config-reader-php.git", + "reference": "5511abfdb673ccfcf0eac9eaf65204f73edd90fd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/platformsh/config-reader-php/zipball/5511abfdb673ccfcf0eac9eaf65204f73edd90fd", + "reference": "5511abfdb673ccfcf0eac9eaf65204f73edd90fd", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Platformsh\\ConfigReader\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Larry Garfield", + "email": "larry@platform.sh" + } + ], + "description": "Small helper to access Platform.sh environment variables", + "time": "2020-12-10T20:50:12+00:00" + }, + { + "name": "psr/log", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2021-05-03T11:20:27+00:00" + }, + { + "name": "react/promise", + "version": "v2.8.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/promise.git", + "reference": "f3cff96a19736714524ca0dd1d4130de73dbbbc4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/promise/zipball/f3cff96a19736714524ca0dd1d4130de73dbbbc4", + "reference": "f3cff96a19736714524ca0dd1d4130de73dbbbc4", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^7.0 || ^6.5 || ^5.7 || ^4.8.36" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com" + } + ], + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "keywords": [ + "promise", + "promises" + ], + "time": "2020-05-12T15:16:56+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">7.2" + }, + "platform-dev": [], + "plugin-api-version": "1.1.0" +} diff --git a/examples/elasticsearch-6.5/esearch.php b/examples/elasticsearch-6.5/esearch.php new file mode 100644 index 0000000..b3f869c --- /dev/null +++ b/examples/elasticsearch-6.5/esearch.php @@ -0,0 +1,98 @@ +credentials('elasticsearch'); + +try { + // The Elasticsearch library lets you connect to multiple hosts. + // On Platform.sh Standard there is only a single host so just + // register that. + $hosts = [ + [ + 'scheme' => $credentials['scheme'], + 'host' => $credentials['host'], + 'port' => $credentials['port'], + ] + ]; + + // Create an Elasticsearch client object. + $builder = ClientBuilder::create(); + $builder->setHosts($hosts); + $client = $builder->build(); + + $index = 'my_index'; + $type = 'People'; + + // Index a few document. + $params = [ + 'index' => $index, + 'type' => $type, + ]; + + $names = ['Ada Lovelace', 'Alonzo Church', 'Barbara Liskov']; + + foreach ($names as $name) { + $params['body']['name'] = $name; + $client->index($params); + } + + // Force just-added items to be indexed. + $client->indices()->refresh(array('index' => $index)); + + + // Search for documents. + $result = $client->search([ + 'index' => $index, + 'type' => $type, + 'body' => [ + 'query' => [ + 'match' => [ + 'name' => 'Barbara Liskov', + ], + ], + ], + ]); + + if (isset($result['hits']['hits'])) { + print << + + + + +TABLE; + foreach ($result['hits']['hits'] as $record) { + printf("\n", $record['_id'], $record['_source']['name']); + } + print "\n
IDName
%s%s
\n"; + } + + // Delete documents. + $params = [ + 'index' => $index, + 'type' => $type, + ]; + + $ids = array_map(function($row) { + return $row['_id']; + }, $result['hits']['hits']); + + foreach ($ids as $id) { + $params['id'] = $id; + $client->delete($params); + } + +} catch (Exception $e) { + print $e->getMessage(); +} diff --git a/examples/elasticsearch-6.5/index.php b/examples/elasticsearch-6.5/index.php new file mode 100644 index 0000000..f157f05 --- /dev/null +++ b/examples/elasticsearch-6.5/index.php @@ -0,0 +1 @@ +HELLO! From 7fc5bbdddae2a607a6fc4459aa856e7f0396859f Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Tue, 26 Oct 2021 16:08:13 -0700 Subject: [PATCH 2/6] #3: Add an additional ES service running a plugin. --- examples/elasticsearch-6.5/.platform.app.yaml | 1 + examples/elasticsearch-6.5/.platform/services.yaml | 5 +++++ examples/elasticsearch-6.5/README.md | 3 +++ 3 files changed, 9 insertions(+) diff --git a/examples/elasticsearch-6.5/.platform.app.yaml b/examples/elasticsearch-6.5/.platform.app.yaml index 08e711d..fadc456 100644 --- a/examples/elasticsearch-6.5/.platform.app.yaml +++ b/examples/elasticsearch-6.5/.platform.app.yaml @@ -9,3 +9,4 @@ web: passthru: "/index.php" relationships: elasticsearch: "searchelastic:elasticsearch" + elasticsearch-plugin: "searchelastic-plugin:elasticsearch" diff --git a/examples/elasticsearch-6.5/.platform/services.yaml b/examples/elasticsearch-6.5/.platform/services.yaml index 64548a1..5e356e1 100644 --- a/examples/elasticsearch-6.5/.platform/services.yaml +++ b/examples/elasticsearch-6.5/.platform/services.yaml @@ -1,2 +1,7 @@ searchelastic: type: elasticsearch:6.5 +searchelastic-plugin: + type: elasticsearch:6.5 + configuration: + plugins: + - mapper-size diff --git a/examples/elasticsearch-6.5/README.md b/examples/elasticsearch-6.5/README.md index 626e73d..5f45219 100644 --- a/examples/elasticsearch-6.5/README.md +++ b/examples/elasticsearch-6.5/README.md @@ -45,6 +45,9 @@ lando ssh -s searchelastic -c "curl -XGET 'http://localhost:9200'" | grep 6.5 # Should be able to connect to elasticsearch from the application containers lando ssh -s app -c "curl localhost/esearch.php" | grep "Barbara Liskov" + +# Should be running the correct elasticsearch versions (plugin service) +lando ssh -s searchelastic-plugin -c "curl -XGET 'http://localhost:9200'" | grep 6.5 ``` Destroy tests From 758855ac49aed162070a74da4e17cfa30afb83d6 Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Mon, 1 Nov 2021 14:50:40 -0700 Subject: [PATCH 3/6] #3: Try testing mapper-size plugin on ES. --- examples/elasticsearch-6.5/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/elasticsearch-6.5/README.md b/examples/elasticsearch-6.5/README.md index 5f45219..0a51f96 100644 --- a/examples/elasticsearch-6.5/README.md +++ b/examples/elasticsearch-6.5/README.md @@ -48,6 +48,16 @@ lando ssh -s app -c "curl localhost/esearch.php" | grep "Barbara Liskov" # Should be running the correct elasticsearch versions (plugin service) lando ssh -s searchelastic-plugin -c "curl -XGET 'http://localhost:9200'" | grep 6.5 + +# Should be able to enable the _size field for mapper-size plugin +lando ssh -s searchelastic-plugin -c "curl -X PUT 'localhost:9200/my_index?pretty' -H 'Content-Type:application/json' -d'{\"mappings\": {\"_doc\": {\"_size\": {\"enabled\": true}}}}'" + +# Should be able to add a doc to the ES index +lando ssh -s searchelastic-plugin -c "curl -X PUT 'localhost:9200/my-index/_doc/1?pretty' -H 'Content-Type: application/json' -d'{\"text\": \"This is a document\"}'" + +# Should see _size field when querying ES index. +lando ssh -s searchelastic-plugin -c "curl -X GET 'localhost:9200/my_index/_search?pretty' -H 'Content-Type: application/json' -d '{ \"query\": { \"range\": { \"_size\": { \"gt\": 10 } } }, \"aggs\": { \"sizes\": { \"terms\": { \"field\": \"_size\", \"size\": 10 } } }, \"sort\": [ { \"_size\": { \"order\": \"desc\" } } ], \"script_fields\": { \"size\": { \"script\": \"doc[\\u0027_size\\u0027]\" } }}'" | grep sizes + ``` Destroy tests From d74a7e68966802c5234b69d2cd3f79d26bec7301 Mon Sep 17 00:00:00 2001 From: John Ouellet Date: Tue, 2 Nov 2021 15:17:21 -0400 Subject: [PATCH 4/6] #3 add in ES 6.8 --- .github/workflows/pr-elasticsearch-tests.yml | 2 +- examples/elasticsearch-6.8/.editorconfig | 20 ++ examples/elasticsearch-6.8/.gitignore | 11 + examples/elasticsearch-6.8/.lando.yml | 10 + examples/elasticsearch-6.8/.platform.app.yaml | 12 + .../elasticsearch-6.8/.platform/routes.yaml | 8 + .../elasticsearch-6.8/.platform/services.yaml | 7 + examples/elasticsearch-6.8/README.md | 74 ++++ examples/elasticsearch-6.8/composer.json | 16 + examples/elasticsearch-6.8/composer.lock | 317 ++++++++++++++++++ examples/elasticsearch-6.8/esearch.php | 98 ++++++ examples/elasticsearch-6.8/index.php | 1 + 12 files changed, 575 insertions(+), 1 deletion(-) create mode 100644 examples/elasticsearch-6.8/.editorconfig create mode 100644 examples/elasticsearch-6.8/.gitignore create mode 100644 examples/elasticsearch-6.8/.lando.yml create mode 100644 examples/elasticsearch-6.8/.platform.app.yaml create mode 100644 examples/elasticsearch-6.8/.platform/routes.yaml create mode 100644 examples/elasticsearch-6.8/.platform/services.yaml create mode 100644 examples/elasticsearch-6.8/README.md create mode 100644 examples/elasticsearch-6.8/composer.json create mode 100644 examples/elasticsearch-6.8/composer.lock create mode 100644 examples/elasticsearch-6.8/esearch.php create mode 100644 examples/elasticsearch-6.8/index.php diff --git a/.github/workflows/pr-elasticsearch-tests.yml b/.github/workflows/pr-elasticsearch-tests.yml index 308d3f2..c1b2555 100644 --- a/.github/workflows/pr-elasticsearch-tests.yml +++ b/.github/workflows/pr-elasticsearch-tests.yml @@ -12,7 +12,7 @@ jobs: matrix: leia-tests: - examples/elasticsearch-6.5 - # - examples/elasticsearch-6.8 + - examples/elasticsearch-6.8 # - examples/elasticsearch-7.2 # - examples/elasticsearch-7.5 # - examples/elasticsearch-7.7 diff --git a/examples/elasticsearch-6.8/.editorconfig b/examples/elasticsearch-6.8/.editorconfig new file mode 100644 index 0000000..9371936 --- /dev/null +++ b/examples/elasticsearch-6.8/.editorconfig @@ -0,0 +1,20 @@ +# Drupal editor configuration normalization +# @see http://editorconfig.org/ + +# This is the top-most .editorconfig file; do not search in parent directories. +root = true + +# All files. +[*] +end_of_line = LF +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[composer.{json,lock}] +indent_size = 4 + +[.platform.app.yaml] +indent_size = 4 diff --git a/examples/elasticsearch-6.8/.gitignore b/examples/elasticsearch-6.8/.gitignore new file mode 100644 index 0000000..84200aa --- /dev/null +++ b/examples/elasticsearch-6.8/.gitignore @@ -0,0 +1,11 @@ +vendor +files +data +private +.platform/local + +*.sql +*.tar.gz +*.tar + +.DS_Store diff --git a/examples/elasticsearch-6.8/.lando.yml b/examples/elasticsearch-6.8/.lando.yml new file mode 100644 index 0000000..52a6cef --- /dev/null +++ b/examples/elasticsearch-6.8/.lando.yml @@ -0,0 +1,10 @@ +name: lando-platformsh-elasticsearch-6.8 +recipe: platformsh +config: + id: DISCONNECTED + + +# This is important because it lets lando know to test against the plugin in this repo +# DO NOT REMOVE THIS! +plugins: + "@lando/platformsh": ./../../ diff --git a/examples/elasticsearch-6.8/.platform.app.yaml b/examples/elasticsearch-6.8/.platform.app.yaml new file mode 100644 index 0000000..fadc456 --- /dev/null +++ b/examples/elasticsearch-6.8/.platform.app.yaml @@ -0,0 +1,12 @@ +name: app +type: "php:7.3" +build: + flavor: composer +web: + locations: + "/": + root: "." + passthru: "/index.php" +relationships: + elasticsearch: "searchelastic:elasticsearch" + elasticsearch-plugin: "searchelastic-plugin:elasticsearch" diff --git a/examples/elasticsearch-6.8/.platform/routes.yaml b/examples/elasticsearch-6.8/.platform/routes.yaml new file mode 100644 index 0000000..b588ae0 --- /dev/null +++ b/examples/elasticsearch-6.8/.platform/routes.yaml @@ -0,0 +1,8 @@ +# The routes of the project. +# +# Each route describes how an incoming URL is going +# to be processed by Platform.sh. + +"https://{default}/": + type: upstream + upstream: "app:http" diff --git a/examples/elasticsearch-6.8/.platform/services.yaml b/examples/elasticsearch-6.8/.platform/services.yaml new file mode 100644 index 0000000..e723064 --- /dev/null +++ b/examples/elasticsearch-6.8/.platform/services.yaml @@ -0,0 +1,7 @@ +searchelastic: + type: elasticsearch:6.8 +searchelastic-plugin: + type: elasticsearch:6.8 + configuration: + plugins: + - mapper-size diff --git a/examples/elasticsearch-6.8/README.md b/examples/elasticsearch-6.8/README.md new file mode 100644 index 0000000..55c711a --- /dev/null +++ b/examples/elasticsearch-6.8/README.md @@ -0,0 +1,74 @@ +Platform.sh elasticsearch 6.8 Example +================================= + +This example exists to test this plugin's implementation of Platform.sh's `elasticsearch:6.8` service. + +* [`elasticsearch:6.8`](https://docs.platform.sh/configuration/services/elasticsearch.html) + +Start up tests +-------------- + +Run the following commands to get up and running with this example. + +```bash +# Should poweroff +lando poweroff + +# Should start up successfully +lando start +``` + +Verification commands +--------------------- + +Run the following commands to validate things are rolling as they should. + +```bash +# Should have the expected platformsh containers and images +docker ps --filter label=com.docker.compose.project=landoplatformshelasticsearch68 | grep docker.registry.platform.sh/php-7.3 | grep landoplatformshelasticsearch68_app_1 +docker ps --filter label=com.docker.compose.project=landoplatformshelasticsearch68 | grep docker.registry.platform.sh/elasticsearch-6.8 | grep landoplatformshelasticsearch68_searchelastic_1 + +# Should be running all application containers as web +lando ssh -s app -c "id" | grep web + +# Should have the platform cli in all application containers +lando ssh -s app -c "platform -V" + +# Should be running the correct php version +lando ssh -s app -c "php --version" | grep 7.3. + +# Should be running all elasticsearch containers as elasticsearch +lando ssh -s searchelastic -c "id" | grep elasticsearch + +# Should be running the correct elasticsearch versions +lando ssh -s searchelastic -c "curl -XGET 'http://localhost:9200'" | grep 6.8 + +# Should be able to connect to elasticsearch from the application containers +lando ssh -s app -c "curl localhost/esearch.php" | grep "Barbara Liskov" + +# Should be running the correct elasticsearch versions (plugin service) +lando ssh -s searchelastic-plugin -c "curl -XGET 'http://localhost:9200'" | grep 6.8 + +# Should be able to enable the _size field for mapper-size plugin +lando ssh -s searchelastic-plugin -c "curl -X PUT 'localhost:9200/my_index?pretty' -H 'Content-Type:application/json' -d'{\"mappings\": {\"_doc\": {\"_size\": {\"enabled\": true}}}}'" + +# Should be able to add a doc to the ES index +lando ssh -s searchelastic-plugin -c "curl -X PUT 'localhost:9200/my-index/_doc/1?pretty' -H 'Content-Type: application/json' -d'{\"text\": \"This is a document\"}'" + +# Should see _size field when querying ES index. +lando ssh -s searchelastic-plugin -c "curl -X GET 'localhost:9200/my_index/_search?pretty' -H 'Content-Type: application/json' -d '{ \"query\": { \"range\": { \"_size\": { \"gt\": 10 } } }, \"aggs\": { \"sizes\": { \"terms\": { \"field\": \"_size\", \"size\": 10 } } }, \"sort\": [ { \"_size\": { \"order\": \"desc\" } } ], \"script_fields\": { \"size\": { \"script\": \"doc[\\u0027_size\\u0027]\" } }}'" | grep sizes + +``` + +Destroy tests +------------- + +Run the following commands to trash this app like nothing ever happened. + +```bash +# Should be able to destroy our app +lando destroy -y + +# Should poweroff +lando poweroff +``` diff --git a/examples/elasticsearch-6.8/composer.json b/examples/elasticsearch-6.8/composer.json new file mode 100644 index 0000000..2cd22ed --- /dev/null +++ b/examples/elasticsearch-6.8/composer.json @@ -0,0 +1,16 @@ +{ + "name": "lando/platformsh-elasticsearch-6.8", + "description": "A basic application to test Lando's implementation of platformsh's elasticsearch 6.8 service.", + "license": "MIT", + "type" : "project", + "require": { + "php": ">7.2", + "platformsh/config-reader": "~2.0", + "elasticsearch/elasticsearch": "~6.8.0" + }, + "autoload": { + "psr-4": { + "App\\": "src/" + } + } +} diff --git a/examples/elasticsearch-6.8/composer.lock b/examples/elasticsearch-6.8/composer.lock new file mode 100644 index 0000000..7bc1cde --- /dev/null +++ b/examples/elasticsearch-6.8/composer.lock @@ -0,0 +1,317 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "88a68a3a82ce70027ff10f76a8540532", + "packages": [ + { + "name": "elasticsearch/elasticsearch", + "version": "v6.8.2", + "source": { + "type": "git", + "url": "https://github.com/elastic/elasticsearch-php.git", + "reference": "619c78266999c6e431df9ca0f844e8f656ac145b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/elastic/elasticsearch-php/zipball/619c78266999c6e431df9ca0f844e8f656ac145b", + "reference": "619c78266999c6e431df9ca0f844e8f656ac145b", + "shasum": "" + }, + "require": { + "ext-json": ">=1.3.7", + "ezimuel/ringphp": "^1.1.2", + "php": "^7.3 || ^8.0", + "psr/log": "~1.0" + }, + "require-dev": { + "doctrine/inflector": "^1.3", + "mockery/mockery": "^1.2", + "phpstan/phpstan": "^0.12", + "phpunit/phpunit": "^9.3", + "squizlabs/php_codesniffer": "^3.4", + "symfony/finder": "~4.0", + "symfony/yaml": "~4.0", + "symplify/git-wrapper": ">=9.0 <9.3.27" + }, + "suggest": { + "ext-curl": "*", + "monolog/monolog": "Allows for client-level logging and tracing" + }, + "type": "library", + "autoload": { + "files": [ + "src/autoload.php" + ], + "psr-4": { + "Elasticsearch\\": "src/Elasticsearch/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Zachary Tong" + }, + { + "name": "Enrico Zimuel" + } + ], + "description": "PHP Client for Elasticsearch", + "keywords": [ + "client", + "elasticsearch", + "search" + ], + "time": "2021-07-14T14:41:55+00:00" + }, + { + "name": "ezimuel/guzzlestreams", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/ezimuel/guzzlestreams.git", + "reference": "abe3791d231167f14eb80d413420d1eab91163a8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ezimuel/guzzlestreams/zipball/abe3791d231167f14eb80d413420d1eab91163a8", + "reference": "abe3791d231167f14eb80d413420d1eab91163a8", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Stream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Fork of guzzle/streams (abandoned) to be used with elasticsearch-php", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "stream" + ], + "time": "2020-02-14T23:11:50+00:00" + }, + { + "name": "ezimuel/ringphp", + "version": "1.1.2", + "source": { + "type": "git", + "url": "https://github.com/ezimuel/ringphp.git", + "reference": "0b78f89d8e0bb9e380046c31adfa40347e9f663b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ezimuel/ringphp/zipball/0b78f89d8e0bb9e380046c31adfa40347e9f663b", + "reference": "0b78f89d8e0bb9e380046c31adfa40347e9f663b", + "shasum": "" + }, + "require": { + "ezimuel/guzzlestreams": "^3.0.1", + "php": ">=5.4.0", + "react/promise": "~2.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "ext-curl": "Guzzle will use specific adapters if cURL is present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Ring\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Fork of guzzle/RingPHP (abandoned) to be used with elasticsearch-php", + "time": "2020-02-14T23:51:21+00:00" + }, + { + "name": "platformsh/config-reader", + "version": "2.4.0", + "source": { + "type": "git", + "url": "https://github.com/platformsh/config-reader-php.git", + "reference": "5511abfdb673ccfcf0eac9eaf65204f73edd90fd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/platformsh/config-reader-php/zipball/5511abfdb673ccfcf0eac9eaf65204f73edd90fd", + "reference": "5511abfdb673ccfcf0eac9eaf65204f73edd90fd", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Platformsh\\ConfigReader\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Larry Garfield", + "email": "larry@platform.sh" + } + ], + "description": "Small helper to access Platform.sh environment variables", + "time": "2020-12-10T20:50:12+00:00" + }, + { + "name": "psr/log", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2021-05-03T11:20:27+00:00" + }, + { + "name": "react/promise", + "version": "v2.8.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/promise.git", + "reference": "f3cff96a19736714524ca0dd1d4130de73dbbbc4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/promise/zipball/f3cff96a19736714524ca0dd1d4130de73dbbbc4", + "reference": "f3cff96a19736714524ca0dd1d4130de73dbbbc4", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^7.0 || ^6.5 || ^5.7 || ^4.8.36" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com" + } + ], + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "keywords": [ + "promise", + "promises" + ], + "time": "2020-05-12T15:16:56+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">7.2" + }, + "platform-dev": [], + "plugin-api-version": "1.1.0" +} diff --git a/examples/elasticsearch-6.8/esearch.php b/examples/elasticsearch-6.8/esearch.php new file mode 100644 index 0000000..b3f869c --- /dev/null +++ b/examples/elasticsearch-6.8/esearch.php @@ -0,0 +1,98 @@ +credentials('elasticsearch'); + +try { + // The Elasticsearch library lets you connect to multiple hosts. + // On Platform.sh Standard there is only a single host so just + // register that. + $hosts = [ + [ + 'scheme' => $credentials['scheme'], + 'host' => $credentials['host'], + 'port' => $credentials['port'], + ] + ]; + + // Create an Elasticsearch client object. + $builder = ClientBuilder::create(); + $builder->setHosts($hosts); + $client = $builder->build(); + + $index = 'my_index'; + $type = 'People'; + + // Index a few document. + $params = [ + 'index' => $index, + 'type' => $type, + ]; + + $names = ['Ada Lovelace', 'Alonzo Church', 'Barbara Liskov']; + + foreach ($names as $name) { + $params['body']['name'] = $name; + $client->index($params); + } + + // Force just-added items to be indexed. + $client->indices()->refresh(array('index' => $index)); + + + // Search for documents. + $result = $client->search([ + 'index' => $index, + 'type' => $type, + 'body' => [ + 'query' => [ + 'match' => [ + 'name' => 'Barbara Liskov', + ], + ], + ], + ]); + + if (isset($result['hits']['hits'])) { + print << + + + + +TABLE; + foreach ($result['hits']['hits'] as $record) { + printf("\n", $record['_id'], $record['_source']['name']); + } + print "\n
IDName
%s%s
\n"; + } + + // Delete documents. + $params = [ + 'index' => $index, + 'type' => $type, + ]; + + $ids = array_map(function($row) { + return $row['_id']; + }, $result['hits']['hits']); + + foreach ($ids as $id) { + $params['id'] = $id; + $client->delete($params); + } + +} catch (Exception $e) { + print $e->getMessage(); +} diff --git a/examples/elasticsearch-6.8/index.php b/examples/elasticsearch-6.8/index.php new file mode 100644 index 0000000..f157f05 --- /dev/null +++ b/examples/elasticsearch-6.8/index.php @@ -0,0 +1 @@ +HELLO! From fbbb628850d9e33d58d98e15c7d4329ed1ceda10 Mon Sep 17 00:00:00 2001 From: John Ouellet Date: Tue, 2 Nov 2021 16:03:18 -0400 Subject: [PATCH 5/6] #3 add in start of ES7.2 --- examples/elasticsearch-7.2/.editorconfig | 20 ++ examples/elasticsearch-7.2/.gitignore | 11 + examples/elasticsearch-7.2/.lando.yml | 10 + examples/elasticsearch-7.2/.platform.app.yaml | 12 + .../elasticsearch-7.2/.platform/routes.yaml | 8 + .../elasticsearch-7.2/.platform/services.yaml | 7 + examples/elasticsearch-7.2/README.md | 74 ++++ examples/elasticsearch-7.2/composer.json | 16 + examples/elasticsearch-7.2/composer.lock | 316 ++++++++++++++++++ examples/elasticsearch-7.2/esearch.php | 98 ++++++ examples/elasticsearch-7.2/index.php | 1 + 11 files changed, 573 insertions(+) create mode 100644 examples/elasticsearch-7.2/.editorconfig create mode 100644 examples/elasticsearch-7.2/.gitignore create mode 100644 examples/elasticsearch-7.2/.lando.yml create mode 100644 examples/elasticsearch-7.2/.platform.app.yaml create mode 100644 examples/elasticsearch-7.2/.platform/routes.yaml create mode 100644 examples/elasticsearch-7.2/.platform/services.yaml create mode 100644 examples/elasticsearch-7.2/README.md create mode 100644 examples/elasticsearch-7.2/composer.json create mode 100644 examples/elasticsearch-7.2/composer.lock create mode 100644 examples/elasticsearch-7.2/esearch.php create mode 100644 examples/elasticsearch-7.2/index.php diff --git a/examples/elasticsearch-7.2/.editorconfig b/examples/elasticsearch-7.2/.editorconfig new file mode 100644 index 0000000..9371936 --- /dev/null +++ b/examples/elasticsearch-7.2/.editorconfig @@ -0,0 +1,20 @@ +# Drupal editor configuration normalization +# @see http://editorconfig.org/ + +# This is the top-most .editorconfig file; do not search in parent directories. +root = true + +# All files. +[*] +end_of_line = LF +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[composer.{json,lock}] +indent_size = 4 + +[.platform.app.yaml] +indent_size = 4 diff --git a/examples/elasticsearch-7.2/.gitignore b/examples/elasticsearch-7.2/.gitignore new file mode 100644 index 0000000..84200aa --- /dev/null +++ b/examples/elasticsearch-7.2/.gitignore @@ -0,0 +1,11 @@ +vendor +files +data +private +.platform/local + +*.sql +*.tar.gz +*.tar + +.DS_Store diff --git a/examples/elasticsearch-7.2/.lando.yml b/examples/elasticsearch-7.2/.lando.yml new file mode 100644 index 0000000..834be85 --- /dev/null +++ b/examples/elasticsearch-7.2/.lando.yml @@ -0,0 +1,10 @@ +name: lando-platformsh-elasticsearch-7.2 +recipe: platformsh +config: + id: DISCONNECTED + + +# This is important because it lets lando know to test against the plugin in this repo +# DO NOT REMOVE THIS! +plugins: + "@lando/platformsh": ./../../ diff --git a/examples/elasticsearch-7.2/.platform.app.yaml b/examples/elasticsearch-7.2/.platform.app.yaml new file mode 100644 index 0000000..fadc456 --- /dev/null +++ b/examples/elasticsearch-7.2/.platform.app.yaml @@ -0,0 +1,12 @@ +name: app +type: "php:7.3" +build: + flavor: composer +web: + locations: + "/": + root: "." + passthru: "/index.php" +relationships: + elasticsearch: "searchelastic:elasticsearch" + elasticsearch-plugin: "searchelastic-plugin:elasticsearch" diff --git a/examples/elasticsearch-7.2/.platform/routes.yaml b/examples/elasticsearch-7.2/.platform/routes.yaml new file mode 100644 index 0000000..b588ae0 --- /dev/null +++ b/examples/elasticsearch-7.2/.platform/routes.yaml @@ -0,0 +1,8 @@ +# The routes of the project. +# +# Each route describes how an incoming URL is going +# to be processed by Platform.sh. + +"https://{default}/": + type: upstream + upstream: "app:http" diff --git a/examples/elasticsearch-7.2/.platform/services.yaml b/examples/elasticsearch-7.2/.platform/services.yaml new file mode 100644 index 0000000..3d6c784 --- /dev/null +++ b/examples/elasticsearch-7.2/.platform/services.yaml @@ -0,0 +1,7 @@ +searchelastic: + type: elasticsearch:7.2 +searchelastic-plugin: + type: elasticsearch:7.2 + configuration: + plugins: + - mapper-size diff --git a/examples/elasticsearch-7.2/README.md b/examples/elasticsearch-7.2/README.md new file mode 100644 index 0000000..83b8649 --- /dev/null +++ b/examples/elasticsearch-7.2/README.md @@ -0,0 +1,74 @@ +Platform.sh elasticsearch 7.2 Example +================================= + +This example exists to test this plugin's implementation of Platform.sh's `elasticsearch:7.2` service. + +* [`elasticsearch:7.2`](https://docs.platform.sh/configuration/services/elasticsearch.html) + +Start up tests +-------------- + +Run the following commands to get up and running with this example. + +```bash +# Should poweroff +lando poweroff + +# Should start up successfully +lando start +``` + +Verification commands +--------------------- + +Run the following commands to validate things are rolling as they should. + +```bash +# Should have the expected platformsh containers and images +docker ps --filter label=com.docker.compose.project=landoplatformshelasticsearch72 | grep docker.registry.platform.sh/php-7.3 | grep landoplatformshelasticsearch72_app_1 +docker ps --filter label=com.docker.compose.project=landoplatformshelasticsearch72 | grep docker.registry.platform.sh/elasticsearch-7.2 | grep landoplatformshelasticsearch72_searchelastic_1 + +# Should be running all application containers as web +lando ssh -s app -c "id" | grep web + +# Should have the platform cli in all application containers +lando ssh -s app -c "platform -V" + +# Should be running the correct php version +lando ssh -s app -c "php --version" | grep 7.3. + +# Should be running all elasticsearch containers as elasticsearch +lando ssh -s searchelastic -c "id" | grep elasticsearch + +# Should be running the correct elasticsearch versions +lando ssh -s searchelastic -c "curl -XGET 'http://localhost:9200'" | grep 7.2 + +# Should be able to connect to elasticsearch from the application containers +lando ssh -s app -c "curl localhost/esearch.php" | grep "Barbara Liskov" + +# Should be running the correct elasticsearch versions (plugin service) +lando ssh -s searchelastic-plugin -c "curl -XGET 'http://localhost:9200'" | grep 7.2 + +# Should be able to enable the _size field for mapper-size plugin +lando ssh -s searchelastic-plugin -c "curl -X PUT 'localhost:9200/my_index?pretty' -H 'Content-Type:application/json' -d'{\"mappings\": {\"_doc\": {\"_size\": {\"enabled\": true}}}}'" + +# Should be able to add a doc to the ES index +lando ssh -s searchelastic-plugin -c "curl -X PUT 'localhost:9200/my-index/_doc/1?pretty' -H 'Content-Type: application/json' -d'{\"text\": \"This is a document\"}'" + +# Should see _size field when querying ES index. +lando ssh -s searchelastic-plugin -c "curl -X GET 'localhost:9200/my_index/_search?pretty' -H 'Content-Type: application/json' -d '{ \"query\": { \"range\": { \"_size\": { \"gt\": 10 } } }, \"aggs\": { \"sizes\": { \"terms\": { \"field\": \"_size\", \"size\": 10 } } }, \"sort\": [ { \"_size\": { \"order\": \"desc\" } } ], \"script_fields\": { \"size\": { \"script\": \"doc[\\u0027_size\\u0027]\" } }}'" | grep sizes + +``` + +Destroy tests +------------- + +Run the following commands to trash this app like nothing ever happened. + +```bash +# Should be able to destroy our app +lando destroy -y + +# Should poweroff +lando poweroff +``` diff --git a/examples/elasticsearch-7.2/composer.json b/examples/elasticsearch-7.2/composer.json new file mode 100644 index 0000000..ec04cdc --- /dev/null +++ b/examples/elasticsearch-7.2/composer.json @@ -0,0 +1,16 @@ +{ + "name": "lando/platformsh-elasticsearch-7.2", + "description": "A basic application to test Lando's implementation of platformsh's elasticsearch 7.2 service.", + "license": "MIT", + "type" : "project", + "require": { + "php": ">7.2", + "platformsh/config-reader": "~2.0", + "elasticsearch/elasticsearch": "~7.2.0" + }, + "autoload": { + "psr-4": { + "App\\": "src/" + } + } +} diff --git a/examples/elasticsearch-7.2/composer.lock b/examples/elasticsearch-7.2/composer.lock new file mode 100644 index 0000000..2fe6f37 --- /dev/null +++ b/examples/elasticsearch-7.2/composer.lock @@ -0,0 +1,316 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "cd7f2bdb926c4e9570006eb55fdfc970", + "packages": [ + { + "name": "elasticsearch/elasticsearch", + "version": "v7.2.2", + "source": { + "type": "git", + "url": "https://github.com/elastic/elasticsearch-php.git", + "reference": "eefeaa8decab4056d6457d179147cd885faf6653" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/elastic/elasticsearch-php/zipball/eefeaa8decab4056d6457d179147cd885faf6653", + "reference": "eefeaa8decab4056d6457d179147cd885faf6653", + "shasum": "" + }, + "require": { + "ext-json": ">=1.3.7", + "guzzlehttp/ringphp": "~1.0", + "php": "^7.1", + "psr/log": "~1.0" + }, + "require-dev": { + "cpliakas/git-wrapper": "~2.0", + "doctrine/inflector": "^1.3", + "mockery/mockery": "^1.2", + "phpstan/phpstan-shim": "^0.11", + "phpunit/phpunit": "^7.5", + "squizlabs/php_codesniffer": "^3.4", + "symfony/finder": "~4.0", + "symfony/yaml": "~4.0" + }, + "suggest": { + "ext-curl": "*", + "monolog/monolog": "Allows for client-level logging and tracing" + }, + "type": "library", + "autoload": { + "psr-4": { + "Elasticsearch\\": "src/Elasticsearch/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Zachary Tong" + }, + { + "name": "Enrico Zimuel" + } + ], + "description": "PHP Client for Elasticsearch", + "keywords": [ + "client", + "elasticsearch", + "search" + ], + "time": "2019-08-30T08:20:06+00:00" + }, + { + "name": "guzzlehttp/ringphp", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/RingPHP.git", + "reference": "5e2a174052995663dd68e6b5ad838afd47dd615b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/5e2a174052995663dd68e6b5ad838afd47dd615b", + "reference": "5e2a174052995663dd68e6b5ad838afd47dd615b", + "shasum": "" + }, + "require": { + "guzzlehttp/streams": "~3.0", + "php": ">=5.4.0", + "react/promise": "~2.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "ext-curl": "Guzzle will use specific adapters if cURL is present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Ring\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.", + "abandoned": true, + "time": "2018-07-31T13:22:33+00:00" + }, + { + "name": "guzzlehttp/streams", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/streams.git", + "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/streams/zipball/47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", + "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Stream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Provides a simple abstraction over streams of data", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "stream" + ], + "abandoned": true, + "time": "2014-10-12T19:18:40+00:00" + }, + { + "name": "platformsh/config-reader", + "version": "2.4.0", + "source": { + "type": "git", + "url": "https://github.com/platformsh/config-reader-php.git", + "reference": "5511abfdb673ccfcf0eac9eaf65204f73edd90fd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/platformsh/config-reader-php/zipball/5511abfdb673ccfcf0eac9eaf65204f73edd90fd", + "reference": "5511abfdb673ccfcf0eac9eaf65204f73edd90fd", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Platformsh\\ConfigReader\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Larry Garfield", + "email": "larry@platform.sh" + } + ], + "description": "Small helper to access Platform.sh environment variables", + "time": "2020-12-10T20:50:12+00:00" + }, + { + "name": "psr/log", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2021-05-03T11:20:27+00:00" + }, + { + "name": "react/promise", + "version": "v2.8.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/promise.git", + "reference": "f3cff96a19736714524ca0dd1d4130de73dbbbc4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/promise/zipball/f3cff96a19736714524ca0dd1d4130de73dbbbc4", + "reference": "f3cff96a19736714524ca0dd1d4130de73dbbbc4", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^7.0 || ^6.5 || ^5.7 || ^4.8.36" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com" + } + ], + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "keywords": [ + "promise", + "promises" + ], + "time": "2020-05-12T15:16:56+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">7.2" + }, + "platform-dev": [], + "plugin-api-version": "1.1.0" +} diff --git a/examples/elasticsearch-7.2/esearch.php b/examples/elasticsearch-7.2/esearch.php new file mode 100644 index 0000000..b3f869c --- /dev/null +++ b/examples/elasticsearch-7.2/esearch.php @@ -0,0 +1,98 @@ +credentials('elasticsearch'); + +try { + // The Elasticsearch library lets you connect to multiple hosts. + // On Platform.sh Standard there is only a single host so just + // register that. + $hosts = [ + [ + 'scheme' => $credentials['scheme'], + 'host' => $credentials['host'], + 'port' => $credentials['port'], + ] + ]; + + // Create an Elasticsearch client object. + $builder = ClientBuilder::create(); + $builder->setHosts($hosts); + $client = $builder->build(); + + $index = 'my_index'; + $type = 'People'; + + // Index a few document. + $params = [ + 'index' => $index, + 'type' => $type, + ]; + + $names = ['Ada Lovelace', 'Alonzo Church', 'Barbara Liskov']; + + foreach ($names as $name) { + $params['body']['name'] = $name; + $client->index($params); + } + + // Force just-added items to be indexed. + $client->indices()->refresh(array('index' => $index)); + + + // Search for documents. + $result = $client->search([ + 'index' => $index, + 'type' => $type, + 'body' => [ + 'query' => [ + 'match' => [ + 'name' => 'Barbara Liskov', + ], + ], + ], + ]); + + if (isset($result['hits']['hits'])) { + print << + + + + +TABLE; + foreach ($result['hits']['hits'] as $record) { + printf("\n", $record['_id'], $record['_source']['name']); + } + print "\n
IDName
%s%s
\n"; + } + + // Delete documents. + $params = [ + 'index' => $index, + 'type' => $type, + ]; + + $ids = array_map(function($row) { + return $row['_id']; + }, $result['hits']['hits']); + + foreach ($ids as $id) { + $params['id'] = $id; + $client->delete($params); + } + +} catch (Exception $e) { + print $e->getMessage(); +} diff --git a/examples/elasticsearch-7.2/index.php b/examples/elasticsearch-7.2/index.php new file mode 100644 index 0000000..f157f05 --- /dev/null +++ b/examples/elasticsearch-7.2/index.php @@ -0,0 +1 @@ +HELLO! From a0705c192935f8460d8b5bfdca226fb5efab64ea Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Thu, 18 Nov 2021 09:37:25 -0800 Subject: [PATCH 6/6] Enable 7.2 test. --- .github/workflows/pr-elasticsearch-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-elasticsearch-tests.yml b/.github/workflows/pr-elasticsearch-tests.yml index c1b2555..ac59f6d 100644 --- a/.github/workflows/pr-elasticsearch-tests.yml +++ b/.github/workflows/pr-elasticsearch-tests.yml @@ -13,7 +13,7 @@ jobs: leia-tests: - examples/elasticsearch-6.5 - examples/elasticsearch-6.8 - # - examples/elasticsearch-7.2 + - examples/elasticsearch-7.2 # - examples/elasticsearch-7.5 # - examples/elasticsearch-7.7 # - examples/elasticsearch-7.9