From 48c391139f4635e20a49f13eb0a4174a8d2f94ec Mon Sep 17 00:00:00 2001
From: Lyuben Penkovski <lyuben.penkovski@vereign.com>
Date: Mon, 28 Mar 2022 07:56:34 +0300
Subject: [PATCH] Policy service definition

---
 README.md          | 88 +++++++++++++++++++++++++++++++---------------
 docker-compose.yml | 49 +++++++++-----------------
 env/infohub.env    |  7 ----
 env/policy.env     | 10 ++++++
 env/resolver.env   |  4 ---
 setup.sh           | 11 +++---
 6 files changed, 91 insertions(+), 78 deletions(-)
 delete mode 100644 env/infohub.env
 create mode 100644 env/policy.env
 delete mode 100644 env/resolver.env

diff --git a/README.md b/README.md
index 88bd3d6..b916685 100644
--- a/README.md
+++ b/README.md
@@ -12,44 +12,74 @@ with environment variables which will be injected in its container.
 * [Install Go](https://golang.org/doc/install) and set the
   [`$GOPATH` variable](https://github.com/golang/go/wiki/SettingGOPATH).
 
-## Setup Workspace
-
-* create directory:
-  ```
-  mkdir -p $GOPATH/src/code.vereign.com/gaiax/tsa/
-  ```
-* move in the previously created directory:
-  ```
-  cd $GOPATH/src/code.vereign.com/gaiax/tsa/
-  ```
-* clone the repository:
-  ```
-  git clone git@code.vereign.com:gaiax/tsa/workspace.git
-  ```
-* run the setup.sh script:
-  ```
-  ./setup.sh
-  ```
-* set the services you would like to use in the docker-compose.yml file, defaults is **infohub**
-
-* run docker compose:
-  ```
-  docker-compose up
-  ```
+## Setup
+
+Clone the workspace repository into `$GOPATH/src/code.vereign.com/gaiax/tsa/workspace`. Using GOPATH is important
+because it's the way the workspace will know where to find you Go source code.
+
+```sh
+# create the backend directory where the workspace will be checked out
+mkdir -p $GOPATH/src/code.vereign.com/gaiax/tsa/workspace
+
+# change to the created directory
+cd $GOPATH/src/code.vereign.com/gaiax/tsa/workspace
+
+# clone the workspace repo
+git clone git@code.vereign.com:gaiax/tsa/workspace.git .
+```
+
+### Checkout services repos
+
+This step is optional because you may already have the repos checked out
+or you may want to do this step manually. But the workspace provides you
+with a `setup.sh` script which will go and checkout the TSA backend
+services at their correct locations, ready for use with `docker-compose`.
+
+```shell
+./setup.sh
+```
+
+> Note: If you have already checked out a repository, and it's not on the main branch or 
+> is not in a clean state, the script will give you a warning and won't override the 
+> state of your repo. You will have to checkout/update it manually.
+
+### Usage
+
+Now you're ready to start using the workspace environment.
+
+```shell
+# start all services
+docker-compose up -d
+
+# see the state of the containers and their exposed ports 
+docker-compose ps
+
+# follow the logs of all services in the workspace
+docker-compose logs -f 
+
+# follow the logs of specified services only
+docker-compose logs -f gateway infohub
+
+# restart a service
+docker-compose restart gateway
+
+# restart a service and reload its environment variables
+docker-compose up -d gateway
+
+# rebuild the docker image of a service
+docker-compose build gateway
+```
 
 ## 3rd Party Services
 
-### DID Resolver service
+#### DID Resolver
 
-The DID Resolver service can be reached at `localhost:9090` from your
-local machine.
+The DID Resolver service can be reached at `localhost:9090` from your local machine.
 Example usage:
 ```
 curl -X GET http://localhost:9090/1.0/identifiers/did:indy:idunion:BDrEcHc8Tb4Lb2VyQZWEDE
 curl -X GET http://localhost:9090/1.0/identifiers/did:key:z6Mkfriq1MqLBoPWecGoDLjguo1sB9brj6wT3qZ5BxkKpuP6
-curl -X GET http://localhost:9090/1.0/identifiers/did:schema:public-ipfs:json-schema:Qma2beXKwZeiUXcaRaQKwbBV1TqyiJnsMTYExUTdQue43J
 curl -X GET http://localhost:9090/1.0/identifiers/did:web:did.actor:alice
-curl -X GET http://localhost:9090/1.0/identifiers/did:sov:WRfXPg8dantKVubE3HX8pw
 ```
 In order to support more DID methods refer to currently supported ones here:
 ```
diff --git a/docker-compose.yml b/docker-compose.yml
index 519936e..5a7bfc7 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,52 +1,35 @@
 version: '3.4'
 
 services:
-  infohub:
-    container_name: infohub
+  policy:
+    container_name: policy
     build:
-      context: $GOPATH/src/code.vereign.com/gaiax/tsa/infohub
+      context: $GOPATH/src/code.vereign.com/gaiax/tsa/policy
       dockerfile: deployment/compose/Dockerfile
     volumes:
-      - "$GOPATH/src/code.vereign.com/gaiax/tsa/infohub:/go/src/code.vereign.com/gaiax/tsa/infohub"
+      - "$GOPATH/src/code.vereign.com/gaiax/tsa/policy:/go/src/code.vereign.com/gaiax/tsa/policy"
     env_file:
-      ./env/infohub.env
+      - ./env/policy.env
     ports:
-      - "8080:8080"
+      - "8081:8080"
 
-  redis:
-    image: "redis:alpine"
-    container_name: redis
-    ports:
-      - "6379:6379"
-
-  uni-resolver-web:
+  didresolver:
     image: universalresolver/uni-resolver-web:latest
     ports:
       - "9090:8080"
 
-  uni-resolver-driver-did-uport:
-    image: uport/uni-resolver-driver-did-uport:2.3.0
-    ports:
-      - "9091:8081"
-
-  driver-did-sov:
-    image: universalresolver/driver-did-sov:latest
-    env_file:
-      ./env/resolver.env
-    ports:
-      - "9092:8080"
-
-  driver-did-key:
+  didresolver-driver-did-key:
     image: universalresolver/driver-did-key:latest
     ports:
-      - "9093:8080"
-
-  schema-registry-did-resolver:
-    image: 51nodes/schema-registry-did-resolver:0.1.1
-    ports:
-      - "9094:8080"
+      - "9091:8080"
 
   indy-did-driver:
     image: ghcr.io/idunion/indy-did-resolver/indy-did-driver:latest
     ports:
-      - "9095:8080"
\ No newline at end of file
+      - "9092:8080"
+
+  redis:
+    image: "redis:alpine"
+    container_name: redis
+    ports:
+      - "6379:6379"
diff --git a/env/infohub.env b/env/infohub.env
deleted file mode 100644
index 47b333d..0000000
--- a/env/infohub.env
+++ /dev/null
@@ -1,7 +0,0 @@
-HTTP_HOST=""
-HTTP_PORT="8080"
-HTTP_IDLE_TIMEOUT="60s"
-HTTP_READ_TIMEOUT="10s"
-HTTP_WRITE_TIMEOUT="10s"
-HTTP_MAX_REQUEST_SIZE="1000000"
-REDIS_HOST="redis"
\ No newline at end of file
diff --git a/env/policy.env b/env/policy.env
new file mode 100644
index 0000000..bbc5899
--- /dev/null
+++ b/env/policy.env
@@ -0,0 +1,10 @@
+HTTP_HOST=""
+HTTP_PORT="8080"
+HTTP_IDLE_TIMEOUT="120s"
+HTTP_READ_TIMEOUT="10s"
+HTTP_WRITE_TIMEOUT="10s"
+REDIS_ADDR="redis:6379"
+REDIS_USER=""
+REDIS_PASS=""
+REDIS_DB=1
+REDIS_EXPIRATION="1h"
\ No newline at end of file
diff --git a/env/resolver.env b/env/resolver.env
deleted file mode 100644
index 53aec93..0000000
--- a/env/resolver.env
+++ /dev/null
@@ -1,4 +0,0 @@
-uniresolver_driver_did_sov_libIndyPath=
-uniresolver_driver_did_sov_poolConfigs=_;./sovrin/_.txn;staging;./sovrin/staging.txn;builder;./sovrin/builder.txn;danube;./sovrin/danube.txn;idu;./sovrin/idu.txn;eesdi;./sovrin/eesdi.txn;indicio;./sovrin/indicio.txn;indicio:test;./sovrin/indicio-test.txn;indicio:demo;./sovrin/indicio-demo.txn;bbu;./sovrin/bbu.txn
-uniresolver_driver_did_sov_poolVersions=_;2;staging;2;builder;2;danube;2;idu;2;eesdi;2;indicio;2;indicio:test;2;indicio:demo;2;bbu;2
-uniresolver_driver_did_sov_walletName=default
diff --git a/setup.sh b/setup.sh
index 3a1cf7b..8b63480 100755
--- a/setup.sh
+++ b/setup.sh
@@ -11,7 +11,7 @@
 # export email="lyuben.penkovski@vereign.com"
 # ------------
 
-# pull the master branch of a given git repository.
+# pull the main branch of a given git repository.
 # User will be prompted for manual action if another branch is checked out or a problem occurs.
 # $1 - name of the repo to pull.
 function pull() {
@@ -20,9 +20,9 @@ function pull() {
   pushd "${repo}"
 
   local branch=`git rev-parse --abbrev-ref HEAD`
-  if [ $branch == "master" ]; then
-    echo "Pulling ${repo}/master..."
-    git pull origin master || read -p "Could not pull ${repo}/master. Fix the issue and press ENTER to continue:"
+  if [ $branch == "main" ]; then
+    echo "Pulling ${repo}/main..."
+    git pull origin main || read -p "Could not pull ${repo}/main. Fix the issue and press ENTER to continue:"
   else
     echo "${repo}/${branch} is checked out"
     read -p "Pull ${repo} manually now or press ENTER to skip:"
@@ -38,7 +38,8 @@ function getServices() {
   mkdir -p "${GAIAX_TSA_DIR}" && cd "$_"
 
   local services=(
-    "infohub"
+    "policy"
+    "task"
   )
 
   for repo in ${services[@]}; do
-- 
GitLab