|
| 1 | +# Local Rosetta API Cluster |
| 2 | + |
| 3 | +This directory contains scripts and configurations for setting up a local Kubernetes cluster using Minikube to deploy the Rosetta API services. The cluster includes monitoring tools such as Prometheus, cAdvisor, and Grafana. |
| 4 | + |
| 5 | +## Purpose |
| 6 | + |
| 7 | +The purpose of this cluster is to provide a local development and testing environment for the Rosetta API services. It allows developers to deploy and test their services in a controlled environment with monitoring capabilities. |
| 8 | + |
| 9 | +## What It Does |
| 10 | + |
| 11 | +- Sets up a Minikube cluster with a specified profile. |
| 12 | +- Installs Prometheus, cAdvisor, and Grafana for monitoring. |
| 13 | +- Deploys the Rosetta API services using Helm charts. |
| 14 | +- Optionally loads local Docker images for the services. |
| 15 | +- Forwards ports for Prometheus, Grafana, and the Rosetta API services. |
| 16 | + |
| 17 | +## Tools |
| 18 | + |
| 19 | +### Minikube |
| 20 | + |
| 21 | +Minikube is a tool that runs a single-node Kubernetes cluster on your local machine. It is useful for development and testing purposes. |
| 22 | + |
| 23 | +### Prometheus |
| 24 | + |
| 25 | +Prometheus is an open-source monitoring and alerting toolkit. It is used to collect and store metrics from various sources, including applications and infrastructure. |
| 26 | + |
| 27 | +### cAdvisor |
| 28 | + |
| 29 | +cAdvisor (Container Advisor) is an open-source container resource usage and performance analysis agent. It provides insights into the resource usage and performance characteristics of running containers. |
| 30 | + |
| 31 | +### Grafana |
| 32 | + |
| 33 | +Grafana is an open-source platform for monitoring and observability. It provides a web-based interface for visualizing and analyzing metrics collected by Prometheus and other data sources. |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +### Prerequisites |
| 38 | + |
| 39 | +The `deploy.sh` script eventually uses Docker, Minikube, Kubectl and Helm, but fear not, it will assist you in installing those if it detects they are absent. |
| 40 | +It was only tested on Ubuntu servers. |
| 41 | + |
| 42 | +WARNING: The script *doesn't* work when run from this repository's dev container (at `./ci/container/`). |
| 43 | + |
| 44 | +## Deploying Prod Images |
| 45 | + |
| 46 | +To create and set-up the local cluster and install the production containers for ICP-Rosetta and ICRC1-Rosetta pointing at DFINITY's test ledgers, simply do: |
| 47 | +```bash |
| 48 | +./deploy.sh [options] |
| 49 | +``` |
| 50 | + |
| 51 | +You can make the rosetta nodes point to other ledgers by using these flags: |
| 52 | +- `--icp-ledger <ledger_id>`: Set the ICP Ledger ID (default: `xafvr-biaaa-aaaai-aql5q-cai`). If `prod`, will point to the official ICP ledger. |
| 53 | +- `--icp-symbol <symbol>`: Set the ICP token symbol (default: `TESTICP`). |
| 54 | +- `--icrc1-ledger <ledger_id>`: Set the ICRC1 Ledger ID (default: `3jkp5-oyaaa-aaaaj-azwqa-cai`). |
| 55 | + |
| 56 | +ATTENTION: The first run might take a few minutes to finish as it'll create the cluster and install the necessary charts in it. After that, all the script will do is re-deploy the rosetta images with different configuration if needed. |
| 57 | + |
| 58 | +## Deploying Local Images |
| 59 | + |
| 60 | +### Build the local containers |
| 61 | +In order to build rosetta containers with local changes, you need to do it from inside the dev container: |
| 62 | + |
| 63 | +```bash |
| 64 | +$ ./ci/container/container-run.sh |
| 65 | + |
| 66 | +# Build the TAR file target |
| 67 | +$ bazel build //rs/rosetta-api/icp:rosetta_image.tar |
| 68 | + |
| 69 | +# Move the resulting TAR file to a place that can be accessed outside the dev container |
| 70 | +$ mv bazel-bin/rs/rosetta-api/icp/rosetta_image.tar /tmp |
| 71 | + |
| 72 | +# Same for ICRC1 |
| 73 | +$ bazel build //rs/rosetta-api/icrc1:icrc_rosetta_image.tar |
| 74 | +$ mv bazel-bin/rs/rosetta-api/icrc1/icrc_rosetta_image.tar /tmp |
| 75 | + |
| 76 | +# Exit the dev container |
| 77 | +$ exit |
| 78 | +``` |
| 79 | + |
| 80 | +### Deploy the local containers |
| 81 | + |
| 82 | +You can use the following flags to deploy additional containers with the TAR files generated above: |
| 83 | + |
| 84 | +- `--local-icp-image-tar <path>`: Path to local ICP image tar file. |
| 85 | +- `--local-icrc1-image-tar <path>`: Path to local ICRC1 image tar file. |
| 86 | + |
| 87 | +Example that deploys local versions for both: |
| 88 | + |
| 89 | +```bash |
| 90 | +./deploy.sh --local-icp-image-tar /tmp/rosetta_image.tar --local-icrc1-image-tar /tmp/icrc_rosetta_image.tar |
| 91 | +``` |
| 92 | + |
| 93 | +The services and pods deployed with those images will have a `-local` in their names. |
| 94 | + |
| 95 | + |
| 96 | +### Cleaning up |
| 97 | + |
| 98 | +You can add the `--clean` flag to any usage of `./deploy.sh`. That will wipe out the current cluster and install it from scratch. |
| 99 | + |
| 100 | +For example, the following command installs all prod and local images in a clean cluster: |
| 101 | + |
| 102 | +```bash |
| 103 | +./deploy.sh --local-icp-image-tar /tmp/rosetta_image.tar --local-icrc1-image-tar /tmp/icrc_rosetta_image.tar --clean |
| 104 | +``` |
| 105 | + |
| 106 | +## Monitoring with Grafana |
| 107 | + |
| 108 | +Grafana will run on port 3000. If you're running this in a remote devenv, you'll need to forward your local machine port to your devenv's one in order to access the service from your browser. |
| 109 | + |
| 110 | +The first time you open `http://localhost:3000`, you'll be asked for login credentials. Use `admin` for both username and password. You'll be asked to change the password, you can either do so or just skip, it doesn't matter. |
| 111 | + |
| 112 | +Once in Grafana, import a new dashboard. As an option to import, you'll see a text box to input a json file. Copy and paste the contents of the `rosetta_load_dashboard.json` file in this directory. |
| 113 | + |
| 114 | +Services and pods with suffix `-latest` represent jobs running with the prod images while the ones with suffix `-local` are the ones running with the locally built ones. |
| 115 | + |
| 116 | + |
| 117 | +## Notes |
| 118 | +- The script will automatically install Minikube if they are not found. |
| 119 | +- The script uses a dedicated Minikube profile (`local-rosetta`) to avoid conflicts with other Minikube clusters. |
0 commit comments