Skip to content

Commit

Permalink
Enable Stack Features (X-Pack) and trial by default (deviantony#387)
Browse files Browse the repository at this point in the history
Co-authored-by: Willian Soares <[email protected]>
  • Loading branch information
antoineco and Willian Soares committed May 6, 2019
1 parent 270933f commit e8e238f
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 116 deletions.
44 changes: 24 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ services: docker
env:
- DOCKER_COMPOSE_VERSION=1.14.0

before_install:
- sudo apt-get update
- sudo apt-get install -y expect jq

install:
# Install Docker Compose
- curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o "$HOME/bin/docker-compose"
Expand All @@ -16,38 +20,38 @@ before_script:

# Pull buildpack image (curl 7.52.0+)
- docker pull buildpack-deps:artful-curl
- shopt -s expand_aliases
- alias curl='docker run --rm --net=host buildpack-deps:artful-curl curl'

# Use built-in users
- sed -i 's/\(elasticsearch.username:\) elastic/\1 kibana/g' kibana/config/kibana.yml
- sed -i 's/\(xpack.monitoring.elasticsearch.username:\) elastic/\1 logstash_system/g' logstash/config/logstash.yml

script:
# Compose
- docker-compose up -d elasticsearch
- sleep 20
- .travis/elasticsearch-setup-passwords.exp
- docker-compose up -d
- sleep 60
- curl -s --retry 10 --retry-delay 5 --retry-connrefused -D- 'http:https://localhost:9200/'
- curl -s --retry 10 --retry-delay 5 --retry-connrefused -D- 'http:https://localhost:5601/api/status'
- curl -s --retry 10 --retry-delay 5 --retry-connrefused -D- 'http:https://localhost:9600/_node/pipelines/main?pretty'
- echo 'dockerelk' | nc localhost 5000
- sleep 2
- curl -s -XPOST 'http:https://localhost:9200/_refresh'
- curl -s 'http:https://localhost:9200/_count?q=message:dockerelk' | egrep '^{"count":1,'
- curl -s 'http:https://localhost:9200/_search?q=message:dockerelk&pretty'
- sleep 90
- .travis/run-tests.sh
- docker-compose ps
- docker-compose logs
- docker-compose logs elasticsearch
- docker-compose logs kibana
- docker-compose logs logstash
- docker-compose down -v

# Swarm
- docker swarm init
- docker stack deploy -c ./docker-stack.yml elk
- docker service scale elk_kibana=0 --detach=false
- docker service scale elk_logstash=0 --detach=false
- sleep 60
- curl -s --retry 10 --retry-delay 5 --retry-connrefused -D- 'http:https://localhost:9200/'
- curl -s --retry 10 --retry-delay 5 --retry-connrefused -D- 'http:https://localhost:5601/api/status'
- curl -s --retry 10 --retry-delay 5 --retry-connrefused -D- 'http:https://localhost:9600/_node/pipelines/main?pretty'
- echo 'dockerelk' | nc localhost 5000
- sleep 2
- curl -s -XPOST 'http:https://localhost:9200/_refresh'
- curl -s 'http:https://localhost:9200/_count?q=message:dockerelk' | egrep '^{"count":1,'
- curl -s 'http:https://localhost:9200/_search?q=message:dockerelk&pretty'
- .travis/elasticsearch-setup-passwords.exp swarm
- docker service scale elk_kibana=1 --detach=false
- docker service scale elk_logstash=1 --detach=false
- sleep 90
- .travis/run-tests.sh
- docker stack services elk
- docker service logs elk_elasticsearch
- docker service logs elk_kibana
- docker service logs elk_logstash
- docker stack rm elk
25 changes: 25 additions & 0 deletions .travis/elasticsearch-setup-passwords.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/expect -f

# List of expected users with dummy password
set user "(elastic|apm_system|kibana|logstash_system|beats_system|remote_monitoring_user)"
set password "changeme"

# Find elasticsearch container id
set MODE [lindex $argv 0]
if { [string match "swarm" $MODE] } {
set cid [exec docker ps -q -f label=com.docker.swarm.service.name=elk_elasticsearch]
} else {
set cid [exec docker ps -q -f label=com.docker.compose.service=elasticsearch]
}

set cmd "docker exec -it $cid bin/elasticsearch-setup-passwords interactive -s -b"

spawn {*}$cmd

expect {
-re "(E|Ree)nter password for \\\[$user\\\]: " {
send "$password\r"
exp_continue
}
eof
}
63 changes: 63 additions & 0 deletions .travis/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

set -eu
set -o pipefail

shopt -s expand_aliases
alias curl="docker run --rm --net=host buildpack-deps:artful-curl curl -s -w '\n'"

function log {
echo -e "\n[+] $1\n"
}

log 'Waiting for Elasticsearch readiness'
curl -D- 'http:https://localhost:9200/' \
--retry 10 \
--retry-delay 5 \
--retry-connrefused \
-u elastic:changeme

log 'Waiting for Kibana readiness'
curl -D- 'http:https://localhost:5601/api/status' \
--retry 10 \
--retry-delay 5 \
--retry-connrefused \
-u kibana:changeme

log 'Waiting for Logstash readiness'
curl -D- 'http:https://localhost:9600/_node/pipelines/main?pretty' \
--retry 10 \
--retry-delay 5 \
--retry-connrefused

log 'Creating Logstash index pattern in Kibana'
source .env
curl -X POST -D- 'http:https://localhost:5601/api/saved_objects/index-pattern' \
-H 'Content-Type: application/json' \
-H "kbn-version: ${ELK_VERSION}" \
-u kibana:changeme \
-d '{"attributes":{"title":"logstash-*","timeFieldName":"@timestamp"}}'

log 'Searching index pattern via Kibana API'
response="$(curl 'http:https://localhost:5601/api/saved_objects/_find?type=index-pattern' -u elastic:changeme)"
echo $response
count="$(jq -rn --argjson data "${response}" '$data.total')"
if [[ $count -ne 1 ]]; then
echo "Expected 1 index pattern, got ${count}"
exit 1
fi

log 'Sending message to Logstash TCP input'
echo 'dockerelk' | nc localhost 5000

sleep 1
curl -X POST 'http:https://localhost:9200/_refresh' -u elastic:changeme

log 'Searching message in Elasticsearch'
response="$(curl 'http:https://localhost:9200/_count?q=message:dockerelk&pretty' -u elastic:changeme)"
echo $response
count="$(jq -rn --argjson data "${response}" '$data.count')"
if [[ $count -ne 1 ]]; then
echo "Expected 1 document, got ${count}"
exit 1
fi
Loading

0 comments on commit e8e238f

Please sign in to comment.