comparison prod/install-docstore-app.sh @ 609:30a35d908d92

DS-56 create docstore local install script
author calmes@ssdt-ohio.org
date Wed, 02 Jul 2025 13:25:13 +0100
parents
children
comparison
equal deleted inserted replaced
604:f05817aee0f0 609:30a35d908d92
1 #!/bin/bash
2 #
3 # read required env variables
4 BASEDIR="$PWD"
5 source $BASEDIR/.env/ssdt-document-store-shared.properties
6 source $BASEDIR/.env/ssdt-document-store.properties
7
8 # define entityId based environment variables
9 ES_SETTING_CLUSTER_NAME=${entityId}-document-store
10 ES_SETTING_NODE_NAME=${entityId}-ds-01
11 DOCUMENTSTORE_ELASTIC_HOST=${entityId}-document
12 ELASTIC_NETWORK=${entityId}-document
13
14 # create backup directory if it does not exist
15 BACKUP_DIR="$BASEDIR/backup"
16 if [ ! -d "$BACKUP_DIR" ]
17 then
18 mkdir "$BACKUP_DIR"
19 fi
20
21 # create docker network if it does not exist
22 if [ -z $(docker network ls --filter name=^${ELASTIC_NETWORK}$ --format="{{ .Name }}") ]
23 then
24 docker network create "${ELASTIC_NETWORK}";
25 fi
26
27 # docker login
28 echo "Attempting to login to $artifactUrl"
29 docker login $artifactUrl -u $artifactUser -p $artifactPassword
30 # docker pull image
31 echo "Attempting to pull $artifactUrl/document-store:$DS_VERSION"
32 docker pull $artifactUrl/document-store:$DS_VERSION
33
34 # build docker run command based on environment variables provided
35 DOCKER_RUN="docker run --name=$ES_SETTING_NODE_NAME --restart=unless-stopped --log-driver local \
36 --env-file $BASEDIR/.env/ssdt-document-store.properties \
37 -e ELASTIC_PASSWORD=$ELASTIC_PASSWORD \
38 --network=$ELASTIC_NETWORK \
39 --ulimit memlock=-1:-1 \
40 --ulimit nofile=65535:65535 \
41 --group-add 0 \
42 --mount type=bind,source=$BACKUP_DIR,destination=/usr/share/elasticsearch/backup/ \
43 --mount type=volume,source=$entityId-document-data,destination=/usr/share/elasticsearch/data/ \
44 --mount type=volume,source=$entityId-document-config,destination=/usr/share/elasticsearch/config/ \
45 -p $DOCUMENTSTORE_ELASTIC_PORT:9200 \
46 -p $DOCUMENTSTORE_TRANSPORT_PORT:9300 \
47 "
48 if [ -d "$BASEDIR/jvm.options.d" ]; then
49 DOCKER_RUN="$DOCKER_RUN --mount type=bind,source=$BASEDIR/jvm.options.d,destination=/usr/share/elasticsearch/config/jvm.options.d/ "
50 fi
51
52 #echo "Executing docker run command $DOCKER_RUN"
53 DOCKER_RUN="$DOCKER_RUN -d docker-images.ssdt-ohio.org/document-store:${DS_VERSION:-latest}"
54 $DOCKER_RUN
55
56 #wait for instance to start
57 attempt=0
58 while [ $attempt -le 15 ]; do
59 attempt=$(( attempt + 1 ))
60 echo "Waiting for server to be up (attempt: $attempt)..."
61 result=$(docker inspect --format='{{.State.Health.Status}}' "$ES_SETTING_NODE_NAME")
62 if [ "$result" = "healthy" ] ; then
63 echo "Elasticsearch is up, preparing to copy certificates and generated properties"
64 break
65 fi
66 sleep 10
67 done
68
69 # copy elasticsearch certificate to basedir for further use if necessary
70 docker cp "$ES_SETTING_NODE_NAME":/usr/share/elasticsearch/config/certs/http_ca.crt "$BASEDIR"
71
72 # copy generated properites i.e. API keys etc to basedir for use in product integration
73 attempt=0
74 generated_contents=$(docker exec -it "$ES_SETTING_NODE_NAME" sed -rn 's/^DOCUMENTSTORE_ELASTIC_FINGERPRINT=([^\n]+)$/\1/p' /usr/share/elasticsearch/config/ssdt-document-store-generated.properties)
75 while [ "$generated_contents" == "" ] && [ $attempt -le 15 ]; do
76 attempt=$(( attempt + 1 ))
77 echo "Waiting for generated properties to be created (attempt: $attempt)..."
78 sleep 10
79 generated_contents=$(docker exec -it "$ES_SETTING_NODE_NAME" sed -rn 's/^DOCUMENTSTORE_ELASTIC_FINGERPRINT=([^\n]+)$/\1/p' /usr/share/elasticsearch/config/ssdt-document-store-generated.properties)
80 done
81 docker cp "$ES_SETTING_NODE_NAME":/usr/share/elasticsearch/config/ssdt-document-store-generated.properties "$BASEDIR"/.env
82
83
84 echo "Elasticsearch is up and running, certificate & generated properties copied"