From 3f49de675e25dc1e848b902968b97f5b5af321e8 Mon Sep 17 00:00:00 2001 From: Fabio Rigamonti <73019897+fabiorigam@users.noreply.github.com> Date: Thu, 6 Jun 2024 10:15:21 +0200 Subject: [PATCH] Add docker for RPC Proxy (#958) * feat: add docker option to RPC Proxy * fix: update README.md --- docs/README.md | 4 +-- packages/rpc-proxy/.dockerignore | 3 ++ packages/rpc-proxy/Dockerfile | 17 ++++++++++ packages/rpc-proxy/README.md | 29 ++++++++++++++--- packages/rpc-proxy/package.json | 8 +++-- yarn.lock | 56 +++++++++++++++++++++++++++++++- 6 files changed, 106 insertions(+), 11 deletions(-) create mode 100644 packages/rpc-proxy/.dockerignore create mode 100644 packages/rpc-proxy/Dockerfile diff --git a/docs/README.md b/docs/README.md index 5c624ae82..548c777da 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ -#VeChain SDK +# VeChain SDK -Welcome to the official documentation for the JavaScriptVeChain SDK! +Welcome to the official documentation for the JavaScript VeChain SDK! This SDK provides developers with tools and resources to integrate VeChain blockchain functionality into their applications with ease. Whether you're building decentralized applications (dApps), managing digital assets, or exploring blockchain-based solutions, this SDK offers a comprehensive set of features to interact with the VeChainThor blockchain. diff --git a/packages/rpc-proxy/.dockerignore b/packages/rpc-proxy/.dockerignore new file mode 100644 index 000000000..620352743 --- /dev/null +++ b/packages/rpc-proxy/.dockerignore @@ -0,0 +1,3 @@ +node_modules +Dockerfile +dist \ No newline at end of file diff --git a/packages/rpc-proxy/Dockerfile b/packages/rpc-proxy/Dockerfile new file mode 100644 index 000000000..ec8ae8302 --- /dev/null +++ b/packages/rpc-proxy/Dockerfile @@ -0,0 +1,17 @@ +# Use the official Node.js image as the base image +FROM node:18-alpine + +# Set the working directory in the container +WORKDIR /app + +# Copy the dependencies file to the working directory +COPY ./ /app + +# Install all the dependencies +RUN yarn install + +# Build the app +RUN yarn build + +# Serve the app +ENTRYPOINT ["yarn", "start"] \ No newline at end of file diff --git a/packages/rpc-proxy/README.md b/packages/rpc-proxy/README.md index a794a6565..abadafc6e 100644 --- a/packages/rpc-proxy/README.md +++ b/packages/rpc-proxy/README.md @@ -3,17 +3,25 @@ Welcome to the **RPC Proxy** of the VeChain SDK! ## Introduction -This project is designed to bridge the gap between Thor's RESTful API and Ethereum's JSON-RPC, for example to support the Remix IDE. By leveraging this proxy, users can seamlessly interact with the VeChainThor blockchain via RPC calls. -# Usage +The RPC Proxy is designed to bridge the gap between Thor's RESTful API and Ethereum's JSON-RPC, enabling seamless interaction with the VeChainThor blockchain through RPC calls. It is particularly useful for integrating with tools such as the Remix IDE. -The RPC proxy is very simple to use. To run it: +## Installation + +To install the RPC proxy, use the following command: ``` bash yarn add @vechain/sdk-rpc-proxy rpc-proxy ``` -By default the Proxy is configured to be used with a solo node running in your local machine. If you want to change the default behaviour, simply create a `config.json` file and pass it to the command when launching the RPC Proxy: +## Usage + +The RPC proxy is simple to use. To start it, run: +``` bash +rpc-proxy +``` + +By default, the proxy is configured to be used with a solo node running on your local machine. If you want to change the default behavior, create a config.json file and pass it to the command when launching the RPC Proxy: ``` bash rpc-proxy -c ``` @@ -22,6 +30,16 @@ Or: rpc-proxy --config ``` +# Run as Docker Container + +To run the RPC proxy as a Docker container, follow these steps: +``` bash +docker build . -t vechain-rpc-proxy +docker run -d -p 8545:8545 -v ./config.json:/app/config.json -t vechain-rpc-proxy +``` + +If you do not pass a config.json file, the default solo network standard configuration will be used. Make sure to provide your desired configuration file. + ## Configuration The `config.json` file is used to configure the proxy server. It contains the following fields: @@ -33,7 +51,8 @@ The `config.json` file is used to configure the proxy server. It contains the fo - `debug`: Whether to enable debug mode. - `enableDelegation`: Whether to enable delegation. -As an example: +### Example Configuration + ``` json { "url": "http://127.0.0.1:8669", diff --git a/packages/rpc-proxy/package.json b/packages/rpc-proxy/package.json index fa2f5da30..3d29eabf5 100644 --- a/packages/rpc-proxy/package.json +++ b/packages/rpc-proxy/package.json @@ -34,15 +34,17 @@ "start": "node dist/index.js" }, "dependencies": { - "@vechain/sdk-network": "1.0.0-beta.14", "@vechain/sdk-logging": "1.0.0-beta.14", + "@vechain/sdk-network": "1.0.0-beta.14", "commander": "^12.1.0", "cors": "^2.8.5", - "express": "^4.19.2" + "express": "^4.19.2", + "tsup": "^8.1.0", + "typescript": "^5.4.5" }, "devDependencies": { "@types/cors": "^2.8.17", "@types/express": "^4.17.21", "@types/node": "^20.14.1" } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index e8c7572e0..d60018c76 100644 --- a/yarn.lock +++ b/yarn.lock @@ -798,6 +798,11 @@ resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.21.4.tgz#11ef0398f9abee161193461910a507ef0d4c0c32" integrity sha512-sywLRD3UK/qRJt0oBwdpYLBibk7KiRfbswmWRDabuncQYSlf8aLEEUor/oP6KRz8KEG+HoiVLBhPRD5JWjS8Sg== +"@esbuild/win32-x64@0.21.4": + version "0.21.4" + resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.21.4.tgz#11ef0398f9abee161193461910a507ef0d4c0c32" + integrity sha512-sywLRD3UK/qRJt0oBwdpYLBibk7KiRfbswmWRDabuncQYSlf8aLEEUor/oP6KRz8KEG+HoiVLBhPRD5JWjS8Sg== + "@eslint-community/eslint-utils@^4.1.2", "@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0": version "4.4.0" resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz#a23514e8fb9af1269d5f7788aa556798d61c6b59" @@ -3528,6 +3533,35 @@ esbuild@^0.21.4: "@esbuild/win32-ia32" "0.21.4" "@esbuild/win32-x64" "0.21.4" +esbuild@^0.21.4: + version "0.21.4" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.21.4.tgz#ceb501def8edb12a5bfd9c55f3a96db698edf022" + integrity sha512-sFMcNNrj+Q0ZDolrp5pDhH0nRPN9hLIM3fRPwgbLYJeSHHgnXSnbV3xYgSVuOeLWH9c73VwmEverVzupIv5xuA== + optionalDependencies: + "@esbuild/aix-ppc64" "0.21.4" + "@esbuild/android-arm" "0.21.4" + "@esbuild/android-arm64" "0.21.4" + "@esbuild/android-x64" "0.21.4" + "@esbuild/darwin-arm64" "0.21.4" + "@esbuild/darwin-x64" "0.21.4" + "@esbuild/freebsd-arm64" "0.21.4" + "@esbuild/freebsd-x64" "0.21.4" + "@esbuild/linux-arm" "0.21.4" + "@esbuild/linux-arm64" "0.21.4" + "@esbuild/linux-ia32" "0.21.4" + "@esbuild/linux-loong64" "0.21.4" + "@esbuild/linux-mips64el" "0.21.4" + "@esbuild/linux-ppc64" "0.21.4" + "@esbuild/linux-riscv64" "0.21.4" + "@esbuild/linux-s390x" "0.21.4" + "@esbuild/linux-x64" "0.21.4" + "@esbuild/netbsd-x64" "0.21.4" + "@esbuild/openbsd-x64" "0.21.4" + "@esbuild/sunos-x64" "0.21.4" + "@esbuild/win32-arm64" "0.21.4" + "@esbuild/win32-ia32" "0.21.4" + "@esbuild/win32-x64" "0.21.4" + escalade@^3.1.1, escalade@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.2.tgz#54076e9ab29ea5bf3d8f1ed62acffbb88272df27" @@ -7414,6 +7448,26 @@ tsup@^8.1.0: sucrase "^3.20.3" tree-kill "^1.2.2" +tsup@^8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/tsup/-/tsup-8.1.0.tgz#354ce9def1721f5029564382ea2a42dc67fbb489" + integrity sha512-UFdfCAXukax+U6KzeTNO2kAARHcWxmKsnvSPXUcfA1D+kU05XDccCrkffCQpFaWDsZfV0jMyTsxU39VfCp6EOg== + dependencies: + bundle-require "^4.0.0" + cac "^6.7.12" + chokidar "^3.5.1" + debug "^4.3.1" + esbuild "^0.21.4" + execa "^5.0.0" + globby "^11.0.3" + joycon "^3.0.1" + postcss-load-config "^4.0.1" + resolve-from "^5.0.0" + rollup "^4.0.2" + source-map "0.8.0-beta.0" + sucrase "^3.20.3" + tree-kill "^1.2.2" + tty-table@^4.1.5: version "4.2.3" resolved "https://registry.yarnpkg.com/tty-table/-/tty-table-4.2.3.tgz#e33eb4007a0a9c976c97c37fa13ba66329a5c515" @@ -7595,7 +7649,7 @@ typedoc@^0.25.13: minimatch "^9.0.3" shiki "^0.14.7" -typescript@^5.4.4: +typescript@^5.4.4, typescript@^5.4.5: version "5.4.5" resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611" integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==