Skip to content

Commit 86f4c49

Browse files
authored
Change testing to docker (#357)
1 parent fe3e437 commit 86f4c49

File tree

9 files changed

+111
-68
lines changed

9 files changed

+111
-68
lines changed

.travis.yml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
---
2-
sudo: false
3-
language: ruby
4-
cache: bundler
2+
sudo: required
3+
services: docker
4+
addons:
5+
apt:
6+
packages:
7+
- docker-ce
58
matrix:
69
include:
7-
- rvm: jruby-9.1.13.0
8-
env: LOGSTASH_BRANCH=master
9-
- rvm: jruby-9.1.13.0
10-
env: LOGSTASH_BRANCH=6.x
11-
- rvm: jruby-9.1.13.0
12-
env: LOGSTASH_BRANCH=6.5
13-
- rvm: jruby-1.7.27
14-
env: LOGSTASH_BRANCH=5.6
10+
- env: ELASTIC_STACK_VERSION=5.x
11+
- env: ELASTIC_STACK_VERSION=6.x
12+
- env: ELASTIC_STACK_VERSION=7.x
13+
- env: SNAPSHOT=true ELASTIC_STACK_VERSION=6.x
14+
- env: SNAPSHOT=true ELASTIC_STACK_VERSION=7.x
1515
fast_finish: true
16-
install: true
17-
script: ci/build.sh
18-
jdk: oraclejdk8
19-
before_install: gem install bundler -v '< 2'
16+
install: ci/unit/docker-setup.sh
17+
script: ci/unit/docker-run.sh

ci/build.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

ci/run.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

ci/setup.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

ci/unit/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ARG ELASTIC_STACK_VERSION
2+
FROM docker.elastic.co/logstash/logstash:$ELASTIC_STACK_VERSION
3+
USER root
4+
RUN yum -y install openssl
5+
USER logstash
6+
COPY --chown=logstash:logstash Gemfile /usr/share/plugins/plugin/Gemfile
7+
COPY --chown=logstash:logstash *.gemspec /usr/share/plugins/plugin/
8+
COPY --chown=logstash:logstash VERSION /usr/share/plugins/plugin/
9+
RUN cp /usr/share/logstash/logstash-core/versions-gem-copy.yml /usr/share/logstash/versions.yml
10+
ENV PATH="${PATH}:/usr/share/logstash/vendor/jruby/bin"
11+
ENV LOGSTASH_SOURCE=1
12+
RUN gem install bundler -v "~> 1"
13+
WORKDIR /usr/share/plugins/plugin
14+
RUN bundle install
15+
COPY --chown=logstash:logstash . /usr/share/plugins/plugin
16+
RUN bundle exec rake vendor
17+
RUN ./gradlew test

ci/unit/docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '3'
2+
3+
# run tests: cd ci/unit; docker-compose up --build --force-recreate
4+
# manual: cd ci/unit; docker-compose run logstash bash
5+
services:
6+
7+
logstash:
8+
build:
9+
context: ../../
10+
dockerfile: ci/unit/Dockerfile
11+
args:
12+
- ELASTIC_STACK_VERSION=$ELASTIC_STACK_VERSION
13+
command: /usr/share/plugins/plugin/ci/unit/run.sh
14+
environment:
15+
LS_JAVA_OPTS: "-Xmx256m -Xms256m"
16+
LOGSTASH_SOURCE: 1
17+
tty: true

ci/unit/docker-run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
# This is intended to be run inside the docker container as the command of the docker-compose.
4+
set -ex
5+
docker-compose -f ci/unit/docker-compose.yml up --exit-code-from logstash

ci/unit/docker-setup.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# This is intended to be run the plugin's root directory. `ci/unit/docker-test.sh`
4+
# Ensure you have Docker installed locally and set the ELASTIC_STACK_VERSION environment variable.
5+
set -e
6+
7+
VERSION_URL="https://raw.githubusercontent.com/elastic/logstash/master/ci/logstash_releases.json"
8+
9+
if [ "$ELASTIC_STACK_VERSION" ]; then
10+
echo "Fetching versions from $VERSION_URL"
11+
VERSIONS=$(curl -s $VERSION_URL)
12+
if [[ "$SNAPSHOT" = "true" ]]; then
13+
ELASTIC_STACK_RETRIEVED_VERSION=$(echo $VERSIONS | jq '.snapshots."'"$ELASTIC_STACK_VERSION"'"')
14+
echo $ELASTIC_STACK_RETRIEVED_VERSION
15+
else
16+
ELASTIC_STACK_RETRIEVED_VERSION=$(echo $VERSIONS | jq '.releases."'"$ELASTIC_STACK_VERSION"'"')
17+
fi
18+
if [[ "$ELASTIC_STACK_RETRIEVED_VERSION" != "null" ]]; then
19+
# remove starting and trailing double quotes
20+
ELASTIC_STACK_RETRIEVED_VERSION="${ELASTIC_STACK_RETRIEVED_VERSION%\"}"
21+
ELASTIC_STACK_RETRIEVED_VERSION="${ELASTIC_STACK_RETRIEVED_VERSION#\"}"
22+
echo "Translated $ELASTIC_STACK_VERSION to ${ELASTIC_STACK_RETRIEVED_VERSION}"
23+
export ELASTIC_STACK_VERSION=$ELASTIC_STACK_RETRIEVED_VERSION
24+
fi
25+
26+
echo "Testing against version: $ELASTIC_STACK_VERSION"
27+
28+
if [[ "$ELASTIC_STACK_VERSION" = *"-SNAPSHOT" ]]; then
29+
cd /tmp
30+
wget https://snapshots.elastic.co/docker/logstash-"$ELASTIC_STACK_VERSION".tar.gz
31+
tar xfvz logstash-"$ELASTIC_STACK_VERSION".tar.gz repositories
32+
echo "Loading docker image: "
33+
cat repositories
34+
docker load < logstash-"$ELASTIC_STACK_VERSION".tar.gz
35+
rm logstash-"$ELASTIC_STACK_VERSION".tar.gz
36+
cd -
37+
fi
38+
39+
if [ -f Gemfile.lock ]; then
40+
rm Gemfile.lock
41+
fi
42+
43+
docker-compose -f ci/unit/docker-compose.yml down
44+
docker-compose -f ci/unit/docker-compose.yml build
45+
#docker-compose -f ci/unit/docker-compose.yml up --exit-code-from logstash --force-recreate
46+
else
47+
echo "Please set the ELASTIC_STACK_VERSION environment variable"
48+
echo "For example: export ELASTIC_STACK_VERSION=6.2.4"
49+
exit 1
50+
fi
51+

ci/unit/run.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
# This is intended to be run inside the docker container as the command of the docker-compose.
4+
set -ex
5+
6+
bundle exec rspec spec
7+
bundle exec rake test:integration:setup
8+
bundle exec rspec spec --tag integration

0 commit comments

Comments
 (0)