diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..74b81af --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM nginx + +# https://github.com/jetbrains-infra/docker-nginx-resolver +ADD entrypoint.sh /entrypoint.sh +CMD ["nginx", "-g", "daemon off;"] +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 74816aa..0388d04 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,13 @@ Directory structure ├── mango-vial - WEBSOCKET API Service for L1, L2 orderbook data for mango markets version 3 └── py - python3 client for above REST API Service ``` + +# How to run +* `docker-compose up` starts the REST API Service and the WEBSOCKET API Service, and a ngninx reverse proxy +* The REST API is then available e.g. `curl http://localhost/api/wallet/balances` +* the WEBSOCKET API is then available e.g.`wscat --connect ws://localhost/ws` (note by default the websocket program when run in isolation is available at `ws://localhost/v1/ws` ) + + # Todos losely sorted in order of importance/priority - rpc node related issues diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fc5dd18 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: "3.9" +services: + mango-service-v3: + build: mango-service-v3 + ports: + - "3000:3000" + volumes: + - ~/.config/solana:/root/.config/solana # mount volume where keys are present, also see PRIVATE_KEY_PATH + environment: + - PORT=3000 + - GROUP_NAME=mainnet.1 + - CLUSTER_URL=${CLUSTER_URL} # configure custom RPC node + - PRIVATE_KEY_PATH=/root/.config/solana/id.json # configure path to private keypair here + mango-vial: + build: "mango-vial" + ports: + - "8000:8000" + environment: + - MV_PORT=8000 + - MV_ENDPOINT=${CLUSTER_URL} # configure custom RPC node + reverse-proxy: + build: . + ports: + - "80:80" + volumes: + - ./nginx.conf/:/etc/nginx/nginx.conf # custom config which unifies mango-service-v3 and mango-vial \ No newline at end of file diff --git a/docker.env b/docker.env new file mode 100644 index 0000000..7846195 --- /dev/null +++ b/docker.env @@ -0,0 +1 @@ +CLUSTER_URL=https://api.mainnet-beta.solana.com \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..5c30ee8 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +# https://github.com/jetbrains-infra/docker-nginx-resolver +export DOLLAR='$' +mkdir -p /etc/nginx/includes/ +echo resolver $(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf) ";" > /etc/nginx/includes/resolver.conf +exec "$@" \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..b29ed76 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,46 @@ +error_log /dev/stdout info; + +events {} + +http { + # https://github.com/jetbrains-infra/docker-nginx-resolver + include /etc/nginx/includes/resolver.conf; + + # https://www.nginx.com/blog/websocket-nginx/ + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; + } + + upstream rest-api { + server mango-service-v3:3000; + } + + upstream ws-api { + server mango-vial:8000; + } + + server { + access_log /dev/stdout; + + listen 80; + + # https://localhost/api + location /api/ { + set $backend_api "http://rest-api/api/"; + if ($request_uri ~* "/api/(.*$)") { + set $path_remainder $1; + } + proxy_pass $backend_api$path_remainder; + } + + # ws://localhost/ws + location /ws { + proxy_pass http://ws-api/v1/ws; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Host $host; + } + } +} \ No newline at end of file