Skip to content

Commit

Permalink
Merge pull request #52 from jembi/PLAT-235-logstash-dev-mount
Browse files Browse the repository at this point in the history
PLAT-235 Logstash dev mount
  • Loading branch information
Mark-Labuschagne authored May 25, 2022
2 parents f3bf5c2 + d7cb881 commit c733836
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ KIBANA_SSL=false
# ES_ELASTIC - Required for Logstash, set in the "Analytics Datastore - Elastic Search" section
LS_JAVA_OPTS=-Xmx2g -Xms2g

LOGSTASH_DEV_MOUNT=false
LOGSTASH_PACKAGE_PATH=

# Dashboard Visualiser - JS Report

JS_REPORT_INSTANCES=1
Expand Down
11 changes: 11 additions & 0 deletions data-mapper-logstash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Data Mapper - Logstash

## Developing the logstash configs locally

When seeking to make changes to the logstash configs without having to repeatedly start and stop the service, one can set the `LOGSTASH_DEV_MOUNT`
env var in your .env file to `true` to attach the service's config files to those on your local machine.

## Notes

- With `LOGSTASH_DEV_MOUNT=true`, you have to set the `LOGSTASH_PACKAGE_PATH` variable with the absolute path to package containing your Logstash config files, i.e., `LOGSTASH_PACKAGE_PATH=/home/user/Documents/Projects/platform/data-mapper-logstash`.
- WARNING: do not edit the pipeline files from within the logstash container, or the group ID and user ID will change, and subsequently will result in file permission errors on your local file system.
2 changes: 0 additions & 2 deletions data-mapper-logstash/dev-mnt-logstash.sh

This file was deleted.

7 changes: 7 additions & 0 deletions data-mapper-logstash/docker-compose.dev-mnt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3.9'

services:
data-mapper-logstash:
volumes:
- ${LOGSTASH_PACKAGE_PATH}/pipeline/:/usr/share/logstash/pipeline/
- ${LOGSTASH_PACKAGE_PATH}/pipelines.yml:/usr/share/logstash/config/pipelines.yml
2 changes: 2 additions & 0 deletions data-mapper-logstash/package-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"environmentVariables": {
"ES_ELASTIC": "${ES_ELASTIC}",
"LS_JAVA_OPTS": "-Xmx2g -Xms2g",
"LOGSTASH_DEV_MOUNT": "false",
"LOGSTASH_PACKAGE_PATH": "",
"LOGSTASH_MEMORY_LIMIT": "3G",
"LOGSTASH_MEMORY_RESERVE": "500M"
},
Expand Down
20 changes: 18 additions & 2 deletions data-mapper-logstash/swarm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Action=$1
Mode=$2

readonly LOGSTASH_DEV_MOUNT=$LOGSTASH_DEV_MOUNT

COMPOSE_FILE_PATH=$(
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
pwd -P
Expand Down Expand Up @@ -61,16 +63,30 @@ else
LogstashDevComposeParam=""
fi

if [[ "$LOGSTASH_DEV_MOUNT" == "true" ]]; then
if [[ -z $LOGSTASH_PACKAGE_PATH ]]; then
echo "ERROR: LOGSTASH_PACKAGE_PATH environment variable not specified. Please specify LOGSTASH_PACKAGE_PATH as stated in the README."
exit 1
fi

echo -e "\nRunning Data Mapper Logstash package with dev mount\n"
LogstashDevMountComposeParam="-c ${COMPOSE_FILE_PATH}/docker-compose.dev-mnt.yml"
else
LogstashDevMountComposeParam=""
fi

if [[ "$Action" == "init" ]] || [[ "$Action" == "up" ]]; then

config::set_config_digests "$COMPOSE_FILE_PATH"/docker-compose.yml

docker stack deploy -c "$COMPOSE_FILE_PATH"/docker-compose.yml $LogstashDevComposeParam instant
docker stack deploy -c "$COMPOSE_FILE_PATH"/docker-compose.yml $LogstashDevComposeParam $LogstashDevMountComposeParam instant

AwaitContainerStartup
AwaitContainerReady

config::copy_shared_configs "$COMPOSE_FILE_PATH"/package-metadata.json /usr/share/logstash/
if [[ "$LOGSTASH_DEV_MOUNT" != "true" ]]; then
config::copy_shared_configs "$COMPOSE_FILE_PATH"/package-metadata.json /usr/share/logstash/
fi

echo "Removing stale configs..."
config::remove_stale_service_configs "$COMPOSE_FILE_PATH"/docker-compose.yml "logstash"
Expand Down
2 changes: 1 addition & 1 deletion utils/config-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ config::copy_shared_configs() {

for sharedConfig in "${sharedConfigs[@]}"; do
# TODO: (https://jembiprojects.jira.com/browse/PLAT-252) swap docker copy for a swarm compliant approach
docker cp "${packageBaseDir}""${sharedConfig//\"//}" "${containerId}":"${CONTAINER_DESTINATION}"
docker cp -a "${packageBaseDir}""${sharedConfig//\"//}" "${containerId}":"${CONTAINER_DESTINATION}"
done
}

Expand Down

0 comments on commit c733836

Please sign in to comment.