Browse Source

Extraction of mongo tasks complete

Jim Barritt 11 months ago
parent
commit
edc5094659

+ 11 - 0
apps/petitions/decode-app/Makefile

@@ -0,0 +1,11 @@
1
+.SILENT: status
2
+
3
+status:
4
+	./ops/local/mongo.sh status
5
+
6
+up:
7
+	./ops/local/mongo.sh up
8
+
9
+down:
10
+	./ops/local/mongo.sh down
11
+

+ 6 - 0
apps/petitions/decode-app/ops/local/env.sh

@@ -0,0 +1,6 @@
1
+#!/usr/bin/env bash
2
+
3
+APP_NAME="decode/app"
4
+DECODE_APP_HOST="http://localhost:3040"
5
+CLUSTER_NAME="petitions-app"
6
+

+ 46 - 0
apps/petitions/decode-app/ops/local/lib.sh

@@ -0,0 +1,46 @@
1
+#!/usr/bin/env bash
2
+
3
+# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
4
+# https://www.ostricher.com/2014/10/the-right-way-to-get-the-directory-of-a-bash-script/
5
+
6
+# TODO: make it so you have to prefix the commands with cmd_ or something so not all functions are availbale
7
+function lib/process_commands {
8
+    CMD=$1
9
+    shift
10
+    ${CMD} $@
11
+}
12
+
13
+
14
+# https://stackoverflow.com/questions/11231937/bash-ignoring-error-for-a-particular-command
15
+# -o makes the output disappear, -s means silent so it doesnt show you what download status
16
+function lib/http_status_of {
17
+    URL=$1
18
+    HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}\n" ${URL} || true)
19
+    if [[ ${HTTP_STATUS} == 200 ]]; then
20
+        echo "Running (200 ok)"
21
+    else
22
+        echo "Not running (${HTTP_STATUS})"
23
+    fi
24
+}
25
+
26
+function lib/wait_for_service {
27
+  HOST=$1
28
+  ATTEMPTS=0
29
+  echo "\nWaiting for service to appear @ ${HOST} ...\n"
30
+  while :
31
+  do
32
+    echo "Trying to reach ${HOST} [${ATTEMPTS}] ..."
33
+    HTTP_STATUS=$(lib/http_status_of ${HOST})
34
+    if [[ ${HTTP_STATUS} == "Running (200 ok)" ]]; then
35
+      echo "Service @ ${HOST} is available"
36
+      break;
37
+    fi
38
+    ((ATTEMPTS++))
39
+    if [[ ${ATTEMPTS} == 15 ]]; then
40
+      echo "The service ${HOST} is still not available after 15 retries"
41
+      echo "Exiting"
42
+      exit 1
43
+    fi
44
+    sleep 2
45
+  done
46
+}

apps/petitions/decode-app/docker-compose.mongo.yml → apps/petitions/decode-app/ops/local/mongo.docker-compose.yml


+ 62 - 0
apps/petitions/decode-app/ops/local/mongo.sh

@@ -0,0 +1,62 @@
1
+#!/usr/bin/env bash
2
+
3
+set -e # Exit script if anything fails
4
+set -u # unset variables cause an error
5
+set -o pipefail # https://coderwall.com/p/fkfaqq/safer-bash-scripts-with-set-euxo-pipefail
6
+#set -x # for debugging each command
7
+
8
+SCRIPT_HOME=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)
9
+
10
+source ${SCRIPT_HOME}/env.sh
11
+source ${SCRIPT_HOME}/lib.sh
12
+
13
+DOCKER_COMPOSE_CONFIG=${SCRIPT_HOME}/mongo.docker-compose.yml
14
+
15
+# File-local config
16
+MONGO_HOST="http://localhost:27017"
17
+
18
+DOCKER_COMMAND="docker-compose -f ${DOCKER_COMPOSE_CONFIG}"
19
+
20
+function status {
21
+    echo -e "Status of local mongo docker:\n"
22
+    echo -e "Docker Config: \n${DOCKER_COMPOSE_CONFIG}\n"
23
+    ${DOCKER_COMMAND} ps
24
+
25
+    HTTP_STATUS=$(lib/http_status_of ${MONGO_HOST})
26
+
27
+
28
+    echo -e "\nStatus of mongo db @ ${MONGO_HOST}: ${HTTP_STATUS}\n"
29
+}
30
+
31
+function docker-logs {
32
+    LOGS_FOLLOW=${1: }
33
+    ${DOCKER_COMMAND} logs ${LOGS_FOLLOW}
34
+}
35
+
36
+function logs {
37
+    LOG_SOURCE=$1
38
+    shift
39
+
40
+    case ${LOG_SOURCE} in
41
+        "docker")
42
+            docker-logs $@
43
+            ;;
44
+        *)
45
+            echo -e "Don't understand how to show you logs for ${LOG_SOURCE}"
46
+            ;;
47
+    esac
48
+}
49
+
50
+function up {
51
+    echo -e "\nStarting local docker container with mongo (run [${SCRIPT_HOME}/mongo.sh docker-logs] to see details)\n"
52
+    ${DOCKER_COMMAND}  up -d
53
+    lib/wait_for_service $MONGO_HOST
54
+    status
55
+}
56
+
57
+function down {
58
+    echo "Stopping local mongo docker container ...\n"
59
+    ${DOCKER_COMMAND} down
60
+    echo -e "\nMongo stopped."
61
+}
62
+lib/process_commands $@

File diff suppressed because it is too large
+ 2887 - 2887
apps/petitions/petitions-app/package-lock.json