Skip to content

Commit

Permalink
feat(operator): rollups operator acting on CRD
Browse files Browse the repository at this point in the history
  • Loading branch information
tuler committed Oct 4, 2023
1 parent 68cdea1 commit eef7481
Show file tree
Hide file tree
Showing 22 changed files with 8,042 additions and 189 deletions.
8 changes: 8 additions & 0 deletions .markdownlint-cli2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
config:
list-marker-space:
ul_multi: 3
ul_single: 3
no-duplicate-header:
siblings_only: true
ul-indent:
indent: 4
1 change: 1 addition & 0 deletions packages/rollups-operator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist
62 changes: 62 additions & 0 deletions packages/rollups-operator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Cartesi Rollups Operator

The Cartesi Rollups Operator is a component responsible for launching Cartesi Rollups nodes on a Kubernetes cluster for applications created through the Cartesi Rollups Application CRD.

The Application CRD looks like the following:

```yaml
apiVersion: rollups.cartesi.io/v1
kind: DApp
metadata:
name: dapp-3694c82f
spec:
address: "0x3694c82fde031b8462e90E8Bfee0377De2B01ECc"
blockHash: "0x7afe732e7bd035923c48f60991d019c588496a83b8f7082a5ae5502910395ff0"
blockNumber: "10"
cid: bafybeibdpcfqtcqhgjzmo5wzi3kraxdu6f4wm2hzna4tj2enkepzvldjtq
transactionHash: "0x13c75f9871d0ae6dd2337bc9ae89fad1d16f6b1bd20ca5ccb950aadd5a7232e7"
```
The operator watches those resources changes and creates (or destroys) Kubernetes resources to run a node for that particular application.
## Cluster Setup
The Cartesi rollups nodes need some basic infrastructure that is shared between applications:
- A [postgres](https://www.postgresql.org) database instance
- A [redis](https://redis.com) instance
- A Web3 Gateway ([Infura](https://www.infura.io), [Alchemy](http://alchemy.com), [Chainstack](http://chainstack.com), or any other)
- An Ethereum wallet
### Postgres
Any postgres database provider can be used for Cartesi rollups nodes. If the cloud provider used by validator already provides a managed database system, like [AWS RDS](https://aws.amazon.com/en/rds/) or [Azure Database for PostgreSQL](https://azure.microsoft.com/en-us/products/postgresql), it works just fine.
The only requirement is that the operator needs credentials with permissions to create new databases on demand, because each application uses its own database.
If no managed database is available, another option is to deploy a postgres instance on the cluster using [Helm](https://helm.sh).
```shell
$ helm install postgres oci://registry-1.docker.io/bitnamicharts/postgresql
postgres-postgresql.default.svc.cluster.local
$ export POSTGRES_PASSWORD=$(kubectl get secret --namespace default postgres-postgresql -o jsonpath="{.data.postgres-password}" | base64 -d)
```

### Redis

```shell
$ helm install redis bitnami/redis --wait --set auth.enabled=false --set architecture=standalone --set image.tag=6.2-debian-11
redis-master.default.svc.cluster.local
```

### Wallet

```shell
kubectl create secret generic mnemonic --from-literal=MNEMONIC="test test test test test test test test test test test junk"
```

### Web3 Gateway

## Configuration

## Development
3 changes: 3 additions & 0 deletions packages/rollups-operator/bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\dev" %*
25 changes: 25 additions & 0 deletions packages/rollups-operator/bin/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env node --no-warnings=ExperimentalWarning --loader ts-node/esm

import oclif from "@oclif/core";
import path from "node:path";
import url from "node:url";
import { register } from "ts-node";

// In dev mode -> use ts-node and dev plugins
process.env.NODE_ENV = "development";

const project = path.join(
path.dirname(url.fileURLToPath(import.meta.url)),
"..",
"tsconfig.json"
);
register({ project });

// In dev mode, always show stack traces
oclif.settings.debug = true;

// Start the CLI
oclif
.run(process.argv.slice(2), import.meta.url)
.then(oclif.flush)
.catch(oclif.Errors.handle);
3 changes: 3 additions & 0 deletions packages/rollups-operator/bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
8 changes: 8 additions & 0 deletions packages/rollups-operator/bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env node

import oclif from "@oclif/core";

oclif
.run(process.argv.slice(2), import.meta.url)
.then(oclif.flush)
.catch(oclif.Errors.handle);
19 changes: 19 additions & 0 deletions packages/rollups-operator/config/devnet/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: cartesi-rollups-config
data:
redis: redis://redis-master.default.svc.cluster.local:6379
rpc_url: http://host.docker.internal:8545
rpc_ws_url: ws://host.docker.internal:8545
chain_id: "31337"
epoch_duration: "3600"
confirmations: "1"
contracts.json: |
{
"contracts": {
"Authority": { "address": "0x5050F233F2312B1636eb7CF6c7876D9cC6ac4785" },
"History": { "address": "0x4FF8BD9122b7D91d56Dd5c88FE6891Fb3c0b5281" },
"InputBox": { "address": "0x59b22D57D4f067708AB0c00552767405926dc768" }
}
}
11 changes: 11 additions & 0 deletions packages/rollups-operator/config/devnet/database.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Secret
metadata:
name: cartesi-rollups-database
type: Opaque
data:
database: cG9zdGdyZXM= # base64('postgres')
hostname: cG9zdGdyZXMtcG9zdGdyZXNxbC5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2Fs # base64('postgresql-postgresql.svc.cluster.local')
password: R0J3SlBmT1p5dA== # base64('GBwJPfOZyt')
port: NTQzMg== # base64('5432')
username: cG9zdGdyZXM= # base64('postgres')
7 changes: 7 additions & 0 deletions packages/rollups-operator/config/devnet/mnemonic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: cartesi-rollups-mnemonic
type: Opaque
data:
MNEMONIC: dGVzdCB0ZXN0IHRlc3QgdGVzdCB0ZXN0IHRlc3QgdGVzdCB0ZXN0IHRlc3QgdGVzdCB0ZXN0IGp1bms= # base64('test test test test test test test test test test test junk')
8 changes: 8 additions & 0 deletions packages/rollups-operator/config/traefik/middleware.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: cartesi-rollups-strip-address
spec:
stripPrefixRegex:
regex:
- "/0x[a-fA-F0-9]{40}/"
83 changes: 83 additions & 0 deletions packages/rollups-operator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"name": "@cartesi/rollups-operator",
"version": "0.1.0",
"description": "Cartesi Rollups Operator",
"author": "Danilo Tuler <[email protected]>",
"bin": {
"sunodo": "./bin/run.js"
},
"type": "module",
"homepage": "https://github.com/cartesi/helm-charts",
"license": "Apache-2.0",
"exports": "./dist/index.js",
"repository": "cartesi/helm-charts",
"scripts": {
"build": "run-s clean compile copy-files",
"clean": "rimraf dist",
"compile": "tsc -b",
"copy-files": "copyfiles -u 1 src/**/*.yml dist",
"dev": "bin/dev.js --help",
"lint": "eslint . --ext .ts --config .eslintrc",
"postpack": "rimraf oclif.manifest.json",
"posttest": "yarn lint",
"prepack": "yarn build && oclif manifest && oclif readme",
"test": "vitest",
"version": "run-s prepack"
},
"files": [
"/bin",
"/dist",
"/oclif.manifest.json"
],
"dependencies": {
"@inquirer/prompts": "^3.0",
"@kubernetes/client-node": "^0.18",
"@oclif/core": "^2.11",
"@oclif/plugin-help": "^5.2",
"@oclif/plugin-plugins": "^3.1",
"@oclif/plugin-update": "^3.1",
"async": "^3.2",
"gaxios": "^6.1"
},
"devDependencies": {
"@oclif/test": "^2.3",
"@types/async": "^3.2",
"@types/inquirer": "^9",
"@types/node": "^20",
"@types/node-fetch": "^2.6",
"copyfiles": "^2",
"eslint": "^8",
"eslint-config-custom": "*",
"eslint-config-oclif": "^4",
"eslint-config-oclif-typescript": "^1",
"npm-run-all": "^4",
"oclif": "^3.11",
"rimraf": "^5",
"ts-node": "^10",
"tsconfig": "*",
"tslib": "^2",
"typescript": "^5",
"vitest": "^0.34"
},
"oclif": {
"bin": "cartesi-rollups-operator",
"default": "start",
"dirname": "cartesi",
"commands": "./dist/commands",
"plugins": [
"@oclif/plugin-help"
],
"topicSeparator": " ",
"macos": {
"identifier": "io.cartesi.rollups.operator"
}
},
"engines": {
"node": ">=18.0.0"
},
"bugs": "https://github.com/cartesi/helm-charts/issues",
"keywords": [
"oclif"
],
"types": "dist/index.d.ts"
}
Loading

0 comments on commit eef7481

Please sign in to comment.