Skip to content

Commit

Permalink
init migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ritual-all committed Jan 18, 2024
0 parents commit 69963b8
Show file tree
Hide file tree
Showing 44 changed files with 6,652 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Config file
config.json

# Data files
*.rdb

# Log files
*.log
29 changes: 29 additions & 0 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# pre-commit workflow
#
# Ensures the codebase passes the pre-commit stack.

name: pre-commit

on: [pull_request]

jobs:
node:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: pip

- name: Install dependencies (python)
run: |
pip install -r requirements.txt
- name: Run pre-commit hooks
uses: pre-commit/[email protected]
with:
extra_args: --all-files --show-diff-on-failure
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Python
env/
__pycache__/
.pytest_cache

# notebooks
*/.vscode/*
*/.idea/*
*/.DS_Store
*/.env
*/.env.local
*/.env.*.local

# Linters
**/.mypy_cache/
**/.ruff_cache/

# Unit test / coverage reports
htmlcov/
.coverage
.coverage.*

# Environments
.env
.venv
env/
venv/

# Local logs
*.log

# Config file
config.json

# Redis
*.rdb
31 changes: 31 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.289
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black

- repo: local
hooks:
- id: mypy
name: mypy
entry: mypy --strict
language: system
types: [python]

# Default pre-commit hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
# Ensure EOF exists
- id: end-of-file-fixer
# Prevent adding large files
- id: check-added-large-files
args: ["--maxkb=5000"]
# Newline at end of file
- id: trailing-whitespace
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# syntax=docker/dockerfile:1

# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/

ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION}-slim as base

# Prevents Python from writing pyc files.
ENV PYTHONDONTWRITEBYTECODE=1

# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
ENV PYTHONUNBUFFERED=1

WORKDIR /app

# Create a non-privileged user that the frenrug will run under.
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
appuser

# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
# Leverage a bind mount to requirements to avoid having to copy them into
# into this layer.
RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=requirements.txt,target=requirements.txt \
python -m pip install -r requirements.txt

# Switch to the non-privileged user to run the application.
# USER appuser

