Skip to content

Commit

Permalink
feat: Draft working prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega committed Jan 17, 2022
1 parent b46ba7e commit 27622a1
Show file tree
Hide file tree
Showing 31 changed files with 7,027 additions and 1 deletion.
Empty file added .github/workflows/ci.yml
Empty file.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.DS_Store
48 changes: 47 additions & 1 deletion README.md
@@ -1,2 +1,48 @@
# cip25-search-engine
# CIP-25 Search Engine

A reference app that uses Oura + Elasticsearch + React to buid a Cardano CIP-25 search engine

## Introduction

This is a reference app to show how _Oura_ can be leveradged to build a search engine for CIP-25 tokens.

The frontend is built using React and Remix.

The backend is a combination of a Cardano node, Oura and Elasticsearch.

Everthing is deployed together using Kubernetes

If I missed any buzzwords, let me know :)

## Deployment

Prerequisites

- K8s Cluster
- Skaffold

Install operator

```
kubectl create -f https://download.elastic.co/downloads/eck/1.9.1/crds.yaml
kubectl apply -f https://download.elastic.co/downloads/eck/1.9.1/operator.yaml
```

Build & Deploy

```
skaffold dev
```

Setup Index Template

```
export ELASTIC_AUTH=user:pass
cd scripts && ./setup-index.sh
```

## Dev

```
skaffold dev --default-repo ghcr.io/txpipe --namespace cip25 --module web --cleanup=false
```
41 changes: 41 additions & 0 deletions k8s/elastic.yaml
@@ -0,0 +1,41 @@
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: sink
spec:
version: 7.16.1
nodeSets:
- name: default
count: 1
volumeClaimTemplates:
- metadata:
name: elasticsearch-data # Do not change this name unless you set up a volume mount for the data path.
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
podTemplate:
spec:
containers:
- name: elasticsearch
env:
- name: ES_JAVA_OPTS
value: -Xms2g -Xmx2g
resources:
requests:
memory: 4Gi
cpu: 1
limits:
memory: 4Gi
---
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
name: sink
spec:
version: 7.16.1
count: 1
elasticsearchRef:
name: sink
78 changes: 78 additions & 0 deletions k8s/oura.yaml
@@ -0,0 +1,78 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: oura
data:
daemon.toml: |-
[source]
type = "N2N"
address = ["Tcp", "relays-new.cardano-mainnet.iohk.io:3001"]
magic = "mainnet"
#since = [26785934, "92d994d49e93b1b4c47383647bd71a965371976d33e84a74a91eae0a3c47b45d"]
#since = [29100429, "8a4f144f0b195522b9d5f7a4c798611cca6e0313c8bd1a01e17386d92bec41be"]
since = [47494387, "8741e7ef3c24c1940df89930bce63a2cb2471a3efdf9ae7957c63c5d5170011e"]
[[filters]]
type = "Fingerprint"
[[filters]]
type = "Selection"
[filters.check]
predicate = "variant_in"
argument = ["CIP25Asset"]
[sink]
type = "Elastic"
url = "https://sink-es-http:9200"
index = "oura.sink.cip25assets"
idempotency = true
[sink.credentials]
type = "Basic"
username = "elastic"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: oura
labels:
app: oura
spec:
replicas: 1
selector:
matchLabels:
app: oura
template:
metadata:
labels:
app: oura
spec:
containers:
- name: main
image: ghcr.io/txpipe/oura:v1.0.0
env:
- name: "RUST_LOG"
value: "info"
- name: "OURA_SINK_CREDENTIALS_PASSWORD"
valueFrom:
secretKeyRef:
key: elastic
name: sink-es-elastic-user
resources:
requests:
memory: 100Mi
cpu: 50m
limits:
memory: 500Mi
cpu: 200m
args:
- "daemon"
volumeMounts:
- mountPath: /etc/oura
name: oura-config
volumes:
- name: oura-config
configMap:
name: oura
29 changes: 29 additions & 0 deletions k8s/web.yaml
@@ -0,0 +1,29 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
labels:
app: web
spec:
replicas: 1
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: main
image: web
env:
- name: "RUST_LOG"
value: "info"
resources:
requests:
memory: 100Mi
cpu: 50m
limits:
memory: 500Mi
cpu: 200m
79 changes: 79 additions & 0 deletions scripts/index-template.json
@@ -0,0 +1,79 @@
{
"template": {
"mappings": {
"properties": {
"@timestamp": {
"type": "date"
},
"context": {
"properties": {
"block_number": {
"type": "long"
},
"block_hash": {
"type": "keyword"
},
"input_idx": {
"type": "long"
},
"output_idx": {
"type": "long"
},
"certificate_idx": {
"type": "long"
},
"slot": {
"type": "long"
},
"timestamp": {
"type": "long"
},
"tx_hash": {
"type": "keyword"
},
"tx_idx": {
"type": "long"
}
}
},
"cip25_asset": {
"properties": {
"policy": {
"type": "keyword"
},
"asset": {
"type": "keyword"
},
"name": {
"type": "text"
},
"mediatType": {
"type": "keyword"
},
"image": {
"type": "keyword"
},
"description": {
"type": "text"
},
"raw_json": {
"enabled": false
}
}
},
"fingerprint": {
"type": "keyword",
"ignore_above": 256
},
"variant": {
"type": "keyword",
"ignore_above": 256
}
}
}
},
"data_stream": {},
"index_patterns": [
"oura.sink.cip25"
]
}
4 changes: 4 additions & 0 deletions scripts/setup-index.sh
@@ -0,0 +1,4 @@
curl -k -X PUT https://localhost:9200/_index_template/oura.sink.cip25 \
-u ${ELASTIC_AUTH} \
-H 'Content-Type: application/json' \
-d @index-template.json
40 changes: 40 additions & 0 deletions skaffold.yaml
@@ -0,0 +1,40 @@
apiVersion: skaffold/v2beta26
kind: Config
metadata:
name: elastic
deploy:
kubectl:
manifests:
- k8s/elastic.yaml
---
apiVersion: skaffold/v2beta26
kind: Config
metadata:
name: oura
requires:
- configs: [elastic]
deploy:
kubectl:
manifests:
- k8s/oura.yaml
---
apiVersion: skaffold/v2beta26
kind: Config
metadata:
name: web
requires:
- configs: [elastic, oura]
build:
artifacts:
- image: web
context: web
deploy:
kubectl:
manifests:
- k8s/web.yaml
portForward:
- resourceType: deployment
resourceName: web
port: 3000
localPort: 3000

6 changes: 6 additions & 0 deletions web/.gitignore
@@ -0,0 +1,6 @@
node_modules

/.cache
/build
/public/build
.env
16 changes: 16 additions & 0 deletions web/Dockerfile
@@ -0,0 +1,16 @@
FROM node:14-alpine AS build

WORKDIR /code

COPY ./package.json ./package.json
COPY ./package-lock.json ./package-lock.json

RUN npm install --loglevel warn

COPY . ./

RUN npm run build

EXPOSE 3000

CMD ["npm", "start"]

0 comments on commit 27622a1

Please sign in to comment.