This commit is contained in:
delvedor
2018-11-09 18:09:31 +01:00
8 changed files with 82 additions and 3 deletions

2
.ci/.dockerignore Normal file
View File

@ -0,0 +1,2 @@
node_modules
npm-debug.log

13
.ci/Dockerfile Normal file
View File

@ -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" ]

38
.ci/docker-compose.yml Normal file
View File

@ -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:

13
.ci/run-tests Executable file
View File

@ -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

10
.ci/test-matrix.yml Normal file
View File

@ -0,0 +1,10 @@
---
ELASTICSEARCH_VERSION:
- 6.4.0
NODE_JS_VERSION:
- 10
- 8
- 6
exclude: ~

View File

@ -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",

View File

@ -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

View File

@ -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
}