diff --git a/.travis.yml b/.travis.yml index 3b61247..f59107f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,16 @@ --- -sudo: false -language: ruby -cache: bundler +sudo: required +language: minimal matrix: include: - - rvm: jruby-9.1.13.0 - env: LOGSTASH_BRANCH=master - - rvm: jruby-9.1.13.0 - env: LOGSTASH_BRANCH=7.0 - - rvm: jruby-9.1.13.0 - env: LOGSTASH_BRANCH=6.7 - - rvm: jruby-9.1.13.0 - env: LOGSTASH_BRANCH=6.6 - - rvm: jruby-1.7.27 - env: LOGSTASH_BRANCH=5.6 + - env: ELASTIC_STACK_VERSION=5.x + - env: ELASTIC_STACK_VERSION=6.x + - env: ELASTIC_STACK_VERSION=7.x + - env: ELASTIC_STACK_VERSION=7.x SNAPSHOT=true + - env: ELASTIC_STACK_VERSION=8.x SNAPSHOT=true fast_finish: true -install: true -script: ci/build.sh -jdk: openjdk8 -before_install: gem install bundler -v '< 2' +#allow_failures: +# - env: ELASTIC_STACK_VERSION=8.x SNAPSHOT=true +# - env: ELASTIC_STACK_VERSION=7.x SNAPSHOT=true +install: ci/unit/docker-setup.sh +script: ci/unit/docker-run.sh diff --git a/ci/Dockerfile b/ci/Dockerfile new file mode 100644 index 0000000..2be9c64 --- /dev/null +++ b/ci/Dockerfile @@ -0,0 +1,18 @@ +ARG ELASTIC_STACK_VERSION +FROM docker.elastic.co/logstash/logstash:$ELASTIC_STACK_VERSION +COPY --chown=logstash:logstash Gemfile /usr/share/plugins/plugin/Gemfile +COPY --chown=logstash:logstash *.gemspec /usr/share/plugins/plugin/ +RUN cp /usr/share/logstash/logstash-core/versions-gem-copy.yml /usr/share/logstash/versions.yml +ENV PATH="${PATH}:/usr/share/logstash/vendor/jruby/bin" +ENV LOGSTASH_SOURCE="1" +ENV ELASTIC_STACK_VERSION=$ELASTIC_STACK_VERSION +# DISTRIBUTION="default" (by default) or "oss" +ARG DISTRIBUTION +ENV DISTRIBUTION=$DISTRIBUTION +# INTEGRATION="true" while integration testing (false-y by default) +ARG INTEGRATION +ENV INTEGRATION=$INTEGRATION +RUN gem install bundler -v '< 2' +WORKDIR /usr/share/plugins/plugin +RUN bundle install --with test ci +COPY --chown=logstash:logstash . /usr/share/plugins/plugin diff --git a/ci/build.sh b/ci/build.sh deleted file mode 100755 index 06caffd..0000000 --- a/ci/build.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# version: 1 -######################################################## -# -# AUTOMATICALLY GENERATED! DO NOT EDIT -# -######################################################## -set -e - -echo "Starting build process in: `pwd`" -source ./ci/setup.sh - -if [[ -f "ci/run.sh" ]]; then - echo "Running custom build script in: `pwd`/ci/run.sh" - source ./ci/run.sh -else - echo "Running default build scripts in: `pwd`/ci/build.sh" - bundle install - bundle exec rake vendor - bundle exec rspec spec -fi diff --git a/ci/docker-run.sh b/ci/docker-run.sh new file mode 100755 index 0000000..bb84184 --- /dev/null +++ b/ci/docker-run.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# This is intended to be run inside the docker container as the command of the docker-compose. +set -ex + +CURRENT_DIR=$(dirname "${BASH_SOURCE[0]}") + +docker-compose -f $CURRENT_DIR/docker-compose.yml up --exit-code-from logstash diff --git a/ci/docker-setup.sh b/ci/docker-setup.sh new file mode 100755 index 0000000..17081d2 --- /dev/null +++ b/ci/docker-setup.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +# This is intended to be run the plugin's root directory. `ci/unit/docker-test.sh` +# Ensure you have Docker installed locally and set the ELASTIC_STACK_VERSION environment variable. +set -e + +VERSION_URL="https://raw.githubusercontent.com/elastic/logstash/master/ci/logstash_releases.json" + +if [ -z "${ELASTIC_STACK_VERSION}" ]; then + echo "Please set the ELASTIC_STACK_VERSION environment variable" + echo "For example: export ELASTIC_STACK_VERSION=7.x" + exit 1 +fi + +echo "Fetching versions from $VERSION_URL" +VERSIONS=$(curl $VERSION_URL) + +if [[ "$SNAPSHOT" = "true" ]]; then + ELASTIC_STACK_RETRIEVED_VERSION=$(echo $VERSIONS | jq '.snapshots."'"$ELASTIC_STACK_VERSION"'"') + echo $ELASTIC_STACK_RETRIEVED_VERSION +else + ELASTIC_STACK_RETRIEVED_VERSION=$(echo $VERSIONS | jq '.releases."'"$ELASTIC_STACK_VERSION"'"') +fi + +if [[ "$ELASTIC_STACK_RETRIEVED_VERSION" != "null" ]]; then + # remove starting and trailing double quotes + ELASTIC_STACK_RETRIEVED_VERSION="${ELASTIC_STACK_RETRIEVED_VERSION%\"}" + ELASTIC_STACK_RETRIEVED_VERSION="${ELASTIC_STACK_RETRIEVED_VERSION#\"}" + echo "Translated $ELASTIC_STACK_VERSION to ${ELASTIC_STACK_RETRIEVED_VERSION}" + export ELASTIC_STACK_VERSION=$ELASTIC_STACK_RETRIEVED_VERSION +fi + +if [[ "$DISTRIBUTION" = "oss" ]]; then + DISTRIBUTION_SUFFIX="-oss" +else + DISTRIBUTION_SUFFIX="" +fi + +echo "Testing against version: $ELASTIC_STACK_VERSION (distribution: ${DISTRIBUTION:-"default"})" + +if [[ "$ELASTIC_STACK_VERSION" = *"-SNAPSHOT" ]]; then + cd /tmp + + jq=".build.projects.\"logstash\".packages.\"logstash$DISTRIBUTION_SUFFIX-$ELASTIC_STACK_VERSION-docker-image.tar.gz\".url" + result=$(curl --silent https://artifacts-api.elastic.co/v1/versions/$ELASTIC_STACK_VERSION/builds/latest | jq -r $jq) + echo $result + curl $result > logstash-docker-image.tar.gz + tar xfvz logstash-docker-image.tar.gz repositories + echo "Loading docker image: " + cat repositories + docker load < logstash-docker-image.tar.gz + rm logstash-docker-image.tar.gz + cd - +fi + +if [ -f Gemfile.lock ]; then + rm Gemfile.lock +fi + +CURRENT_DIR=$(dirname "${BASH_SOURCE[0]}") # e.g. "ci/unit" + +docker-compose -f "$CURRENT_DIR/docker-compose.yml" down +docker-compose -f "$CURRENT_DIR/docker-compose.yml" build logstash + +#docker-compose -f "$CURRENT_DIR/docker-compose.yml" up --exit-code-from logstash --force-recreate diff --git a/ci/setup.sh b/ci/setup.sh deleted file mode 100755 index 835fa43..0000000 --- a/ci/setup.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# version: 1 -######################################################## -# -# AUTOMATICALLY GENERATED! DO NOT EDIT -# -######################################################## -set -e -if [ "$LOGSTASH_BRANCH" ]; then - echo "Building plugin using Logstash source" - BASE_DIR=`pwd` - echo "Checking out branch: $LOGSTASH_BRANCH" - git clone -b $LOGSTASH_BRANCH https://github.com/elastic/logstash.git ../../logstash --depth 1 - printf "Checked out Logstash revision: %s\n" "$(git -C ../../logstash rev-parse HEAD)" - cd ../../logstash - echo "Building plugins with Logstash version:" - cat versions.yml - echo "---" - # We need to build the jars for that specific version - echo "Running gradle assemble in: `pwd`" - ./gradlew assemble - cd $BASE_DIR - export LOGSTASH_SOURCE=1 -else - echo "Building plugin using released gems on rubygems" -fi diff --git a/ci/unit/Dockerfile b/ci/unit/Dockerfile new file mode 120000 index 0000000..395595c --- /dev/null +++ b/ci/unit/Dockerfile @@ -0,0 +1 @@ +../Dockerfile \ No newline at end of file diff --git a/ci/unit/docker-compose.yml b/ci/unit/docker-compose.yml new file mode 100644 index 0000000..edf102e --- /dev/null +++ b/ci/unit/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3' + +# run tests: cd ci/unit; docker-compose up --build --force-recreate +# manual: cd ci/unit; docker-compose run logstash bash +services: + + logstash: + build: + context: ../../ + dockerfile: ci/unit/Dockerfile + args: + - ELASTIC_STACK_VERSION=$ELASTIC_STACK_VERSION + - DISTRIBUTION=${DISTRIBUTION:-default} + #- INTEGRATION=false + command: jruby -rbundler/setup -S rspec -fd + env_file: docker.env + environment: + - SPEC_OPTS + tty: true diff --git a/ci/unit/docker-run.sh b/ci/unit/docker-run.sh new file mode 120000 index 0000000..47dc7a0 --- /dev/null +++ b/ci/unit/docker-run.sh @@ -0,0 +1 @@ +../docker-run.sh \ No newline at end of file diff --git a/ci/unit/docker-setup.sh b/ci/unit/docker-setup.sh new file mode 120000 index 0000000..8775b96 --- /dev/null +++ b/ci/unit/docker-setup.sh @@ -0,0 +1 @@ +../docker-setup.sh \ No newline at end of file diff --git a/ci/unit/docker.env b/ci/unit/docker.env new file mode 100644 index 0000000..b855907 --- /dev/null +++ b/ci/unit/docker.env @@ -0,0 +1 @@ +LS_JAVA_OPTS="-Xms256m -Xmx256m -XX:MaxMetaspaceSize=256m" diff --git a/ci/unit/run.sh b/ci/unit/run.sh new file mode 100755 index 0000000..f08a3c8 --- /dev/null +++ b/ci/unit/run.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# This is intended to be run inside the docker container as the command of the docker-compose. +set -ex + +jruby -rbundler/setup -S rspec -fd