# Install some executables
RUN apt-get update \
&& apt-get install -y curl procps sysstat ifstat \
&& rm -rf /var/lib/apt/lists/*

# Copy the source code into the container.
COPY . .

# Run the application.
ENTRYPOINT ["/app/entrypoint.sh"]
32 changes: 32 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
The Clear BSD License

Copyright (c) 2023 Origin Research Ltd
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted (subject to the limitations in the disclaimer below) provided that
the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
55 changes: 55 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Use bash as shell
SHELL := /bin/bash

# Phony targets
.PHONY: install run deps

# Default: install deps
all: install

# Install dependencies
install:
@pip install -r requirements.txt

# Save dependencies
deps:
@pip-chill > requirements.txt

# Lint code
lint:
@echo "Linting src/"
@ruff check src --fix
@echo "Linting scripts/"
@ruff check scripts --fix

# Type check code
types:
@mypy src/main.py --check-untyped-defs

# Format code
format:
@echo "Formatting src/"
@ruff format src
@echo "Formatting scripts/"
@ruff format scripts

# Run process
run:
@python3.11 src/main.py

# Script: register node
register-node:
@PYTHONPATH=$$PYTHONPATH:src python3.11 scripts/register_node.py

# Script: activate node
activate-node:
@PYTHONPATH=$$PYTHONPATH:src python3.11 scripts/activate_node.py

build:
docker build -t ritualnetwork/infernet-node:$(tag) .

# You may need to set up a docker builder, to do so run:
# docker buildx create --name mybuilder --bootstrap --use
# refer to https://docs.docker.com/build/building/multi-platform/#building-multi-platform-images for more info
build-multiplatform:
docker buildx build --platform linux/amd64,linux/arm64 -t ritualnetwork/infernet-node:$(tag) --push .
125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
[![pre-commit](https://github.com/ritual-net/infernet-node/actions/workflows/workflow.yaml/badge.svg)](https://github.com/ritual-net/infernet-node/migration/actions/workflows/workflow.yaml)

# Infernet Node

The Infernet Node is the off-chain counterpart to the [Infernet SDK](https://github.com/ritual-net/infernet-sdk) from [Ritual](https://ritual.net), responsible for servicing compute workloads and delivering responses to on-chain smart contracts.

Developers can flexibily configure an Infernet Node for both on- and off-chain compute consumption, with extensible and robust parameterization at a per-container level.

> [!IMPORTANT]
> Infernet Node architecture, quick-start guides, and in-depth documentation can be found on the [Ritual documentation website](https://docs.ritual.net/infernet/node/introduction)
> [!WARNING]
> This software is being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of the software.
## Node configuration

At its core, the Infernet Node operates according to a set of runtime configurations. Some of these configurations have sane defaults and do not need modification. See [config.sample.json](./config.sample.json) for an example, or copy to begin modifying:

```bash
# Copy and modify sample config
cp config.sample.json config.json
vim config.json
```

### Required configuration parameters

- **log_path** (`string`). The local file path for logging.
- **startup_wait** (`float`, Optional). The number of seconds to wait for containers to start up before starting the node.
- **chain** (`object`). Chain configurations.
- **enabled** (`boolean`). Whether chain is enabled on this node.
- **trail_head_blocks** (`integer`). _if enabled_: how many blocks to stay behind head when syncing. Set to `0` to ignore.
- **rpc_url** (`string`). _if enabled_: the HTTP(s) JSON-RPC url.
- **coordinator_address** (`string`). _if enabled_: the Coordinator contract address.
- **wallet** (`object`). _if enabled_:
- **max_gas_limit** (`integer`). Maximum gas limit per node transaction
- **private_key** (`string`). Node wallet private key
- **docker** (`object`, optional). Docker credentials to pull private containers with
- **username** (`string`). The Dockerhub username.
- **password** (`string`). The Dockerhub [Personal Access Token](https://docs.docker.com/security/for-developers/access-tokens/) (PAT).
- **containers** (`array[container_spec]`). Array of supported container specifications.
- **container_spec** (`object`). Specification of supported container.
- **id** (`string`). **Must be unique**. ID of supported service.
- **image** (`string`). Dockerhub image to run container from. Must be local, public, or accessible with provided DockerHub credentials.
- **command** (`string`). The command and flags to run the container with.
- **env** (`object`). The environment variables to pass into the container.
- **port** (`integer`). Local port to expose this container on.
- **external** (`boolean`). Whether this container can be the first container in a [JobRequest](/src/server/api.md#jobrequest).
- **description** (`string`, optional). Description of service provided by this container.
- **allowed_ips** (`array[string]`). Container-level firewall. Only specified IPs allowed to request execution of this container.
- _Leave empty for no restrictions_.
- **allowed_addresses** (`array[string]`). Container-level firewall. Only specified addresses allowed to request execution of this container, with request originating from on-chain contract.
- _Leave empty for no restrictions_.
- **allowed_delegate_addresses** (`array[string]`). Container-level firewall. Only specified addresses allowed to request execution of this container, with request originating from on-chain contract but via off-chain delegate subscription (with this address corresponding to the delegate subscription `owner`).
- _Leave empty for no restrictions_.
- **gpu** (`boolean`). Whether this should be a GPU-enabled container. Host must also be GPU-enabled.

### Sane default configuration parameters

- **server** (`object`). Server configurations.
- **port** (`integer`). Port to run server on. Defaults to `4000`.
- **redis** (`object`). Redis configurations.
- **host** (`string`). Host to connect to. Defaults to `"redis"`.
- **port** (`integer`). Port to connect to. Defaults to `6379`.
- **forward_stats** (`boolean`). Whether to send diagnostic system stats to Ritual. Defaults to `true`.
- **startup_wait** (`float`). Number of seconds to wait for containers to start up before starting the node.
Defaults to `60`.

## Deploying the node

### Locally via Docker

```bash
# Set tag
tag="0.0.1"

# Build image from source
docker build -t ritualnetwork/infernet-node:$tag .

# Configure node
cd deploy
cp ../config.sample.json config.json
# FILL IN config.json #

# Run node and dependencies
docker compose up -d
```

### Locally via source

```bash
# Create and source new python venv
python3.11 -m venv env
source ./env/bin/activate

# Install dependencies
make install

# Configure node
cp config.sample.json config.json
# FILL IN config.json #

# Run node
make run
```

### Remotely via AWS / GCP

Follow README instructions in the [infernet-node-deploy](https://github.com/ritual-net/infernet-node-deploy) repository.

## Publishing a Docker image

```bash
# Set tag
tag="0.0.1"

# Force linux build (useful when building on Mac)
docker build --platform linux/amd64 -t ritualnetwork/infernet-node:$tag .

# Push to Dockerhub
docker push ritualnetwork/infernet-node:$tag
```

## License

[BSD 3-clause Clear](./LICENSE)
Loading

0 comments on commit 69963b8

Please sign in to comment.