Skip to content

Commit

Permalink
Fix docker-compose setup and use Hostname env var on test config
Browse files Browse the repository at this point in the history
  • Loading branch information
crespocarlos committed Oct 13, 2022
1 parent 0aca5a7 commit cf14f66
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 48 deletions.
4 changes: 2 additions & 2 deletions packages/kibana/_dev/deploy/docker/config/kibana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ elasticsearch.ssl.verificationMode: "none"
xpack.security.audit.enabled: true
xpack.security.audit.appender:
type: rolling-file
fileName: ./logs/audit.log
fileName: /var/log/audit.log
policy:
type: time-interval
interval: 24h
Expand All @@ -25,6 +25,6 @@ logging:
appenders:
file:
type: file
fileName: ./logs/kibana.log
fileName: /var/log/kibana.log
layout:
type: json
44 changes: 23 additions & 21 deletions packages/kibana/_dev/deploy/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,49 @@ services:
image: "docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION:-8.5.0-SNAPSHOT}"
environment:
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
- "ELASTIC_PASSWORD:changeme"
- "ELASTIC_PASSWORD=changeme"
ports:
- "127.0.0.1:9201:9200"
volumes:
- "./config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml"
healthcheck:
test: curl -sfo /dev/null -u elastic:changeme localhost:9200 || exit 1
test: curl -sfo /dev/null -u elastic:changeme http://localhost:9200 || exit 1
retries: 300
interval: 1s
setup:
image: "alpine/curl:latest"
user: root
environment:
- "ES_SERVICE_HOST=http://elasticsearch:9200"
- "ELASTIC_PASSWORD:changeme"
- "KIBANA_PASSWORD:changeme"
command: ["/bin/sh", "./setup.sh"]
- "ELASTIC_PASSWORD=changeme"
- "KIBANA_PASSWORD=changeme"
command: /bin/sh ./setup.sh
volumes:
- ./scripts/setup.sh:/setup.sh
- "./scripts/setup.sh:/setup.sh"
kibana:
image: "docker.elastic.co/kibana/kibana:${ELASTIC_VERSION:-8.5.0-SNAPSHOT}"
depends_on:
elasticsearch:
condition: service_healthy
volumes:
- ./config/kibana.yml:/usr/share/kibana/config/kibana.yml
- ${SERVICE_LOGS_DIR}:/usr/share/kibana/logs
- "./config/kibana.yml:/usr/share/kibana/config/kibana.yml"
- "${SERVICE_LOGS_DIR}:/var/log"
ports:
- "127.0.0.1:5602:5601"
healthcheck:
test: curl -sfo /dev/null localhost:5601 || exit 1
test: curl -sfo /dev/null http://localhost:5601 || exit 1
retries: 600
interval: 1s
log_generation:
image: "alpine/curl:latest"
depends_on:
kibana:
condition: service_healthy
environment:
- "KIBANA_SERVICE_HOST=http://kibana:5601"
- "ELASTIC_PASSWORD:changeme"
- "KIBANA_PASSWORD:changeme"
command: ["/bin/sh", "./generate-audit-logs.sh"]
volumes:
- ./scripts/generate-audit-logs.sh:/generate-audit-logs.sh
# logger:
# image: "alpine/curl:latest"
# user: root
# depends_on:
# kibana:
# condition: service_healthy
# environment:
# - "KIBANA_SERVICE_HOST=http://kibana:5601"
# - "ELASTIC_PASSWORD=changeme"
# - "KIBANA_PASSWORD=changeme"
# command: /bin/sh ./generate-audit-logs.sh
# volumes:
# - ./scripts/generate-audit-logs.sh:/generate-audit-logs.sh
32 changes: 20 additions & 12 deletions packages/kibana/_dev/deploy/docker/scripts/generate-audit-logs.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
#!/bin/sh

# Makes requests to kibana API so that audit logs can be generated
attempt_counter=0
max_attempts=6

set -e
until curl -s --request GET \
--url $KIBANA_SERVICE_HOST/login \
--user "elastic:$KIBANA_PASSWORD" \
--header 'Content-Type: application/json'
do

until curl --request GET \
--user "elastic:$KIBANA_PASSWORD" \
--url $KIBANA_SERVICE_HOST/login \
--header 'Content-Type: application/json'
do sleep 10;
done;
if [ ${attempt_counter} -eq ${max_attempts} ];then
echo "Max attempts reached"
exit 1
fi

printf '.'
attempt_counter=$(($attempt_counter+1))
sleep 10
done

while true
do
echo Generating audit logs

curl --request GET \
curl -s --request GET \
--url $KIBANA_SERVICE_HOST/api/features \
--user "elastic:$KIBANA_PASSWORD" \
--url $KIBANA_SERVICE_HOST/api/features \
--header 'Content-Type: application/json'

echo "Audit log created"
sleep 10
done;
done
24 changes: 17 additions & 7 deletions packages/kibana/_dev/deploy/docker/scripts/setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#!/bin/sh

#Sets a password for kibana_system user
attempt_counter=0
max_attempts=6

set -e

until curl --request POST $ES_SERVICE_HOST/_security/user/kibana_system/_password \
--user elastic:$ELASTIC_PASSWORD \
until curl -s --request POST $ES_SERVICE_HOST/_security/user/kibana_system/_password \
--user "elastic:$ELASTIC_PASSWORD" \
--header 'Content-Type: application/json' \
--data "{\"password\":\"$KIBANA_PASSWORD\"}"
do sleep 10;
done;
--data "{\"password\":\"$KIBANA_PASSWORD\"}"
do
if [ ${attempt_counter} -eq ${max_attempts} ];then
echo "Max attempts reached"
exit 1
fi

printf '.'
attempt_counter=$(($attempt_counter+1))
sleep 10
done

echo "Setup complete"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type: kibana/metrics
dataset: kibana.stack_monitoring.cluster_actions
vars:
hosts:
- "http://elastic-package-service-kibana-1:5601"
- "http://{{Hostname}}:5601"
username: elastic
password: changeme
data_stream: ~
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type: kibana/metrics
dataset: kibana.stack_monitoring.cluster_rules
vars:
hosts:
- "http://elastic-package-service-kibana-1:5601"
- "http://{{Hostname}}:5601"
username: elastic
password: changeme
data_stream: ~
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type: kibana/metrics
dataset: kibana.stack_monitoring.node_actions
vars:
hosts:
- "http://elastic-package-service-kibana-1:5601"
- "http://{{Hostname}}:5601"
username: elastic
password: changeme
data_stream: ~
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type: kibana/metrics
dataset: kibana.stack_monitoring.node_rules
vars:
hosts:
- "http://elastic-package-service-kibana-1:5601"
- "http://{{Hostname}}:5601"
username: elastic
password: changeme
data_stream: ~
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type: kibana/metrics
dataset: kibana.stack_monitoring.stats
vars:
hosts:
- "http://elastic-package-service-kibana-1:5601"
- "http://{{Hostname}}:5601"
username: elastic
password: changeme
data_stream: ~
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type: kibana/metrics
dataset: kibana.stack_monitoring.status
vars:
hosts:
- "http://elastic-package-service-kibana-1:5601"
- "http://{{Hostname}}:5601"
username: elastic
password: changeme
data_stream: ~

0 comments on commit cf14f66

Please sign in to comment.