Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

removing rmbProxy endpoints, RMB, Ygg, and Redis #292

Merged
merged 10 commits into from
Feb 28, 2023
Merged
26 changes: 3 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,50 +1,30 @@
FROM docker.io/golang:alpine as builder

ARG YGG_VERSION=v0.4.7
ENV CGO_ENABLED=0

WORKDIR /src

RUN apk add git

RUN git clone --depth 1 --branch $YGG_VERSION https://github.com/yggdrasil-network/yggdrasil-go.git .
RUN ./build && go build -o /src/genkeys cmd/genkeys/main.go

RUN git clone https://github.com/threefoldtech/tfgridclient_proxy && cd tfgridclient_proxy/cmds/proxy_server &&\
CGO_ENABLED=0 GOOS=linux go build -ldflags "-w -s -X main.GitCommit=$(git describe --tags --abbrev=0) -extldflags '-static'" -o server &&\
chmod +x server

RUN git clone https://github.com/threefoldtech/rmb_go && cd rmb_go/cmds/msgbusd &&\
CGO_ENABLED=0 GOOS=linux go build -ldflags '-w -s -extldflags "-static"' -o msgbusd &&\
chmod +x msgbusd
CGO_ENABLED=0 GOOS=linux go build -ldflags "-w -s -X main.GitCommit=$(git describe --tags --abbrev=0) -extldflags '-static'" -o gridrest &&\
chmod +x gridrest

FROM alpine:3.14

RUN apk --update add redis

COPY --from=builder /src/yggdrasil /usr/bin/yggdrasil
COPY --from=builder /src/yggdrasilctl /usr/bin/yggdrasilctl
COPY --from=builder /src/genkeys /usr/bin/genkeys
COPY --from=builder /src/tfgridclient_proxy/cmds/proxy_server/server /usr/bin/server
COPY --from=builder /src/rmb_go/cmds/msgbusd/msgbusd /usr/bin/msgbusd
COPY --from=builder /src/tfgridclient_proxy/cmds/proxy_server/gridrest /usr/bin/gridrest

RUN wget https://github.com/threefoldtech/zinit/releases/download/v0.2.10/zinit -O /sbin/zinit \
&& chmod +x /sbin/zinit

COPY ygg_entrypoint.sh /etc/ygg_entrypoint.sh
RUN chmod +x /etc/ygg_entrypoint.sh
COPY rootfs /

ENV MNEMONICS=""
ENV SERVER_PORT=":443"
ENV POSTGRES_HOST="postgres"
ENV POSTGRES_PORT="5432"
ENV POSTGRES_DB="name"
ENV POSTGRES_USER="postgres"
ENV POSTGRES_PASSWORD="123"
ENV SUBSTRATE="wss://tfchain.dev.grid.tf/ws"
ENV REDIS="tcp://127.0.0.1:6379"
ENV RMB_TIMEOUT="30"

EXPOSE 443 8051
ENTRYPOINT [ "zinit", "init" ]
85 changes: 34 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ To list all the available tasks for running:

## Prerequisites

