Browse Source

Added chainspace commands

Jim Barritt 11 months ago
parent
commit
968128c89e

+ 8 - 0
apps/petitions/decode-app/do.sh

@@ -21,6 +21,11 @@ function mongo {
21 21
     ./ops/local/mongo.sh $@
22 22
 }
23 23
 
24
+function chainspace {
25
+    ./ops/local/chainspace.sh $@
26
+}
27
+
28
+
24 29
 function decode-app {
25 30
     ./ops/local/decode-app.sh $@
26 31
 }
@@ -30,6 +35,9 @@ function status {
30 35
     decode-app status
31 36
 }
32 37
 
38
+function init_docker {
39
+    ./ops/local/docker.sh init
40
+}
33 41
 
34 42
 function up {
35 43
     mongo start

+ 4 - 0
apps/petitions/decode-app/ops/local/_docker-compose.yml

@@ -4,3 +4,7 @@ services:
4 4
     image: "mongo:4.1.6"
5 5
     ports:
6 6
      - "27017:27017"
7
+  chainspace:
8
+    image: "chainspace"
9
+    ports:
10
+      - "5000:5000"

+ 1 - 0
apps/petitions/decode-app/ops/local/_env.sh

@@ -7,6 +7,7 @@ APP_NAME="decode/app"
7 7
 CLUSTER_NAME="petitions-app"
8 8
 
9 9
 DOCKER_COMPOSE_CONFIG=${SCRIPT_HOME}/_docker-compose.yml
10
+DOCKER_COMMAND="docker-compose -f ${DOCKER_COMPOSE_CONFIG}"
10 11
 
11 12
 source ${SCRIPT_HOME}/_lib.sh
12 13
 

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

@@ -1,2 +1,64 @@
1 1
 #!/usr/bin/env bash
2 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
+
12
+
13
+CHAINSPACE_API_URL="http://localhost:5000/api/1.0/"
14
+
15
+
16
+function status {
17
+    echo -e "Status of local chainspace docker:\n"
18
+    echo -e "Docker Config: \n${DOCKER_COMPOSE_CONFIG}\n"
19
+    ${DOCKER_COMMAND} ps chainspace
20
+
21
+    HTTP_STATUS=$(lib/http_status_of ${CHAINSPACE_API_URL})
22
+
23
+    echo -e "\nStatus of local chainspace api @ ${CHAINSPACE_API_URL}: ${HTTP_STATUS}\n"
24
+}
25
+
26
+function logs {
27
+    LOG_SOURCE=$1
28
+    shift
29
+
30
+    case ${LOG_SOURCE} in
31
+        "docker")
32
+            docker-logs $@
33
+            ;;
34
+        *)
35
+            echo -e "Don't understand how to show you logs for ${LOG_SOURCE}"
36
+            ;;
37
+    esac
38
+}
39
+
40
+function start {
41
+    echo -e "\nStarting local docker container with chainspace (run [${SCRIPT_HOME}/chainspace.sh docker-logs] to see details)\n"
42
+    ${DOCKER_COMMAND} start chainspace
43
+    lib/wait_for_service ${CHAINSPACE_API_URL}
44
+    status
45
+}
46
+
47
+function stop {
48
+    echo "Stopping local chainspace docker container ...\n"
49
+    ${DOCKER_COMMAND} stop chainspace
50
+    echo -e "\nMongo stopped."
51
+}
52
+
53
+function restart {
54
+    echo "Restarting local chainspace docker container ...\n"
55
+    ${DOCKER_COMMAND} restart chainspace
56
+    echo -e "\Chainspace stopped."
57
+}
58
+
59
+function shell {
60
+    ${DOCKER_COMMAND} exec chainspace sh
61
+}
62
+
63
+
64
+lib/process_commands $@

+ 28 - 0
apps/petitions/decode-app/ops/local/docker.sh

@@ -0,0 +1,28 @@
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
+
12
+
13
+function status {
14
+    echo -e "Status of local docker:\n"
15
+    echo -e "Docker Config: \n${DOCKER_COMPOSE_CONFIG}\n"
16
+
17
+
18
+    ${DOCKER_COMMAND} ps
19
+
20
+
21
+}
22
+
23
+function init {
24
+    ${DOCKER_COMMAND} up --no-start
25
+
26
+}
27
+
28
+lib/process_commands $@

+ 1 - 1
apps/petitions/decode-app/ops/local/mongo.lib.sh

@@ -10,7 +10,7 @@ MONGO_URL="http://${MONGO_HOST}:${MONGO_PORT}"
10 10
 
11 11
 
12 12
 
13
-DOCKER_COMMAND="docker-compose -f ${DOCKER_COMPOSE_CONFIG}"
13
+
14 14
 
15 15
 
16 16
 function mongo/connection {

+ 5 - 1
apps/petitions/decode-app/ops/local/mongo.sh

@@ -60,11 +60,15 @@ function restart {
60 60
     echo -e "\nMongo stopped."
61 61
 }
62 62
 
63
-
64 63
 function shell {
65 64
     mongo/shell
66 65
 }
67 66
 
67
+function docker-shell {
68
+    ${DOCKER_COMMAND} exec chainspace sh
69
+}
70
+
71
+
68 72
 
69 73
 lib/process_commands $@
70 74