Skip to content

Commit

Permalink
Merge pull request #6 from skalenetwork/feature/SKALE-4289-refactor-p…
Browse files Browse the repository at this point in the history
…roxy

SKALE-4289 SKALE Proxy v2
  • Loading branch information
dmytrotkk authored Sep 22, 2022
2 parents 244c620 + 0c922f7 commit 658f6c0
Show file tree
Hide file tree
Showing 38 changed files with 907 additions and 664 deletions.
2 changes: 0 additions & 2 deletions .env-sample

This file was deleted.

3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 100
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,venv,node_modules,helper-scripts
49 changes: 0 additions & 49 deletions .github/workflows/build_docker.yml

This file was deleted.

50 changes: 50 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build and publish
on:
pull_request:
types: [closed]
branches:
- master
- develop
- beta
- stable

jobs:
build:
runs-on: ubuntu-latest
if: github.event.pull_request.merged
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Build and publish container
run: |
export BRANCH=${GITHUB_REF##*/}
export VERSION=$(cat VERSION)
echo "Branch: $BRANCH"
echo "Base version: $VERSION"
export VERSION=$(bash ./helper-scripts/calculate_version.sh)
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Version $VERSION"
export RELEASE=true
echo "RELEASE=$RELEASE" >> $GITHUB_ENV
export CONTAINER_NAME="proxy"
bash ./helper-scripts/build_and_publish.sh
- name: Checkout code
uses: actions/checkout@master
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
draft: false
prerelease: true
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
*.crt
*.key
.env

venv

__pycache__

abi.json
chains.json

conf/upstreams/*.conf
conf/chains/*.conf
6 changes: 5 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[submodule "proxy-ui"]
path = proxy-ui
url = https://github.com/skalenetwork/proxy-ui.git
branch = master
branch = beta
[submodule "helper-scripts"]
path = helper-scripts
url = https://github.com/skalenetwork/helper-scripts.git
branch = develop
39 changes: 9 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
FROM ubuntu:20.04

# Keep upstart from complaining
RUN dpkg-divert --local --rename --add /sbin/initctl
RUN ln -sf /bin/true /sbin/initctl

# Let the conatiner know that there is no tty
ENV DEBIAN_FRONTEND noninteractive
FROM python:3.9-buster

RUN apt-get update
RUN apt-get -y upgrade

# Basic Requirements
RUN apt-get -y install nginx pwgen python3 python3-pip curl git unzip vim

RUN pip3 install web3==5.13.1

# nginx config
RUN sed -i -e"s/keepalive_timeout\s*65/keepalive_timeout 2/" /etc/nginx/nginx.conf
RUN sed -i -e"s/keepalive_timeout 2/keepalive_timeout 2;\n\tclient_max_body_size 100m/" /etc/nginx/nginx.conf
RUN echo "daemon off;" >> /etc/nginx/nginx.conf

# nginx site conf
ADD sample/nginx-site.conf /etc/nginx/sites-available/default
COPY abi /etc/
RUN mkdir /usr/src/proxy /data
WORKDIR /usr/src/proxy

RUN pip3 install web3==5.13.1
COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt

ADD ./endpoints.py /etc/endpoints.py
ADD ./periodic_config_update.py /etc/periodic_config_update.py
ADD ./VERSION /etc/VERSION
COPY . .

# Initialization and Startup Script
ADD ./start.sh /start.sh
RUN chmod 755 /start.sh
ENV PYTHONPATH="/usr/src/proxy"
ENV COLUMNS=80

CMD ["/bin/bash", "/start.sh"]
CMD python /usr/src/proxy/proxy/main.py
45 changes: 26 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
# skale-proxy
# SKALE Proxy

skale-proxy is a public service that provides proxied and load-balanced JSON-RPC endpoints for SKALE chains
[![Discord](https://img.shields.io/discord/534485763354787851.svg)](https://discord.gg/vvUtWJB)

SKALE Proxy is high performance, easy-to-run public service that provides proxied and load-balanced
JSON-RPC endpoints for SKALE chains. It is based on NGINX.

# running
## Usage guide

### Prerequisites

1. Place you ABI json file into abi directory
- Docker
- docker-compose

2. Set 'ABI_FILENAME directory' in docker-compose.yml to the name of the ABI file.

3. Set 'PROXY_FULL_HOST_NAME' in docker-compose.yml to the domain name of your proxy.
### Repo setup

4. Set 'ENDPOINT_PREFIX' in 'docker-compose.yml' to the endpoint prefix (must be non-empty!)
1. Clone repo & all submodules
2. Put `abi.json`, `server.crt` and `server.key`files in `data` folder
3. Export all required environement variables (see below)
4. Run `scripts/run_proxy.sh`

5. Set 'ETH_ENDPOINT' in docker-compose to your ETH main net endpoint.
#### Required environement variables

6. Create 'data' directory and copy 'server.crt' and 'server.key' to it.
The certificate need to be issued to 'PROXY_FULL_HOST_NAME'.
- `NETWORKS`
- `DOCS_WEBSITE_URL`
- `MAIN_WEBSITE_URL`
- `NETWORK_NAME`
- `CHAIN_ID`
- `EXPLORER_URL`
- `BASE_PROXY_URL`
- `ETH_ENDPOINT`


7. Run 'docker-compose pull && docker-compose up' andf wait around a minute until skale-proxy reads schain info from blockchain and starts.
## License

8. Try 'http://PROXY_FULL_HOST_NAME/api.json' . You should be able to see API descriptions.
[![License](https://img.shields.io/github/license/skalenetwork/skale-proxy.svg)](LICENSE)

Voila!

# local development

Set `FULL_PROXY_DOMAIN_NAME` to localhost and run `cert_gen.sh`. This will generate a self-signed cert in the `data/` directory.
All contributions to SKALE Proxy are made under the [GNU Affero General Public License v3](https://www.gnu.org/licenses/agpl-3.0.en.html). See [LICENSE](LICENSE).

Copyright (C) 2022-Present SKALE Labs.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.77.1
2.0.0
40 changes: 40 additions & 0 deletions config/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
events {
worker_connections 100000;
}

http {

limit_req_zone $binary_remote_addr zone=one:10m rate=15r/s;
client_max_body_size 5M;

server {
listen 80;
listen 443 ssl;
ssl_certificate /data/server.crt;
ssl_certificate_key /data/server.key;
server_name _;

limit_req zone=one burst=100;

proxy_read_timeout 500s;
proxy_connect_timeout 500s;
proxy_send_timeout 500s;

location / {
proxy_http_version 1.1;
proxy_pass http://proxy-ui:5001/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

location /files/ {
root /usr/share/nginx/www;
}

include /etc/nginx/conf/chains/*.conf;
}

include /etc/nginx/conf/upstreams/*.conf;
}
31 changes: 20 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,40 @@ version: '3'
services:
proxy-ui:
image: proxy-ui:latest
container_name: proxy_ui
build:
context: ./proxy-ui
dockerfile: Dockerfile
ports:
- "5000:5000"
- "5001:5001"
skale-proxy:
environment:
PROXY_FULL_HOST_NAME: ${PROXY_FULL_HOST_NAME}
ETH_ENDPOINT: ${ENDPOINT}
ENDPOINT_PREFIX: mainnet
ABI_FILENAME: abi.json
SERVER_NAME: ${SERVER_NAME}
ETH_ENDPOINT: ${ETH_ENDPOINT}
image: skale-proxy:latest
container_name: proxy_admin
build:
context: .
dockerfile: Dockerfile
ports:
- "80:80"
- "443:443"
volumes:
- /dev/urandom:/dev/random
- ./data:/data
- ./data:/usr/src/proxy/data
- ./www:/usr/src/proxy/www
- ./conf:/usr/src/proxy/conf/
- /var/run/docker.sock:/var/run/docker.sock
logging:
driver: json-file
options:
max-size: "10m"
max-file: "4"
restart: unless-stopped

nginx:
image: nginx:1.20.2
container_name: proxy_nginx
ports:
- "80:80"
- "443:443"
volumes:
- ./data:/data
- ./www:/usr/share/nginx/www/files
- ./config/nginx.conf:/etc/nginx/nginx.conf:ro
- ./conf:/etc/nginx/conf/
Loading

0 comments on commit 658f6c0

Please sign in to comment.