1. A [msgbusd](https://github.com/threefoldtech/rmb_go) instance must be running on the node. This client uses RMB (message bus) to send messages to nodes, and get the responses.
2. A valid MNEMONICS.
3. [yggdrasil](https://yggdrasil-network.github.io/installation.html) service running with a valid ip assigned to the MNEMONICS on [polkadot](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Ftfchain.dev.grid.tf%2Fws#/accounts).
4. Golang compiler > 1.13 to run the grid proxy server.
5. Postgres database
1. If you need to compile the server from source code you will need Golang compiler > 1.13, otherwise you can just download the compiled binaries from github [releases](https://github.com/threefoldtech/tfgridclient_proxy/releases).
2. Postgres connection string

## Generate swagger doc files

Expand All @@ -52,43 +49,8 @@ To list all the available tasks for running:
cd cmds/proxy_server && CGO_ENABLED=0 GOOS=linux go build -ldflags "-w -s -X main.GitCommit=$GIT_COMMIT -extldflags '-static'" -o server
```

## Development Run

- Start the msgbus with your MNEMONICS ID
```sh
msgbusd --mnemonics "YOUR MNEMONICS" --substrate "wss://tfchain.dev.grid.tf"
```
- To run in development envornimnet see [here](tools/db/README.md) how to generate test db or load a db dump then use:
```sh
go run cmds/proxy_server/main.go --address :8080 --log-level debug -no-cert --postgres-host 127.0.0.1 --postgres-db tfgrid-graphql --postgres-password postgres --postgres-user postgres
```
- all server Options:

| Option | Description |
| --- | --- |
| -address | Server ip address (default `":443"`) |
| -ca | certificate authority used to generate certificate (default `"https://acme-staging-v02.api.letsencrypt.org/directory"`) |
| -cert-cache-dir | path to store generated certs in (default `"/tmp/certs"`) |
| -domain | domain on which the server will be served |
| -email | email address to generate certificate with |
| -log-level | log level `[debug\|info\|warn\|error\|fatal\|panic]` (default `"info"`) |
| -no-cert | start the server without certificate |
| -postgres-db | postgres database |
| -postgres-host | postgres host |
| -postgres-password | postgres password |
| -postgres-port | postgres port (default 5432) |
| -postgres-user | postgres username |
| -redis | redis url (default `"tcp://127.0.0.1:6379"`) |
| -substrate-user | substrate url (default`"wss://tfchain.dev.grid.tf/ws"`) |
| -rmb-timeout | timeout for rmb requests (default `30` seconds) |
| -v | shows the package version |


- Then visit `http://localhost:8080/<endpoint>`

## Production Run
sameh-farouk marked this conversation as resolved.
Show resolved Hide resolved

- Start the msgbus systemd service with a machine MNEMONICS linked to its yggdrasil IP or public ip if there, [download and more info](https://github.com/threefoldtech/go-rmb)
- Download the latest binary [here](https://github.com/threefoldtech/tfgridclient_proxy/releases)
- add the execution permission to the binary and move it to the bin directory

Expand All @@ -105,10 +67,9 @@ cat << EOF > /etc/systemd/system/gridproxy-server.service
[Unit]
Description=grid proxy server
After=network.target
After=msgbus.service

[Service]
ExecStart=gridproxy-server --domain gridproxy.dev.grid.tf --email omar.elawady.alternative@gmail.com -ca https://acme-v02.api.letsencrypt.org/directory --substrate wss://tfchain.dev.grid.tf/ws --postgres-host 127.0.0.1 --postgres-db db --postgres-password password --postgres-user postgres
ExecStart=gridproxy-server --domain gridproxy.dev.grid.tf --email omar.elawady.alternative@gmail.com -ca https://acme-v02.api.letsencrypt.org/directory --postgres-host 127.0.0.1 --postgres-db db --postgres-password password --postgres-user postgres
Type=simple
Restart=always
User=root
Expand Down Expand Up @@ -141,8 +102,9 @@ EOF
- The command options:
- domain: the host domain which will generate ssl certificate to.
- email: the mail used to run generate the ssl certificate.
- ca: certificate authority server url
- substrate: substrate websocket link.
- ca: certificate authority server url, e.g.
- let's encrypt staging: `https://acme-staging-v02.api.letsencrypt.org/directory`
- let's encrypt production: `https://acme-v02.api.letsencrypt.org/directory`
- postgre-\*: postgres connection info.

## To upgrade the machine
Expand All @@ -159,21 +121,42 @@ systemctl restart gridproxy-server.service
systemctl daemon-reload
```

## Dockerfile
## Development Run

- To run in development envornimnet see [here](tools/db/README.md) how to generate test db or load a db dump then use:
```sh
go run cmds/proxy_server/main.go --address :8080 --log-level debug -no-cert --postgres-host 127.0.0.1 --postgres-db tfgrid-graphql --postgres-password postgres --postgres-user postgres
```
- all server Options:

| Option | Description |
| --- | --- |
| -address | Server ip address (default `":443"`) |
| -ca | certificate authority used to generate certificate (default `"https://acme-v02.api.letsencrypt.org/directory"`) |
| -cert-cache-dir | path to store generated certs in (default `"/tmp/certs"`) |
| -domain | domain on which the server will be served |
| -email | email address to generate certificate with |
| -log-level | log level `[debug\|info\|warn\|error\|fatal\|panic]` (default `"info"`) |
| -no-cert | start the server without certificate |
| -postgres-db | postgres database |
| -postgres-host | postgres host |
| -postgres-password | postgres password |
| -postgres-port | postgres port (default 5432) |
| -postgres-user | postgres username |
| -v | shows the package version |

- get public and private key for a yggdrasil configuration

- Then visit `http://localhost:8080/<endpoint>`

## Dockerfile

To build & run dockerfile

```bash
docker build -t threefoldtech/gridproxy .
docker run --name gridproxy -e MNEMONICS="" -e SUBSTRATE="wss://tfchain.dev.grid.tf/ws" -e PUBLIC_KEY="5011157c2451b238c99247b9f0793f66e5b77998272c00676d23767fe3d576d8" -e PRIVATE_KEY="ff5b3012dbec23e86e2fde7dcd3c951781e87fe505be225488b50a6bb27662f75011157c2451b238c99247b9f0793f66e5b77998272c00676d23767fe3d576d8" -e POSTGRES_HOST="127.0.0.1" -e POSTGRES_PORT="5432" -e POSTGRES_DB="db" -e POSTGRES_USER="postgres" -e POSTGRES_PASSWORD="password" -e RMB_TIMEOUT="30" --cap-add=NET_ADMIN threefoldtech/gridproxy
docker run --name gridproxy -e POSTGRES_HOST="127.0.0.1" -e POSTGRES_PORT="5432" -e POSTGRES_DB="db" -e POSTGRES_USER="postgres" -e POSTGRES_PASSWORD="password" threefoldtech/gridproxy
```

- PUBLIC_KEY: yggdrasil public key
- PRIVATE_KEY: yggdrasil private key
- PEERS: yggdrasil peers

## Update helm package

- Do `helm lint charts/gridproxy`
Expand Down
20 changes: 5 additions & 15 deletions charts/gridproxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

- `Helm repo update`

- get public and private key for a yggdrasil configuration, **note**: each setup should has it's own public key and private key and not to be shared with anyone

`yggdrasil -genconf -json > yggdrasil.conf`

see [here](https://yggdrasil-network.github.io/configuration.html) and example file `ygg_sample.conf`

- Remove traefik controller & service and Install nginx controller and cert manager (if not there)

for nginx:
Expand All @@ -30,17 +24,13 @@

- Apply certificate `kubectl create -f prod_issuer.yaml`

- If you want to add more peers add using `--set env.PEERS=" tls:\\\/\\\/62.210.85.80:39575\\\n tls:\\\/\\\/54.37.137.221:11129\\\n"` add `\\\` as escape characters before each `/`

- Install the chart

**Note**: EXPLORER_URL, SERVER_IP and REDIS_URL has default values you may not pass them if you want to use the defaults
**Note**: these envs has default values you may not pass them if you want to use the defaults
- SERVER_PORT: Addr optionally specifies the TCP address for the server to listen on, in the form "host:port". default `:80`
- POSTGRES_PORT: default `5432`
- POSTGRES_USER: default `postgres`

```bash
helm install -f values.yaml gridproxy . --set ingress.host="gridproxy.3botmain.grid.tf" --set env.MNEMONICS="" --set env.SUBSTRATE="wss://tfchain.dev.grid.tf/ws" --set env.PUBLIC_KEY="5011157c2451b238c99247b9f0793f66e5b77998272c00676d23767fe3d576d8" --set env.PRIVATE_KEY="ff5b3012dbec23e86e2fde7dcd3c951781e87fe505be225488b50a6bb27662f75011157c2451b238c99247b9f0793f66e5b77998272c00676d23767fe3d576d8" --set env.PEERS=" tls:\\\/\\\/62.210.85.80:39575\\\n tls:\\\/\\\/54.37.137.221:11129\\\n" --set env.POSTGRES_HOST="127.0.0.1" --set env.POSTGRES_PORT="5432" --set env.POSTGRES_DB="db" --set env.POSTGRES_USER="postgres" --set env.POSTGRES_PASSWORD="password" --set env.RMB_TIMEOUT="30"
helm install -f values.yaml gridproxy . --set ingress.host="gridproxy.dev.grid.tf" --set env.POSTGRES_HOST="127.0.0.1" --set env.POSTGRES_PORT="5432" --set env.POSTGRES_DB="db" --set env.POSTGRES_USER="postgres" --set env.POSTGRES_PASSWORD="password"
```

- PUBLIC_KEY: yggdrasil public key
- PRIVATE_KEY: yggdrasil private key
- PEERS: yggdrasil peers, get from [here](https://publicpeers.neilalexander.dev/)
- SUBSTRATE: substrate url
15 changes: 0 additions & 15 deletions charts/gridproxy/templates/service-rmb.yaml

This file was deleted.

16 changes: 0 additions & 16 deletions charts/gridproxy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,8 @@ image:
# tag: "v1.7.0-rc1"

env:
- name: "MNEMONICS"
value: ""
- name: "SERVER_PORT"
value: ""
- name: "EXPLORER"
value: ""
- name: "SUBSTRATE"
value: ""
- name: "REDIS"
value: ""
- name: "PUBLIC_KEY"
value: ""
- name: "PRIVATE_KEY"
value: ""
- name: "PEERS"
value: ""
- name: "POSTGRES_HOST"
value: "postgres"
- name: "POSTGRES_PORT"
Expand All @@ -38,8 +24,6 @@ image:
value: "postgres"
- name: "POSTGRES_PASSWORD"
value: "123"
- name: "RMB_TIMEOUT"
value: "30"

imagePullSecrets: []
nameOverride: ""
Expand Down
Loading