Skip to content

Commit df32e53

Browse files
jsvdkares
andauthored
update to centralized travis configuration (logstash-plugins#930)
same work as done in the logstash-plugins/logstash-filter-elasticsearch#126 and logstash-plugins/logstash-input-elasticsearch#120. The only difference is that integration tests need to know the exact elasticsearch version being tested (but the input can be "7.x"). This PR modifies the .ci/logstash-run to fetch the version from elasticsearch itself. Co-authored-by: Karol Bucek <[email protected]>
1 parent 7ba6acc commit df32e53

11 files changed

+106
-119
lines changed

.ci/Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
ARG ELASTIC_STACK_VERSION
2+
# TODO: refactor this to be implicitly resolved by logstash-plugins/.ci/Dockerfile
3+
ARG DISTRIBUTION_SUFFIX
4+
FROM docker.elastic.co/logstash/logstash$DISTRIBUTION_SUFFIX:$ELASTIC_STACK_VERSION
5+
USER logstash
6+
COPY --chown=logstash:logstash Gemfile /usr/share/plugins/plugin/Gemfile
7+
COPY --chown=logstash:logstash *.gemspec VERSION* version* /usr/share/plugins/plugin/
8+
RUN cp /usr/share/logstash/logstash-core/versions-gem-copy.yml /usr/share/logstash/versions.yml
9+
ENV PATH="${PATH}:/usr/share/logstash/vendor/jruby/bin"
10+
ENV LOGSTASH_SOURCE="1"
11+
ENV ELASTIC_STACK_VERSION=$ELASTIC_STACK_VERSION
12+
# DISTRIBUTION="default" (by default) or "oss"
13+
ARG DISTRIBUTION
14+
ENV DISTRIBUTION=$DISTRIBUTION
15+
# INTEGRATION="true" while integration testing (false-y by default)
16+
ARG INTEGRATION
17+
ENV INTEGRATION=$INTEGRATION
18+
RUN gem install bundler -v '< 2'
19+
WORKDIR /usr/share/plugins/plugin
20+
RUN bundle install --with test ci
21+
COPY --chown=logstash:logstash . /usr/share/plugins/plugin
22+
RUN bundle exec rake vendor
23+
RUN .ci/setup.sh

.ci/Dockerfile.elasticsearch

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
ARG ELASTIC_STACK_VERSION
2+
ARG DISTRIBUTION_SUFFIX
3+
FROM docker.elastic.co/elasticsearch/elasticsearch$DISTRIBUTION_SUFFIX:$ELASTIC_STACK_VERSION
4+
5+
ARG plugin_path=/usr/share/plugins/plugin
6+
ARG es_path=/usr/share/elasticsearch
7+
ARG es_yml=$es_path/config/elasticsearch.yml
8+
ARG SECURE_INTEGRATION
9+
10+
RUN rm -f $es_path/config/scripts
11+
12+
COPY --chown=elasticsearch:elasticsearch spec/fixtures/scripts/groovy/* $es_path/config/scripts/
13+
COPY --chown=elasticsearch:elasticsearch spec/fixtures/test_certs/* $es_path/config/test_certs/
14+
COPY --chown=elasticsearch:elasticsearch .ci/elasticsearch-run.sh $es_path/
15+
16+
RUN if [ "$SECURE_INTEGRATION" = "true" ] ; then echo "xpack.security.http.ssl.enabled: $SECURE_INTEGRATION" >> $es_yml; fi
17+
RUN if [ "$SECURE_INTEGRATION" = "true" ] ; then echo "xpack.security.http.ssl.key: $es_path/config/test_certs/test.key" >> $es_yml; fi
18+
RUN if [ "$SECURE_INTEGRATION" = "true" ] ; then echo "xpack.security.http.ssl.certificate: $es_path/config/test_certs/test.crt" >> $es_yml; fi
19+
RUN if [ "$SECURE_INTEGRATION" = "true" ] ; then echo "xpack.security.http.ssl.certificate_authorities: [ '$es_path/config/test_certs/ca.crt' ]" >> $es_yml; fi
20+
RUN if [ "$SECURE_INTEGRATION" = "true" ] ; then $es_path/bin/elasticsearch-users useradd simpleuser -p abc123 -r superuser; fi
21+
RUN if [ "$SECURE_INTEGRATION" = "true" ] ; then $es_path/bin/elasticsearch-users useradd 'f@ncyuser' -p 'ab%12#' -r superuser; fi

.ci/docker-compose.override.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '3'
2+
3+
services:
4+
5+
logstash:
6+
command: /usr/share/plugins/plugin/.ci/logstash-run.sh
7+
build:
8+
args:
9+
- ELASTIC_STACK_VERSION=$ELASTIC_STACK_VERSION
10+
- DISTRIBUTION=${DISTRIBUTION:-default}
11+
- DISTRIBUTION_SUFFIX=${DISTRIBUTION_SUFFIX}
12+
environment:
13+
- DISTRIBUTION=${DISTRIBUTION:-default}
14+
- DISTRIBUTION_SUFFIX=${DISTRIBUTION_SUFFIX}
15+
- INTEGRATION=${INTEGRATION:-false}
16+
- SECURE_INTEGRATION=${SECURE_INTEGRATION:-false}
17+
18+
elasticsearch:
19+
build:
20+
context: ../
21+
dockerfile: .ci/Dockerfile.elasticsearch
22+
args:
23+
- ELASTIC_STACK_VERSION=$ELASTIC_STACK_VERSION
24+
- INTEGRATION=${INTEGRATION:-false}
25+
- SECURE_INTEGRATION=${SECURE_INTEGRATION:-false}
26+
- DISTRIBUTION_SUFFIX=${DISTRIBUTION_SUFFIX}
27+
command: /usr/share/elasticsearch/elasticsearch-run.sh
28+
tty: true
29+
ports:
30+
- "9200:9200"
31+
user: elasticsearch
32+

ci/docker-run.sh renamed to .ci/docker-run.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
# This is intended to be run inside the docker container as the command of the docker-compose.
44
set -ex
5+
6+
cd .ci
7+
58
if [ "$INTEGRATION" == "true" ]; then
6-
docker-compose -f ci/docker-compose.yml up --exit-code-from logstash
9+
docker-compose up --exit-code-from logstash
710
else
8-
docker-compose -f ci/docker-compose.yml up --exit-code-from logstash logstash
11+
docker-compose up --exit-code-from logstash logstash
912
fi

ci/docker-setup.sh renamed to .ci/docker-setup.sh

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# This is intended to be run the plugin's root directory. `ci/docker-test.sh`
3+
# This is intended to be run the plugin's root directory. `.ci/docker-setup.sh`
44
# Ensure you have Docker installed locally and set the ELASTIC_STACK_VERSION environment variable.
55
set -e
66

@@ -67,12 +67,14 @@ if [ "$ELASTIC_STACK_VERSION" ]; then
6767
rm Gemfile.lock
6868
fi
6969

70+
cd .ci
71+
7072
if [ "$INTEGRATION" == "true" ]; then
71-
docker-compose -f ci/docker-compose.yml down
72-
docker-compose -f ci/docker-compose.yml build
73+
docker-compose down
74+
docker-compose build
7375
else
74-
docker-compose -f ci/docker-compose.yml down
75-
docker-compose -f ci/docker-compose.yml build logstash
76+
docker-compose down
77+
docker-compose build logstash
7678
fi
7779
else
7880
echo "Please set the ELASTIC_STACK_VERSION environment variable"
File renamed without changes.

ci/logstash-run.sh renamed to .ci/logstash-run.sh

+13-12
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ set -ex
33

44
export PATH=$BUILD_DIR/gradle/bin:$PATH
55

6+
if [[ "$SECURE_INTEGRATION" == "true" ]]; then
7+
ES_URL="https://elasticsearch:9200 -k"
8+
else
9+
ES_URL="http://elasticsearch:9200"
10+
fi
11+
612
wait_for_es() {
7-
echo "Waiting for elasticsearch to respond..."
8-
es_url="http://elasticsearch:9200"
9-
if [[ "$SECURE_INTEGRATION" == "true" ]]; then
10-
es_url="https://elasticsearch:9200 -k"
11-
fi
1213
count=120
13-
while ! curl --silent $es_url && [[ $count -ne 0 ]]; do
14+
while ! curl -s $ES_URL >/dev/null && [[ $count -ne 0 ]]; do
1415
count=$(( $count - 1 ))
15-
[[ $count -eq 0 ]] && return 1
16+
[[ $count -eq 0 ]] && exit 1
1617
sleep 1
1718
done
18-
echo "Elasticsearch is Up !"
19-
20-
return 0
19+
echo $(curl -s $ES_URL | python -c "import sys, json; print(json.load(sys.stdin)['version']['number'])")
2120
}
2221

2322
if [[ "$INTEGRATION" != "true" ]]; then
@@ -35,6 +34,8 @@ else
3534
elif [[ "$DISTRIBUTION" == "default" ]]; then
3635
extra_tag_args="$extra_tag_args --tag ~distribution:oss --tag distribution:xpack"
3736
fi
38-
wait_for_es
39-
bundle exec rspec -fd $extra_tag_args --tag update_tests:painless --tag update_tests:groovy --tag es_version:$ELASTIC_STACK_VERSION spec/integration
37+
echo "Waiting for elasticsearch to respond..."
38+
ES_VERSION=$(wait_for_es)
39+
echo "Elasticsearch $ES_VERSION is Up!"
40+
bundle exec rspec -fd $extra_tag_args --tag update_tests:painless --tag update_tests:groovy --tag es_version:$ES_VERSION spec/integration
4041
fi

.travis.yml

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
---
2-
sudo: required
3-
services: docker
4-
addons:
5-
apt:
6-
packages:
7-
- docker-ce
1+
import:
2+
- logstash-plugins/.ci:travis/[email protected]
3+
84
env:
9-
- INTEGRATION=false ELASTIC_STACK_VERSION=5.x
10-
- INTEGRATION=false ELASTIC_STACK_VERSION=6.x
11-
- INTEGRATION=false ELASTIC_STACK_VERSION=7.x
5+
- DISTRIBUTION=default INTEGRATION=false ELASTIC_STACK_VERSION=6.x
6+
- DISTRIBUTION=default INTEGRATION=false ELASTIC_STACK_VERSION=7.x
127
- DISTRIBUTION=default INTEGRATION=true ELASTIC_STACK_VERSION=6.x
138
- DISTRIBUTION=default INTEGRATION=true ELASTIC_STACK_VERSION=7.x
149
- DISTRIBUTION=default INTEGRATION=true ELASTIC_STACK_VERSION=7.x SNAPSHOT=true
1510
- DISTRIBUTION=default INTEGRATION=true ELASTIC_STACK_VERSION=8.x SNAPSHOT=true
1611
- DISTRIBUTION=default SECURE_INTEGRATION=true INTEGRATION=true ELASTIC_STACK_VERSION=7.x
1712
- DISTRIBUTION=oss INTEGRATION=true ELASTIC_STACK_VERSION=7.x
18-
install: ci/docker-setup.sh
19-
script: ci/docker-run.sh

ci/Dockerfile.elasticsearch

-21
This file was deleted.

ci/Dockerfile.logstash

-25
This file was deleted.

ci/docker-compose.yml

-42
This file was deleted.

0 commit comments

Comments
 (0)