Skip to content

Commit 51c2c9f

Browse files
authored
In preparation for moving to Elastic's CI (#862)
* In preperation for moving to Elastic's CI Add dockerfile to build image for testing python client in a docker container add docker-compose to create environment for running tests against specific versions of ES Add Makefile to make it easy to execute tests and cleanup add wait-for-elasticsearch.sh script to wait for elasticsearch before executing the tests. * add pull and comment about pushing requring auth * spelling errors * adding CI directory for jenkins to pick up fixing typo too * fix test-matrix and create working run-tests * add comment about why skipping python 2.6 * adding dockerfiles to create base images for ci
1 parent 3176f46 commit 51c2c9f

File tree

8 files changed

+148
-0
lines changed

8 files changed

+148
-0
lines changed

.ci/Dockerfile-py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ARG PYTHON_VERSION=3
2+
FROM python:${PYTHON_VERSION}

.ci/Dockerfile-py26

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM ubuntu:18.04
2+
RUN apt-get update && apt-get install -y curl build-essential zlib1g-dev libssl1.0-dev
3+
RUN ln -s /lib/i386-linux-gnu/libz.so.1 /lib/libz.so
4+
RUN curl -s https://www.python.org/ftp/python/2.6.9/Python-2.6.9.tgz | tar -xzf -
5+
WORKDIR Python-2.6.9
6+
RUN LDFLAGS="-L/usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)" ./configure
7+
RUN make
8+
RUN make install
9+
RUN curl https://bootstrap.pypa.io/2.6/get-pip.py -o get-pip.py
10+
RUN python get-pip.py

.ci/run-tests

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Runs the client tests via Docker with the expectation that the required
5+
# environment variables have already been exported before running this script.
6+
#
7+
# The required environment variables include:
8+
#
9+
# - $ELASTICSEARCH_VERSION
10+
# - $PYTHON_VERSION
11+
#
12+
13+
# TODO: implement the docker-based testing
14+
cd ..
15+
make run_tests

.ci/test-matrix.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
ELASTICSEARCH_VERSION:
3+
- 6.4.2
4+
- 6.3.2
5+
- 6.1.4
6+
- 6.0.1
7+
8+
9+
10+
PYTHON_VERSION:
11+
- 3
12+
- 2.7
13+
- 2.6
14+
15+
exclude:
16+
# since a base image for python2.6 doens't exist i need to create one.
17+
- PYTHON_VERSION: 2.6
18+

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ARG PYTHON_VERSION=3
2+
FROM python:${PYTHON_VERSION}
3+
RUN apt-get update && apt-get install -y git curl
4+
RUN pip install ipdb python-dateutil GitPython
5+
6+
RUN git clone https://github.com/elastic/elasticsearch.git /code/elasticsearch
7+
8+
WORKDIR /code/elasticsearch-py
9+
COPY . .
10+
RUN pip install .[develop]
11+
RUN python setup.py develop
12+
CMD ["/code/wait-for-elasticsearch.sh", "http://elasticsearch:9200", "--", "python", "setup.py", "test"]

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
clean:
2+
docker-compose down --remove-orphans --volumes
3+
4+
build:
5+
PYTHON_VERSION=${PYTHON_VERSION} docker-compose build client
6+
7+
pull:
8+
ELASTIC_VERSION=${ELASTIC_VERSION} PYTHON_VERSION=${PYTHON_VERSION} docker-compose pull
9+
10+
push:
11+
# requires authentication.
12+
PYTHON_VERSION=${PYTHON_VERSION} docker-compose push client
13+
14+
run_tests:
15+
ELASTIC_VERSION=${ELASTIC_VERSION} PYTHON_VERSION=${PYTHON_VERSION} docker-compose run client python setup.py test
16+
17+
start_elasticsearch:
18+
ELASTIC_VERSION=${ELASTIC_VERSION} docker-compose up -d elasticsearch

docker-compose.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: '3.3'
2+
services:
3+
client:
4+
image: docker.elastic.co/clients/elasticsearch-py:${PYTHON_VERSION:-3}
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
args:
9+
PYTHON_VERSION: ${PYTHON_VERSION:-3}
10+
environment:
11+
- "TEST_ES_SERVER=http://elasticsearch:9200"
12+
volumes:
13+
- .:/code/elasticsearch-py
14+
- esvol:/tmp
15+
networks:
16+
- esnet
17+
depends_on:
18+
- elasticsearch
19+
command: ["true"] # dummy command to override the command in the Dockerfile and do nothing.
20+
elasticsearch:
21+
image: docker.elastic.co/elasticsearch/elasticsearch-oss:${ELASTIC_VERSION:-6.2.4}
22+
volumes:
23+
- esvol:/tmp
24+
networks:
25+
- esnet
26+
environment:
27+
- path.repo=/tmp
28+
- "repositories.url.allowed_urls=http://*"
29+
- node.attr.testattr=test
30+
- bootstrap.memory_lock=false
31+
- "discovery.zen.ping.unicast.hosts=elasticsearch"
32+
- "http.max_content_length=5mb"
33+
networks:
34+
esnet:
35+
volumes:
36+
esvol:

wait-for-elasticsearch.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
host="$1"
6+
shift
7+
cmd="$@"
8+
9+
10+
until $(curl --output /dev/null --silent --head --fail "$host"); do
11+
printf '.'
12+
sleep 1
13+
done
14+
15+
# First wait for ES to start...
16+
response=$(curl $host)
17+
18+
until [ "$response" = "200" ]; do
19+
response=$(curl --write-out %{http_code} --silent --output /dev/null "$host")
20+
>&2 echo "Elasticsearch is unavailable - sleeping"
21+
sleep 1
22+
done
23+
24+
25+
# next wait for ES status to turn to Green
26+
health="$(curl -fsSL "$host/_cat/health?h=status")"
27+
health="$(echo "$health" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" # trim whitespace (otherwise we'll have "green ")
28+
29+
until [ "$health" = 'green' ]; do
30+
health="$(curl -fsSL "$host/_cat/health?h=status")"
31+
health="$(echo "$health" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" # trim whitespace (otherwise we'll have "green ")
32+
>&2 echo "Elasticsearch is unavailable - sleeping"
33+
sleep 1
34+
done
35+
36+
>&2 echo "Elasticsearch is up"
37+
exec $cmd

0 commit comments

Comments
 (0)