Skip to content

Commit 0eb5fb0

Browse files
committed
CI: redo Travis (unit) testing using Docker images
1 parent 4d63827 commit 0eb5fb0

File tree

12 files changed

+132
-64
lines changed

12 files changed

+132
-64
lines changed

.travis.yml

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
---
2-
sudo: false
3-
language: ruby
4-
cache: bundler
2+
sudo: required
3+
language: minimal
54
matrix:
65
include:
7-
- rvm: jruby-9.1.13.0
8-
env: LOGSTASH_BRANCH=master
9-
- rvm: jruby-9.1.13.0
10-
env: LOGSTASH_BRANCH=7.0
11-
- rvm: jruby-9.1.13.0
12-
env: LOGSTASH_BRANCH=6.7
13-
- rvm: jruby-9.1.13.0
14-
env: LOGSTASH_BRANCH=6.6
15-
- rvm: jruby-1.7.27
16-
env: LOGSTASH_BRANCH=5.6
6+
- env: ELASTIC_STACK_VERSION=5.x
7+
- env: ELASTIC_STACK_VERSION=6.x
8+
- env: ELASTIC_STACK_VERSION=7.x
9+
- env: ELASTIC_STACK_VERSION=7.x SNAPSHOT=true
10+
- env: ELASTIC_STACK_VERSION=8.x SNAPSHOT=true
1711
fast_finish: true
18-
install: true
19-
script: ci/build.sh
20-
jdk: openjdk8
21-
before_install: gem install bundler -v '< 2'
12+
#allow_failures:
13+
# - env: ELASTIC_STACK_VERSION=8.x SNAPSHOT=true
14+
# - env: ELASTIC_STACK_VERSION=7.x SNAPSHOT=true
15+
install: ci/unit/docker-setup.sh
16+
script: ci/unit/docker-run.sh

ci/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ARG ELASTIC_STACK_VERSION
2+
FROM docker.elastic.co/logstash/logstash:$ELASTIC_STACK_VERSION
3+
COPY --chown=logstash:logstash Gemfile /usr/share/plugins/plugin/Gemfile
4+
COPY --chown=logstash:logstash *.gemspec /usr/share/plugins/plugin/
5+
RUN cp /usr/share/logstash/logstash-core/versions-gem-copy.yml /usr/share/logstash/versions.yml
6+
ENV PATH="${PATH}:/usr/share/logstash/vendor/jruby/bin"
7+
ENV LOGSTASH_SOURCE="1"
8+
ENV ELASTIC_STACK_VERSION=$ELASTIC_STACK_VERSION
9+
# DISTRIBUTION="default" (by default) or "oss"
10+
ARG DISTRIBUTION
11+
ENV DISTRIBUTION=$DISTRIBUTION
12+
# INTEGRATION="true" while integration testing (false-y by default)
13+
ARG INTEGRATION
14+
ENV INTEGRATION=$INTEGRATION
15+
RUN gem install bundler -v '< 2'
16+
WORKDIR /usr/share/plugins/plugin
17+
RUN bundle install --with test ci
18+
COPY --chown=logstash:logstash . /usr/share/plugins/plugin

ci/build.sh

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

ci/docker-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+
CURRENT_DIR=$(dirname "${BASH_SOURCE[0]}")
7+
8+
docker-compose -f $CURRENT_DIR/docker-compose.yml up --exit-code-from logstash

ci/docker-setup.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 [ -z "${ELASTIC_STACK_VERSION}" ]; then
10+
echo "Please set the ELASTIC_STACK_VERSION environment variable"
11+
echo "For example: export ELASTIC_STACK_VERSION=7.x"
12+
exit 1
13+
fi
14+
15+
echo "Fetching versions from $VERSION_URL"
16+
VERSIONS=$(curl $VERSION_URL)
17+
18+
if [[ "$SNAPSHOT" = "true" ]]; then
19+
ELASTIC_STACK_RETRIEVED_VERSION=$(echo $VERSIONS | jq '.snapshots."'"$ELASTIC_STACK_VERSION"'"')
20+
echo $ELASTIC_STACK_RETRIEVED_VERSION
21+
else
22+
ELASTIC_STACK_RETRIEVED_VERSION=$(echo $VERSIONS | jq '.releases."'"$ELASTIC_STACK_VERSION"'"')
23+
fi
24+
25+
if [[ "$ELASTIC_STACK_RETRIEVED_VERSION" != "null" ]]; then
26+
# remove starting and trailing double quotes
27+
ELASTIC_STACK_RETRIEVED_VERSION="${ELASTIC_STACK_RETRIEVED_VERSION%\"}"
28+
ELASTIC_STACK_RETRIEVED_VERSION="${ELASTIC_STACK_RETRIEVED_VERSION#\"}"
29+
echo "Translated $ELASTIC_STACK_VERSION to ${ELASTIC_STACK_RETRIEVED_VERSION}"
30+
export ELASTIC_STACK_VERSION=$ELASTIC_STACK_RETRIEVED_VERSION
31+
fi
32+
33+
if [[ "$DISTRIBUTION" = "oss" ]]; then
34+
DISTRIBUTION_SUFFIX="-oss"
35+
else
36+
DISTRIBUTION_SUFFIX=""
37+
fi
38+
39+
echo "Testing against version: $ELASTIC_STACK_VERSION (distribution: ${DISTRIBUTION:-"default"})"
40+
41+
if [[ "$ELASTIC_STACK_VERSION" = *"-SNAPSHOT" ]]; then
42+
cd /tmp
43+
44+
jq=".build.projects.\"logstash\".packages.\"logstash$DISTRIBUTION_SUFFIX-$ELASTIC_STACK_VERSION-docker-image.tar.gz\".url"
45+
result=$(curl --silent https://artifacts-api.elastic.co/v1/versions/$ELASTIC_STACK_VERSION/builds/latest | jq -r $jq)
46+
echo $result
47+
curl $result > logstash-docker-image.tar.gz
48+
tar xfvz logstash-docker-image.tar.gz repositories
49+
echo "Loading docker image: "
50+
cat repositories
51+
docker load < logstash-docker-image.tar.gz
52+
rm logstash-docker-image.tar.gz
53+
cd -
54+
fi
55+
56+
if [ -f Gemfile.lock ]; then
57+
rm Gemfile.lock
58+
fi
59+
60+
CURRENT_DIR=$(dirname "${BASH_SOURCE[0]}") # e.g. "ci/unit"
61+
62+
docker-compose -f "$CURRENT_DIR/docker-compose.yml" down
63+
docker-compose -f "$CURRENT_DIR/docker-compose.yml" build logstash
64+
65+
#docker-compose -f "$CURRENT_DIR/docker-compose.yml" up --exit-code-from logstash --force-recreate

ci/setup.sh

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

ci/unit/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Dockerfile

ci/unit/docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
- DISTRIBUTION=${DISTRIBUTION:-default}
14+
#- INTEGRATION=false
15+
command: jruby -rbundler/setup -S rspec -fd
16+
env_file: docker.env
17+
environment:
18+
- SPEC_OPTS
19+
tty: true

ci/unit/docker-run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../docker-run.sh

ci/unit/docker-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../docker-setup.sh

ci/unit/docker.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LS_JAVA_OPTS="-Xms256m -Xmx256m -XX:MaxMetaspaceSize=256m"

ci/unit/run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
jruby -rbundler/setup -S rspec -fd

0 commit comments

Comments
 (0)