From 3c9d87d6e9042c740f6ee77686531af0d7c56c88 Mon Sep 17 00:00:00 2001 From: Wietse Wind Date: Sat, 7 Oct 2023 03:25:18 +0200 Subject: [PATCH] Add Docker Compose support --- README.md | 22 +++++++++++ conf/nginx.conf | 96 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 32 ++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 conf/nginx.conf create mode 100644 docker-compose.yml diff --git a/README.md b/README.md index 005ce06..ae034d3 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,28 @@ Based on the work by @RichardAH: https://github.com/RichardAH/xpop-generator ## Run (Docker) +#### Docker Compose + +To run this service & nginx in two separate preconfigured containers, simply run: + +```bash +docker-compose up +``` + +Unless specified otherwise (with environment variables) a connection to XRPL Testnet will be made. + +You will get a container running at port 3000 (unless configured differently), with the following routes: + +- `http://{host}:3000` » Web Browser: homepage with some stats and links +- `http://{host}:3000` » WebSocket: live events on xPOP generated +- `http://{host}:3000/blob` » WebSocket: live events on xPOP generated + HEX XPOP +- `http://{host}:3000/blob/{account}` » WebSocket: live events on xPOP generated + HEX XPOP for specific account +- `http://{host}:3000/xpop/{hash}` » HEX encoded xPOP +- `http://{host}:3000/{networkid}/{...}` » Web Browser Dirlisting & xPOP source files +- `http://{host}:3000/{networkid}/{...}` » Called with `Content-Type: application/json`? JSON dirlisting + + +#### Single Docker Container Run a container with HTTP exposed, for XRPL testnet, auto-remove container after running & interactive (allow for CTRL+C to kill). Docker Hub: https://hub.docker.com/r/wietsewind/xpop diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..8b72027 --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,96 @@ +user nginx; +worker_processes auto; + +error_log /dev/stderr notice; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /dev/stdout main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + # gzip on; + + map $http_connection $connection_upgrade { + "~*Upgrade" $http_connection; + default keep-alive; + } + + map $http_content_type $is_json_request { + "application/json" 1; + default 0; + } + + upstream backend { + server xpop:3000; + keepalive 32; + } + + server { + listen 3000; + server_name _; + + autoindex_format html; + + location /xpop { + root /usr/share/nginx/html; + autoindex off; + } + + if ($http_content_type ~* json) { + set $json_request 1; + } + + location ~ ^/json(/.*)?$ { + internal; + alias /usr/share/nginx/html$1; # Point to the same root as the previous location + autoindex on; + autoindex_format json; + } + + location ~* ^/[0-9]+ { + root /usr/share/nginx/html; + autoindex on; + + if ($is_json_request = 1) { + rewrite ^ /json$request_uri? last; + } + } + + location / { + proxy_pass http://backend; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_cache off; + proxy_buffering off; + # Configuration for LongPolling or if your KeepAliveInterval is longer than 60 seconds + proxy_read_timeout 100s; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + # proxy_set_header X-Forwarded-Proto $scheme; + } + + # error_page 404 /404.html; + # redirect server error pages to the static page /50x.html + # + # error_page 500 502 503 504 /50x.html; + # location = /50x.html { + # root /usr/share/nginx/html; + # } + + } # END: server {} +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5ca8d87 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3.3' +services: + nginx: + container_name: xpopweb + read_only: true + volumes: + - ./conf/nginx.conf:/etc/nginx/nginx.conf:ro + - nginxcache:/var/cache/nginx + - nginxpid:/var/run + - ./store/:/usr/share/nginx/html:ro + ports: + - ${PORT:-3000}:3000 + image: nginx:alpine + xpop: + container_name: xpop + image: xpop:service + build: . + volumes: + - ./store:/usr/src/app/store + environment: + - EVENT_SOCKET_PORT=3000 + - URL_PREFIX=${URL_PREFIX:-http://localhost:3000} + - NETWORKID=${NETWORKID:-1} + - UNLURL=${UNLURL:-https://vl.altnet.rippletest.net} + - UNLKEY=${UNLKEY:-ED264807102805220DA0F312E71FC2C69E1552C9C5790F6C25E3729DEB573D5860} + - NODES=${NODES:-wss://testnet.xrpl-labs.com,wss://s.altnet.rippletest.net:51233} + - FIELDSREQUIRED=${FIELDSREQUIRED:-Fee,Account,OperationLimit} + - NOVALIDATIONLOG=${NOVALIDATIONLOG} + - NOELIGIBLEFULLTXLOG=${NOELIGIBLEFULLTXLOG} +volumes: + nginxcache: + nginxpid: