From 6f08079953ee42fe757b6ec33371218094d69e29 Mon Sep 17 00:00:00 2001 From: Tomas Della Vedova Date: Fri, 9 Nov 2018 17:57:23 +0100 Subject: [PATCH] WIP: clients-ci (#723) clients-ci --- .ci/.dockerignore | 2 ++ .ci/Dockerfile | 13 +++++++++++++ .ci/docker-compose.yml | 38 ++++++++++++++++++++++++++++++++++++++ .ci/run-tests | 13 +++++++++++++ .ci/test-matrix.yml | 10 ++++++++++ package.json | 3 ++- scripts/wait-cluster.sh | 4 +++- test/integration/index.js | 2 +- 8 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 .ci/.dockerignore create mode 100644 .ci/Dockerfile create mode 100644 .ci/docker-compose.yml create mode 100755 .ci/run-tests create mode 100644 .ci/test-matrix.yml diff --git a/.ci/.dockerignore b/.ci/.dockerignore new file mode 100644 index 000000000..93f136199 --- /dev/null +++ b/.ci/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log diff --git a/.ci/Dockerfile b/.ci/Dockerfile new file mode 100644 index 000000000..04ff3f55d --- /dev/null +++ b/.ci/Dockerfile @@ -0,0 +1,13 @@ +ARG NODE_JS_VERSION=8 +FROM node:${NODE_JS_VERSION} + +# Create app directory +WORKDIR /usr/src/app + +# Install app dependencies +COPY package*.json ./ +RUN npm install + +COPY . . + +CMD [ "npm", "run", "ci" ] diff --git a/.ci/docker-compose.yml b/.ci/docker-compose.yml new file mode 100644 index 000000000..541bb4898 --- /dev/null +++ b/.ci/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3.2' +services: + client: + image: docker.elastic.co/clients/elasticsearch-js:${NODE_JS_VERSION:-8} + build: + context: .. + dockerfile: .ci/Dockerfile + args: + NODE_JS_VERSION: ${NODE_JS_VERSION:-8} + environment: + - "TEST_ES_SERVER=http://elasticsearch:9200" + volumes: + - ..:/usr/src/app + # This will mount the node_modules directory + # to the host machine using the buildtime directory. + - /usr/src/app/node_modules + - esvol:/tmp + networks: + - esnet + depends_on: + - elasticsearch + elasticsearch: + image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTICSEARCH_VERSION:-6.4.0} + volumes: + - esvol:/tmp + networks: + - esnet + environment: + - path.repo=/tmp + - "repositories.url.allowed_urls=http://*" + - node.attr.testattr=test + - bootstrap.memory_lock=false + - "discovery.zen.ping.unicast.hosts=elasticsearch" + - "http.max_content_length=5mb" +networks: + esnet: +volumes: + esvol: diff --git a/.ci/run-tests b/.ci/run-tests new file mode 100755 index 000000000..e0deadb62 --- /dev/null +++ b/.ci/run-tests @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# +# Runs the client tests via Docker with the expectation that the required +# environment variables have already been exported before running this script. +# +# The required environment variables include: +# +# - $ELASTICSEARCH_VERSION +# - $NODE_JS_VERSION +# + +ELASTICSEARCH_VERSION=${ELASTICSEARCH_VERSION} NODE_JS_VERSION=${NODE_JS_VERSION} docker-compose -f .ci/docker-compose.yml run client diff --git a/.ci/test-matrix.yml b/.ci/test-matrix.yml new file mode 100644 index 000000000..9848e5c31 --- /dev/null +++ b/.ci/test-matrix.yml @@ -0,0 +1,10 @@ +--- +ELASTICSEARCH_VERSION: +- 6.4.0 + +NODE_JS_VERSION: +- 10 +- 8 +- 6 + +exclude: ~ diff --git a/package.json b/package.json index 5fda757e3..e29c8cf35 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "lint": "standard", "lint:fix": "standard --fix", "generate": "node scripts/run.js", - "elasticsearch": "./scripts/es-docker.sh" + "elasticsearch": "./scripts/es-docker.sh", + "ci": "./scripts/wait-cluster.sh && npm test && npm run test:integration" }, "author": { "name": "Tomas Della Vedova", diff --git a/scripts/wait-cluster.sh b/scripts/wait-cluster.sh index f94c333ed..4cacaa4b6 100755 --- a/scripts/wait-cluster.sh +++ b/scripts/wait-cluster.sh @@ -1,8 +1,10 @@ #!/bin/bash +TEST_ES_SERVER=${TEST_ES_SERVER:-"http://localhost:9200"} + attempt_counter=0 max_attempts=5 -url='http://localhost:9200/_cluster/health?wait_for_status=green&timeout=50s' +url="${TEST_ES_SERVER}/_cluster/health?wait_for_status=green&timeout=50s" echo "Waiting for Elasticsearch..." while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' --max-time 55 "$url")" != "200" ]]; do diff --git a/test/integration/index.js b/test/integration/index.js index b20adb936..afc72421f 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -238,7 +238,7 @@ if (require.main === module) { boolean: ['bailout'], default: { // node: 'http://elastic:passw0rd@localhost:9200', - node: 'http://localhost:9200', + node: process.env.TEST_ES_SERVER || 'http://localhost:9200', version: '6.4', bailout: false }