From 04dc377bf8b3b4f2e5380c9b0b14b69ca63f62f1 Mon Sep 17 00:00:00 2001 From: abs2023 Date: Thu, 5 Dec 2024 12:07:31 -0500 Subject: [PATCH 1/7] improve VLAST call --- .github/actions/gen_tag_name/action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/actions/gen_tag_name/action.yml b/.github/actions/gen_tag_name/action.yml index e3874eeb..36bb09ea 100644 --- a/.github/actions/gen_tag_name/action.yml +++ b/.github/actions/gen_tag_name/action.yml @@ -11,8 +11,7 @@ runs: VMIN=0 VPAT=0 set +o pipefail - # VLAST=$(git describe --tags --abbrev=0 --match='v[1-9]*' 2>/dev/null | cut -c2-) - VLAST=$(git fetch origin main --tags && git describe --tags --abbrev=0 --match='v[1-9]*' origin/main | cut -c2-) + VLAST=$(git describe --tags --abbrev=0 --match='v[1-9]*' refs/remotes/origin/main 2>/dev/null | cut -c2-) [ $VLAST ] && declare $(echo $VLAST | awk -F '.' '{print "VMAJ="$1" VMIN="$2" VPAT="$3}') if [ "$GITHUB_REF_NAME" = "main" ] then From 5681f56fce4f0942c1dc71534f1f762f469951ca Mon Sep 17 00:00:00 2001 From: abs2023 Date: Thu, 5 Dec 2024 14:36:06 -0500 Subject: [PATCH 2/7] docker build helper script and docs --- docs/02a-proxy-router-docker.md | 72 +++++++++++++++++++++++++++++++++ proxy-router/.gitignore | 10 ++++- proxy-router/Dockerfile | 13 ++---- proxy-router/docker-compose.yml | 13 ++++-- proxy-router/docker_build.sh | 43 ++++++++++++++++++++ 5 files changed, 138 insertions(+), 13 deletions(-) create mode 100644 docs/02a-proxy-router-docker.md create mode 100755 proxy-router/docker_build.sh diff --git a/docs/02a-proxy-router-docker.md b/docs/02a-proxy-router-docker.md new file mode 100644 index 00000000..1892a9db --- /dev/null +++ b/docs/02a-proxy-router-docker.md @@ -0,0 +1,72 @@ + +# Proxy-Router Docker Setup: + +**This document describes setting up the proxy-router component of the Morpheus AI Network in a Docker container ONLY and accessing it via the Swagger API Interface...no GUI or Wallet components are included in this setup** + +## Overview: +* The Proxy-Router is a critical component of the Morpheus AI Network. It is responsible for monitoring the blockchain for events and managing the AI models and providers that are available to the network. +* The Proxy-Router is a standalone application that can be run on any server that has access to the blockchain and the AI models. +* This document walks through using Docker to build and run the proxy-router image on your server. + +## Pre-Requisites: +* Your AI model has been configured, started and made available to the proxy-router server via a private endpoint (IP:PORT or DNS:PORT) eg: `http://mycoolaimodel.domain.com:8080` +* You have an existing funded wallet with MOR and ETH and also have the `private key` for the wallet (this will be needed for the .env file configuration) +* Your proxy-router must have a **publicly accessible endpoint** for the provider (ip:port or fqdn:port no protocol) eg: `mycoolmornode.domain.com:3333` - this will be used when creating the provider on the blockchain +* Docker and Git are installed and current on your server +* The three key configuration files are located in the same directory as the proxy-router code: + * .env + * models-config.json + * rating-config.json + +## Installation & Configuration Steps: +1. Clone the source code from the repository: + * `git clone -b main https://github.com/Lumerin-protocol/Morpheus-Lumerin-Node.git` +1. Change to the proxy-router directory: + * `cd Morpheus-Lumerin-Node\proxy-router` +1. Configure the 3 key files for your environment: + 1. Environment file configuration + 1. Copy the example file to .env: + * Linux/Mac: `cp env.example .env` + * Windows: `copy env.example.win .env` + 1. Edit values within the .env as desired + * Add your private key to`WALLET_PRIVATE_KEY=` + * `MODELS_CONFIG_PATH=/app/data/models-config.json` + * `RATING_CONFIG_PATH=/app/data/rating-config.json` + 1. Choose the **blockchain** you'd like to work on...**Arbitrum MAINNET is the default** + * To operate on the Sepolia Arbitrum TESTNET, + * Uncomment the `TESTNET VALUES` and comment the `MAINNET VALUES` lines & save the file + 1. Models Configuration file + 1. Copy the example file to models-config.json: + * Linux/Mac: `cp models-config.json.example models-config.json` + * Windows: `copy models-config.json.example models-config.json` + 1. Edit the models-config.json file to include the models you'd like to use.. details here: [models-config.json.md](models-config.json.md) + 1. Once your provider is up and running, deploy a new model and model bid via the API interface (you will need to update the `modelId` for the configuration) + 1. Rating Configuration file + 1. Copy the example file to rating-config.json: + * Linux/Mac: `cp rating-config.json.example rating-config.json` + * Windows: `copy rating-config.json.example rating-config.json` + 1. Edit the rating-config.json file to include the weights and preferred providers you'd like to use.. details here: [rating-config.json.md](rating-config.json.md) + +## Build the proxy-router Docker Image: +1. Build the Docker image using the provided `docker_build.sh` script + * `./docker_build.sh --build` + * This script pulls the current Git tag and version, builds the docker image with all the port and defaults defined in the docker-compose.yml file + +## Running the proxy-router Docker Container: +1. Run the Docker container using the provided `docker_build.sh` script + * `./docker_build.sh --run` + * This script runs the docker container with the port and volume mappings defined in the docker-compose.yml file + * The proxy-router will start and begin listening for blockchain events + +## Validating Steps: +1. Once the proxy-router is running, you can navigate to the Swagger API Interface (http://localhost:8082/swagger/index.html as example) to validate that the proxy-router is running and listening for blockchain events +1. Once validated, you can move on and create your provider, model and bid on the blockchain [03-provider-offer.md](03-provider-offer.md) + +## NOTES: +* We have created docker-compose.yml, Dockerfile and docker_build.sh scripts to ease configuration and deployment of the proxy-router in a containerized environment +* Use these files as guides for applying to your system needs and configurations, private key, eth_node, ports, endpoints, volumes, .env, models-config.json and rating-config.json will need to be adjusted to your specific needs +* In most cases, the default .env file will work for the proxy-router...In some cases you will want to modify the .env file with advanced capability (log entries, private keys, private endpoints, etc) +* Please see the following for more information on these key config files: + * [proxy-router.all.env](proxy-router.all.env) + * [models-config.json.md](models-config.json.md) + * [rating-config.json.md](rating-config.json.md) \ No newline at end of file diff --git a/proxy-router/.gitignore b/proxy-router/.gitignore index 57b9093e..2f5df023 100644 --- a/proxy-router/.gitignore +++ b/proxy-router/.gitignore @@ -11,4 +11,12 @@ bin data* models-config.json -rating-config.json \ No newline at end of file +rating-config.json + +#Badger DB +*.vlog +*.mem +DISCARD +KEYREGISTRY +LOCK +MANIFEST \ No newline at end of file diff --git a/proxy-router/Dockerfile b/proxy-router/Dockerfile index f3581e27..b9f7c9f6 100644 --- a/proxy-router/Dockerfile +++ b/proxy-router/Dockerfile @@ -10,16 +10,11 @@ ENV COMMIT=$COMMIT WORKDIR /app COPY . . -# Build the Go binary (recommended for linux/amd64...for MacARM use buildx) -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ +# Build the Go binary (Docker will build automatically to the OS and Arch that is hosting) +RUN CGO_ENABLED=0 \ TAG_NAME=$TAG_NAME COMMIT=$COMMIT ./build.sh && \ cp /bin/sh /app/sh && chmod +x /app/sh - # Multiplatform Build Notes: -# to support both amd64 and arm64, use Docker’s Buildx to create a multi-architecture image -# docker buildx create --use -# docker buildx build --platform linux/amd64,linux/arm64 -t proxy-router:latest . - # Stage 2: Final Image FROM scratch WORKDIR /app @@ -29,8 +24,8 @@ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /app/bin/proxy-router /usr/bin/ # Optional Copy utilities from busybox image -# COPY --from=busybox /bin /bin -# COPY --from=busybox /lib /lib +COPY --from=busybox /bin /bin +COPY --from=busybox /lib /lib SHELL ["/bin/sh", "-c"] EXPOSE 3333 8082 diff --git a/proxy-router/docker-compose.yml b/proxy-router/docker-compose.yml index e4beebfa..2819466a 100644 --- a/proxy-router/docker-compose.yml +++ b/proxy-router/docker-compose.yml @@ -1,8 +1,15 @@ services: proxy-router: - build: . + build: + context: . + args: + COMMIT: ${COMMIT:-unknown} + TAG_NAME: ${TAG_NAME:-latest} + image: proxy-router:${TAG_NAME} env_file: - .env ports: - - 8082:8082 - - 3333:3333 \ No newline at end of file + - "8082:8082" + - "3333:3333" + volumes: + - .:/app/data \ No newline at end of file diff --git a/proxy-router/docker_build.sh b/proxy-router/docker_build.sh new file mode 100755 index 00000000..ef109d6c --- /dev/null +++ b/proxy-router/docker_build.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# This script assumes you've cloned the repository and want to build with proper commit and version numbers +# It will use the latest Git tag as the version number and the latest short commit hash as the commit number +# It also leverages the docker-compose.yml file to build the Docker image + +# Pre-requisites: Docker & Git installed + +# Assumptions: +# - properly formatted .env in current directory +# - properly formatted models-config.json in current directory +# - properly formatted rating-config.json in current directory + +# Check if TAG_NAME is set; if not, use the latest Git tag +if [ -z "$TAG_NAME" ]; then + VLAST=$(git describe --tags --abbrev=0 --match='v[1-9]*' refs/remotes/origin/main 2>/dev/null | cut -c2-) + [ $VLAST ] && declare $(echo $VLAST | awk -F '.' '{print "VMAJ="$1" VMIN="$2" VPAT="$3}') + MB=$(git merge-base refs/remotes/origin/main HEAD) + VPAT=$(git rev-list --count --no-merges ${MB}..HEAD) + TAG_NAME=${VMAJ}.${VMIN}.${VPAT} +fi +VERSION=$TAG_NAME +echo VERSION=$VERSION + +# if commit is not set, use the latest commit +if [ -z "$COMMIT" ]; then + SHORT_COMMIT=$(git rev-parse --short HEAD) +fi +COMMIT=$SHORT_COMMIT +echo COMMIT=$COMMIT +export VERSION COMMIT + +# Check if the user wants to build or run the Docker image +if [ "$1" = "--build" ]; then + echo "Building Docker image..." + docker-compose build + docker tag proxy-router:$VERSION proxy-router:latest +elif [ "$1" = "--run" ]; then + echo "Running Docker container..." + docker-compose up +else + echo "Usage: $0 [--build | --run]" +fi \ No newline at end of file From 14a7f6f3595c7eb2ff5984ce8c0d5631e0658b60 Mon Sep 17 00:00:00 2001 From: abs2023 Date: Thu, 5 Dec 2024 14:40:22 -0500 Subject: [PATCH 3/7] update to include /data instruction --- docs/02a-proxy-router-docker.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/02a-proxy-router-docker.md b/docs/02a-proxy-router-docker.md index 1892a9db..71563e72 100644 --- a/docs/02a-proxy-router-docker.md +++ b/docs/02a-proxy-router-docker.md @@ -30,8 +30,10 @@ * Windows: `copy env.example.win .env` 1. Edit values within the .env as desired * Add your private key to`WALLET_PRIVATE_KEY=` - * `MODELS_CONFIG_PATH=/app/data/models-config.json` - * `RATING_CONFIG_PATH=/app/data/rating-config.json` + * Modify the following values to ensure that those files remain "outside of the running container" for persistence and are mounted by the docker-compose.yml file's `volume` directive + * `MODELS_CONFIG_PATH=/app/data/models-config.json` + * `RATING_CONFIG_PATH=/app/data/rating-config.json` + * `PROXY_STORAGE_PATH=/app/data/badger` 1. Choose the **blockchain** you'd like to work on...**Arbitrum MAINNET is the default** * To operate on the Sepolia Arbitrum TESTNET, * Uncomment the `TESTNET VALUES` and comment the `MAINNET VALUES` lines & save the file From 02c0ae921e606b0918522133f3d99eae6178eb3d Mon Sep 17 00:00:00 2001 From: abs2023 Date: Thu, 5 Dec 2024 14:56:45 -0500 Subject: [PATCH 4/7] update script and doc --- docs/02a-proxy-router-docker.md | 10 ++++++---- proxy-router/docker_build.sh | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/02a-proxy-router-docker.md b/docs/02a-proxy-router-docker.md index 71563e72..d96c90a8 100644 --- a/docs/02a-proxy-router-docker.md +++ b/docs/02a-proxy-router-docker.md @@ -26,8 +26,8 @@ 1. Configure the 3 key files for your environment: 1. Environment file configuration 1. Copy the example file to .env: - * Linux/Mac: `cp env.example .env` - * Windows: `copy env.example.win .env` + * Linux/Mac: `cp .env.example .env` + * Windows: `copy .env.example.win .env` 1. Edit values within the .env as desired * Add your private key to`WALLET_PRIVATE_KEY=` * Modify the following values to ensure that those files remain "outside of the running container" for persistence and are mounted by the docker-compose.yml file's `volume` directive @@ -41,13 +41,15 @@ 1. Copy the example file to models-config.json: * Linux/Mac: `cp models-config.json.example models-config.json` * Windows: `copy models-config.json.example models-config.json` - 1. Edit the models-config.json file to include the models you'd like to use.. details here: [models-config.json.md](models-config.json.md) + 1. Edit the models-config.json file to include the models you'd like to use. + 1. Details here: [models-config.json.md](models-config.json.md) 1. Once your provider is up and running, deploy a new model and model bid via the API interface (you will need to update the `modelId` for the configuration) 1. Rating Configuration file 1. Copy the example file to rating-config.json: * Linux/Mac: `cp rating-config.json.example rating-config.json` * Windows: `copy rating-config.json.example rating-config.json` - 1. Edit the rating-config.json file to include the weights and preferred providers you'd like to use.. details here: [rating-config.json.md](rating-config.json.md) + 1. Edit the rating-config.json file to include the weights and preferred providers you'd like to use. + 1. Details here: [rating-config.json.md](rating-config.json.md) ## Build the proxy-router Docker Image: 1. Build the Docker image using the provided `docker_build.sh` script diff --git a/proxy-router/docker_build.sh b/proxy-router/docker_build.sh index ef109d6c..282b98c1 100755 --- a/proxy-router/docker_build.sh +++ b/proxy-router/docker_build.sh @@ -28,7 +28,7 @@ if [ -z "$COMMIT" ]; then fi COMMIT=$SHORT_COMMIT echo COMMIT=$COMMIT -export VERSION COMMIT +export VERSION COMMIT TAG_NAME # Check if the user wants to build or run the Docker image if [ "$1" = "--build" ]; then From 13c804e3fb71d4afcce1a484da642a793c7af441 Mon Sep 17 00:00:00 2001 From: abs2023 Date: Thu, 5 Dec 2024 15:10:42 -0500 Subject: [PATCH 5/7] final doc updat --- docs/02a-proxy-router-docker.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/02a-proxy-router-docker.md b/docs/02a-proxy-router-docker.md index d96c90a8..8446e2de 100644 --- a/docs/02a-proxy-router-docker.md +++ b/docs/02a-proxy-router-docker.md @@ -33,7 +33,7 @@ * Modify the following values to ensure that those files remain "outside of the running container" for persistence and are mounted by the docker-compose.yml file's `volume` directive * `MODELS_CONFIG_PATH=/app/data/models-config.json` * `RATING_CONFIG_PATH=/app/data/rating-config.json` - * `PROXY_STORAGE_PATH=/app/data/badger` + * `PROXY_STORAGE_PATH=/app/data/` 1. Choose the **blockchain** you'd like to work on...**Arbitrum MAINNET is the default** * To operate on the Sepolia Arbitrum TESTNET, * Uncomment the `TESTNET VALUES` and comment the `MAINNET VALUES` lines & save the file From 0e600ffa44815f4c498d4aac5a1627c4316d6795 Mon Sep 17 00:00:00 2001 From: abs2023 Date: Thu, 5 Dec 2024 15:22:27 -0500 Subject: [PATCH 6/7] updated gitignore --- proxy-router/.gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/proxy-router/.gitignore b/proxy-router/.gitignore index 2f5df023..381e8305 100644 --- a/proxy-router/.gitignore +++ b/proxy-router/.gitignore @@ -19,4 +19,5 @@ rating-config.json DISCARD KEYREGISTRY LOCK -MANIFEST \ No newline at end of file +MANIFEST +chats/ \ No newline at end of file From 126e16be2f2b564a78cbe7752aa83a4a4067728c Mon Sep 17 00:00:00 2001 From: abs2023 Date: Thu, 5 Dec 2024 15:28:33 -0500 Subject: [PATCH 7/7] udpated case for dockerfile --- proxy-router/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy-router/Dockerfile b/proxy-router/Dockerfile index b9f7c9f6..0e558363 100644 --- a/proxy-router/Dockerfile +++ b/proxy-router/Dockerfile @@ -1,5 +1,5 @@ # Stage 1: Build -FROM golang:1.22.3-alpine as builder +FROM golang:1.22.3-alpine AS builder # Capture the Git tag and commit hash during build ARG TAG_NAME