diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 433f3bc..3ec4c1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,23 +16,25 @@ jobs: - name: Checkout plugin uses: actions/checkout@v1 - - name: Build and pull docker files for opendistro + - name: Build and pull docker files for unit tests env: OPENDISTRO_VERSION: "1.13.2" LOGSTASH_VERSION: "7.13.2" run: | - ./scripts/opendistro/docker-setup.sh + ./scripts/unit-test/docker-setup.sh - # TODO: Refactor scripts into one unit test and multiple integration test - - name: Run unit tests for opendistro - env: - INTEGRATION: false + - name: Run unit tests run: | - ./scripts/opendistro/docker-run.sh + ./scripts/unit-test/docker-run.sh - - name: Run integration tests for opendistro + - name: Build and pull docker files for OpenDistro env: - INTEGRATION: true + OPENDISTRO_VERSION: "1.13.2" + LOGSTASH_VERSION: "7.13.2" + run: | + ./scripts/opendistro/docker-setup.sh + + - name: Run Integration tests against OpenDistro run: | ./scripts/opendistro/docker-run.sh @@ -43,14 +45,6 @@ jobs: run: | ./scripts/opensearch/docker-setup.sh - - name: Run unit tests for OpenSearch - env: - INTEGRATION: false - run: | - ./scripts/opensearch/docker-run.sh - - - name: Run integration tests for OpenSearch - env: - INTEGRATION: true + - name: Run Integration tests against OpenSearch run: | ./scripts/opensearch/docker-run.sh \ No newline at end of file diff --git a/scripts/Dockerfile b/scripts/Dockerfile index b301f0c..89051b3 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -5,8 +5,6 @@ COPY --chown=logstash:logstash *.gemspec VERSION* version* /usr/share/plugins/pl 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:/usr/share/logstash/jdk/bin" ENV LOGSTASH_SOURCE="1" -ARG INTEGRATION -ENV INTEGRATION=$INTEGRATION RUN gem install bundler -v '< 2' WORKDIR /usr/share/plugins/plugin RUN bundle install --with test ci diff --git a/scripts/logstash-run.sh b/scripts/logstash-run.sh index ffe2fbb..a20c932 100755 --- a/scripts/logstash-run.sh +++ b/scripts/logstash-run.sh @@ -15,11 +15,7 @@ wait_for_es() { echo $(curl -s $SERVICE_URL | python -c "import sys, json; print(json.load(sys.stdin)['version']['number'])") } -if [[ "$INTEGRATION" != "true" ]]; then - bundle exec rspec -fd spec/unit -t ~integration -else - echo "Waiting for cluster to respond..." - VERSION=$(wait_for_es) - echo "Integration test cluster $VERSION is Up!" - bundle exec rspec -fd --tag integration --tag update_tests:painless --tag version:$VERSION spec/integration -fi +echo "Waiting for cluster to respond..." +VERSION=$(wait_for_es) +echo "Integration test cluster $VERSION is Up!" +bundle exec rspec -fd --tag integration --tag update_tests:painless --tag version:$VERSION spec/integration diff --git a/scripts/opendistro/docker-compose.override.yml b/scripts/opendistro/docker-compose.override.yml index 0d22274..ae94b44 100644 --- a/scripts/opendistro/docker-compose.override.yml +++ b/scripts/opendistro/docker-compose.override.yml @@ -5,7 +5,7 @@ services: logstash: command: /usr/share/plugins/plugin/scripts/logstash-run.sh environment: - - INTEGRATION=${INTEGRATION:-false} + - INTEGRATION=true integration: @@ -13,7 +13,7 @@ services: context: ../../ dockerfile: scripts/opendistro/Dockerfile.opendistro args: - - INTEGRATION=${INTEGRATION:-false} + - INTEGRATION=true command: /usr/share/elasticsearch/elasticsearch-run.sh ports: - "9200:9200" diff --git a/scripts/opendistro/docker-run.sh b/scripts/opendistro/docker-run.sh index f4cdc95..69ae105 100755 --- a/scripts/opendistro/docker-run.sh +++ b/scripts/opendistro/docker-run.sh @@ -5,8 +5,4 @@ set -ex cd scripts/opendistro -if [ "$INTEGRATION" == "true" ]; then - docker-compose up --exit-code-from logstash -else - docker-compose up --exit-code-from logstash logstash -fi +docker-compose up --exit-code-from logstash diff --git a/scripts/opendistro/docker-setup.sh b/scripts/opendistro/docker-setup.sh index 411e1aa..60637f1 100755 --- a/scripts/opendistro/docker-setup.sh +++ b/scripts/opendistro/docker-setup.sh @@ -9,10 +9,5 @@ if [ -f Gemfile.lock ]; then fi cd scripts/opendistro; -if [ "$INTEGRATION" == "true" ]; then - docker-compose down - docker-compose build -else - docker-compose down - docker-compose build logstash -fi +docker-compose down +docker-compose build diff --git a/scripts/opensearch/docker-compose.override.yml b/scripts/opensearch/docker-compose.override.yml index b3f3304..6c40ed9 100755 --- a/scripts/opensearch/docker-compose.override.yml +++ b/scripts/opensearch/docker-compose.override.yml @@ -5,7 +5,7 @@ services: logstash: command: /usr/share/plugins/plugin/scripts/logstash-run.sh environment: - - INTEGRATION=${INTEGRATION:-false} + - INTEGRATION=true integration: @@ -13,7 +13,7 @@ services: context: ../../ dockerfile: scripts/opensearch/Dockerfile.opensearch args: - - INTEGRATION=${INTEGRATION:-false} + - INTEGRATION=true command: /usr/share/opensearch/opensearch-run.sh ports: - "9200:9200" diff --git a/scripts/opensearch/docker-run.sh b/scripts/opensearch/docker-run.sh index 8074fc3..ba39f1f 100755 --- a/scripts/opensearch/docker-run.sh +++ b/scripts/opensearch/docker-run.sh @@ -5,8 +5,4 @@ set -ex cd scripts/opensearch -if [ "$INTEGRATION" == "true" ]; then - docker-compose up --exit-code-from logstash -else - docker-compose up --exit-code-from logstash logstash -fi +docker-compose up --exit-code-from logstash diff --git a/scripts/opensearch/docker-setup.sh b/scripts/opensearch/docker-setup.sh index 2204feb..4312a15 100755 --- a/scripts/opensearch/docker-setup.sh +++ b/scripts/opensearch/docker-setup.sh @@ -9,10 +9,5 @@ if [ -f Gemfile.lock ]; then fi cd scripts/opensearch; -if [ "$INTEGRATION" == "true" ]; then - docker-compose down - docker-compose build -else - docker-compose down - docker-compose build logstash -fi +docker-compose down +docker-compose build diff --git a/scripts/unit-test/docker-compose.yml b/scripts/unit-test/docker-compose.yml new file mode 100644 index 0000000..d3ee0a0 --- /dev/null +++ b/scripts/unit-test/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3' + +services: + + logstash: + build: + context: ../../ + dockerfile: scripts/Dockerfile + command: /usr/share/plugins/plugin/scripts/unit-test/logstash-run.sh + env_file: ../docker.env + environment: + - SPEC_OPTS + - LOG_LEVEL # devutils (>= 2.0.4) reads the ENV and sets LS logging + tty: true \ No newline at end of file diff --git a/scripts/unit-test/docker-run.sh b/scripts/unit-test/docker-run.sh new file mode 100755 index 0000000..cfd9621 --- /dev/null +++ b/scripts/unit-test/docker-run.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# This is intended to be run inside the docker container as the command of the docker-compose. +set -ex + +cd scripts/unit-test; +docker-compose up --exit-code-from logstash logstash diff --git a/scripts/unit-test/docker-setup.sh b/scripts/unit-test/docker-setup.sh new file mode 100755 index 0000000..c8179d6 --- /dev/null +++ b/scripts/unit-test/docker-setup.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# This is intended to be run the plugin's root directory. `.scripts/opendistro/docker-setup.sh` +# Ensure you have Docker installed locally and set the OPENDISTRO_VERSION environment variable. +set -e + +if [ -f Gemfile.lock ]; then + rm Gemfile.lock +fi + +cd scripts/unit-test; +docker-compose down +docker-compose build logstash diff --git a/scripts/unit-test/logstash-run.sh b/scripts/unit-test/logstash-run.sh new file mode 100755 index 0000000..da1a667 --- /dev/null +++ b/scripts/unit-test/logstash-run.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -ex + +export PATH=$BUILD_DIR/gradle/bin:$PATH + +bundle exec rspec -fd spec/unit -t ~integration