# Installation

### Knowledge Needed

A good understanding of docker, docker-compose & nginx

### Prerequisites

#### Docker

Installation instructions for Docker can be found [here](https://docs.docker.com/engine/install/).

Run `docker -v` in terminal to check if `docker` has been installed correctly:

```
$ docker -v
Docker version 20.10.9, build c2ea9bc90b
```

#### Docker Compose

Installation instructions can be found [here](https://docs.docker.com/compose/install/).

Run `docker compose version` in the terminal to check if `docker compose` has been installed correctly:

```
$ docker compose version
Docker Compose version 2.0.1
```

### Backend Setup <a href="#btcqa01b80kx" id="btcqa01b80kx"></a>

### Getting Code for Backend <a href="#pjvmd0ibetjy" id="pjvmd0ibetjy"></a>

Clone the repo

```bash
git clone https://github.com/Sunbird-RC/demo-education-registry.git
git checkout federated_edu_registry
```

This will create a demo-education-registry folder in the current working directory. Goto that folder

### Setting up a Registry Instance <a href="#id-5l1lkhqaq9ey" id="id-5l1lkhqaq9ey"></a>

In the demo-education-folder, run the following command

```bash
docker compose up -d
```

This will start all the required services. Once all the services are started, Go to the browser and open <http://localhost:8080/auth/>. This will open up the keycloak admin portal. Use username as `admin` and password as `admin`.

Once logged in, navigate to `clients`. Select `admin-api`. Go to `credentials` tab and click on regenerate secret. Copy this secret. Create a .env file in the project repo and add `KEYCLOAK_SECRET` it as an environment variable with the value of the secret in the following format\
`KEYCLOAK_SECRET=<copied_secret>`

![](https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-557b7b097f8c02a186bce3be8deba025dfa720ca%2F0.png?alt=media)

Recreate the registry so that it reflects the keycloak secret. This can be done using

```bash
docker compose up -d --force-recreate --no-deps registry
```

If any service has not started you can recreate that service with the same command

```bash
docker compose up -d --force-recreate --no-deps <service_name>
```

Check if all the services are started

```bash
docker compose ps
```

```bash
NAME                                                   IMAGE                                                  COMMAND                  SERVICE                      CREATED              STATUS                                 PORTS
demo-education-registry-adhoc_worker-1                 redash/redash:8.0.0.b32245                             "/app/bin/docker-ent…"   adhoc_worker                 About a minute ago   Up About a minute                      5000/tcp
demo-education-registry-certificate-api-1              ghcr.io/sunbird-rc/sunbird-rc-certificate-api                   "docker-entrypoint.s…"   certificate-api              17 hours ago         Up 17 hours (healthy)                  0.0.0.0:8078->8078/tcp, :::8078->8078/tcp
demo-education-registry-certificate-signer-1           ghcr.io/sunbird-rc/sunbird-rc-certificate-signer                "docker-entrypoint.s…"   certificate-signer           17 hours ago         Up 17 hours (healthy)                  0.0.0.0:8079->8079/tcp, :::8079->8079/tcp
demo-education-registry-claim-ms-1                     ghcr.io/sunbird-rc/sunbird-rc-claim-ms:v0.0.13                  "java -jar /app.jar"     claim-ms                     About a minute ago   Up About a minute                      0.0.0.0:8082->8082/tcp, :::8082->8082/tcp
demo-education-registry-clickhouse-1                   clickhouse/clickhouse-server:head-alpine               "/entrypoint.sh"         clickhouse                   17 hours ago         Up 17 hours (healthy)                  8123/tcp, 9009/tcp, 0.0.0.0:9004->9000/tcp, :::9004->9000/tcp
demo-education-registry-db-1                           postgres                                               "docker-entrypoint.s…"   db                           About a minute ago   Up About a minute                      0.0.0.0:5432->5432/tcp, :::5432->5432/tcp
demo-education-registry-digilocker_certificate_api-1   sunbirdrc/sunbird-rc-digilocker-certificate-api        "/go/main"               digilocker_certificate_api   About a minute ago   Up About a minute                      8086/tcp, 0.0.0.0:8087->8087/tcp, :::8087->8087/tcp
demo-education-registry-es-1                           docker.elastic.co/elasticsearch/elasticsearch:7.10.1   "/tini -- /usr/local…"   es                           17 hours ago         Up 17 hours (healthy)                  0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp
demo-education-registry-file-storage-1                 quay.io/minio/minio                                    "/usr/bin/docker-ent…"   file-storage                 17 hours ago         Up 17 hours (healthy)                  0.0.0.0:9003->9000/tcp, :::9003->9000/tcp, 0.0.0.0:9002->9001/tcp, :::9002->9001/tcp
demo-education-registry-kafka-1                        confluentinc/cp-kafka:latest                           "/etc/confluent/dock…"   kafka                        17 hours ago         Up 17 hours (unhealthy)                0.0.0.0:9092->9092/tcp, :::9092->9092/tcp
demo-education-registry-keycloak-1                     ghcr.io/sunbird-rc/sunbird-rc-keycloak:nonce                    "/opt/jboss/tools/do…"   keycloak                     About a minute ago   Up About a minute (health: starting)   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp, 0.0.0.0:9990->9990/tcp, :::9990->9990/tcp, 8443/tcp
demo-education-registry-metrics-1                      ghcr.io/sunbird-rc/sunbird-rc-metrics:metrics                    "/app/metrics/metric…"   metrics                      17 hours ago         Up 2 minutes                           0.0.0.0:8070->8070/tcp, :::8070->8070/tcp
demo-education-registry-nginx-1                        ghcr.io/sunbird-rc/sunbird-rc-nginx                             "/docker-entrypoint.…"   nginx                        About a minute ago   Restarting (1) 26 seconds ago
demo-education-registry-redis-1                        redis                                                  "docker-entrypoint.s…"   redis                        17 hours ago         Up 17 hours                            0.0.0.0:6379->6379/tcp, :::6379->6379/tcp
demo-education-registry-registry-1                     ghcr.io/sunbird-rc/sunbird-rc-core:metrics                       "java -Xms1024m -Xmx…"   registry                     About a minute ago   Up About a minute                      0.0.0.0:8081->8081/tcp, :::8081->8081/tcp
demo-education-registry-scheduled_worker-1             redash/redash:8.0.0.b32245                             "/app/bin/docker-ent…"   scheduled_worker             About a minute ago   Up About a minute                      5000/tcp
demo-education-registry-scheduler-1                    redash/redash:8.0.0.b32245                             "/app/bin/docker-ent…"   scheduler                    About a minute ago   Up About a minute                      5000/tcp
demo-education-registry-server-1                       redash/redash:8.0.0.b32245                             "/app/bin/docker-ent…"   server                       About a minute ago   Up About a minute                      0.0.0.0:5678->5000/tcp, :::5678->5000/tcp
demo-education-registry-zookeeper-1                    confluentinc/cp-zookeeper:latest                       "/etc/confluent/dock…"   zookeeper                    17 hours ago         Up 17 hours                            2888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp, 3888/tcp
```

### Setting up Keycloak <a href="#id-9kf7tx8j3sxx" id="id-9kf7tx8j3sxx"></a>

**Adding Roles**

Open <http://localhost:8080/auth/> in the browser and navigate to roles in the left side pane. Click on Add Role.

![](https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-81fb2f3e0c11bd0ce75e8ab80ac250d99afce939%2F1.png?alt=media)

Create `admin`, `scholarship`, `trial-scholarship` roles

![](https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-d807d107765a553ceac1c493f507a1411c1facd9%2F2.png?alt=media)

Create `admin` user in keycloak

![](https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-bf6efe89226580a71319c8a6aefb7fd06a502dc1%2F3.png?alt=media)

Update the credential for the `admin` user. `Ex: abcd@123`

![](https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-5ce3a4735ca0ae0534528cc268e0fa8ed1fc1b9f%2F4.png?alt=media)

Assign `admin` role to this user

![](https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-a5ea2a0746b3dd5aae5b16d381f768403a724591%2F5.png?alt=media)

Now you can use the `admin` user to create issuers, create schemas, issue VCs and view issued VCs\
You can follow the following [jupyter notebook](https://github.com/varadeth/demo-education-registry/blob/issue_624_backend_eer_docs/issuance.ipynb) which has all the APIs.

**Note**:-

* Schemas for EER are present in the following location

{% embed url="<https://github.com/Sunbird-RC/demo-education-registry/tree/federated_edu_registry/sample_schemas>" %}

#### Assign \`admin\` role to the issuer

* An issuer will require `admin` role to create schemas in the registry.
* Goto keycloak admin console, <http://localhost:8080/auth/>
* Goto `Groups` and double-click on `Issuer`
* If `Issuer` group is not found, then you need to create an issuer first. The APIs to create the issuer is documented in the above jupyter notebook.
* Goto `Role Mappings` and select `admin` from `Available Roles` and click `Add Selected`

<figure><img src="https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-96c04320500a54050dde95ef6125e2a8d81b5bf7%2FScreenshot%202023-05-25%20at%2010.56.30%20AM.png?alt=media" alt=""><figcaption></figcaption></figure>

The issuer will require the same roles that are configured in the schema configuration to issue VCs for that schema. In the below sample schema, `ScholarshipForTopClassStudents` it requires a user to have `scholarship` role. Only if the issuer contains that role then he will be able to issue VC. Similar to the above steps, you can assign the `scholarship` roles to the issuer to get access.

{% embed url="<https://github.com/Sunbird-RC/demo-education-registry/blob/federated_edu_registry/sample_schemas/PreMatricScholarship.json#L90>" %}

### Setting up Redash <a href="#cf0y99rd0e19" id="cf0y99rd0e19"></a>

How to configure

Once all the services are up and running, run the following command

```bash
docker compose run --rm server create_db
```

This command will run migrations for redash

Once this is successful, open the <http://localhost:5678> in the browser. The following screen should be displayed

![](https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-8164c3a11386b955c2572362c8a7c489b860fc04%2F6.png?alt=media)

You can create the admin user on this screen. Once you create the admin user, the admin user will be displayed. Here you can create a dashboard, queries etc. Create a dashboard and queries here

![](https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-eadd936ba8d7e08005cb7b717df7f01da835d7d9%2F7.png?alt=media)

#### Connect to the data source

* On the home page click on `Connect a Data Source`
* Search for `Clickhouse`
* Add these details on the form to set up a connection with Clickhouse

![](https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-669da43b2e2217d2ce07a6857ee77c4d3e0ce359%2F9.png?alt=media)

Now that you have connected to Clickhouse, you can create queries. Once a query is created, you can add your visualization for the same.

#### Create a query and visualization

Create a visualization showing the total number of VCs issued for `PreMatricScholarship` schema.

* Goto `Queries` tab
* Click on `Create your first Query`
* Paste the below query and click on `Save`

`select count(*) as count from default.prematricscholarship`

* Rename this query `New Query` to `Total PreMatricScholarship VC Issued`

<figure><img src="https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-243d38d3d4ac4de67d1cb3064dfe1e8a1feb0992%2FScreenshot%202023-05-25%20at%2012.20.13%20PM.png?alt=media" alt=""><figcaption></figcaption></figure>

* Click on `Save` and click on `Publish`
* Click on `Show Data Only`
* At the bottom click on `Blue Play Button`
* Click on `+ New Visualization`
* Create a visualization with the below values. And click on `Save`

<figure><img src="https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-b4b2b8771372dad916e9af270dc02d8fef6778fb%2FScreenshot%202023-05-25%20at%2012.27.35%20PM.png?alt=media" alt=""><figcaption></figcaption></figure>

* Click on `Create` and click on `Dashboard`. You can give a name to your dashboard and click on `Save`

  <figure><img src="https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-40a0d7100943b75dd9a8d42af08bb7e658cf80d8%2FScreenshot%202023-05-25%20at%2012.15.09%20PM.png?alt=media" alt=""><figcaption></figcaption></figure>
* Click on `Add Widget` and select the new visualization created. And click `Add to Dashboard`

<figure><img src="https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-5e006c7d8aed17683adc4c01732fa91500681312%2FScreenshot%202023-05-25%20at%2012.30.38%20PM.png?alt=media" alt=""><figcaption></figcaption></figure>

* Click on `Done editing` and click on `Publish`

<figure><img src="https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-3d0c008a09db78774af7bcfd38ef4b300bb25acf%2FScreenshot%202023-05-25%20at%2012.32.27%20PM.png?alt=media" alt=""><figcaption></figcaption></figure>

* Now the dashboard can be shared with other members. Click on `Share` and enable `public access` and copy the URL and share it with others for viewing the dashboard

  <figure><img src="https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-c6ee44046025d875f688789758bffaeed2d382b0%2FScreenshot%202023-05-25%20at%2012.33.26%20PM.png?alt=media" alt=""><figcaption></figcaption></figure>

### Frontend Setup <a href="#lcjuuta90ki" id="lcjuuta90ki"></a>

* Navigate to this repository and create a fork & clone <https://github.com/Sunbird-RC/federated-education-registry>
* Navigate to the federated-education-registry folder

![](https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-f0b083193160cd9b54ab108be5a2d1c45e63e627%2Funknown.png?alt=media)

* Make sure your node and npm versions are - node v16.13.1 (npm v8.1.2)

You can also manage these versions using [Node Version Manager](https://www.freecodecamp.org/news/node-version-manager-nvm-install-guide/)

![](https://976594346-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mi9TAMApVKuSwtZEklF%2Fuploads%2Fgit-blob-99f2c7dad63e70233267e6bf9c61829f8863965d%2Funknown.png?alt=media)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sunbirdrc.dev/reference-solutions-for-functional-registries/education/education-ecosystem/installation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
