Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/decentralisation #4

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .env.standalone.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
REDIS_USERNAME=
REDIS_PASSWORD=

DB_HOST=postgres-service:5432
DB_NAME=
DB_USERNAME=
DB_PASSWORD=

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_S3_BUCKET_NAME=
S3_PUBLIC_URL=

JWT_SECRET=
ETHEREUM_NODE=
30 changes: 17 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,37 @@ WORKDIR /app
COPY go.mod go.sum ./

RUN go mod download
# prefetch the prisma binaries, so that they will be cached and not downloaded on each change
RUN go run github.com/steebchen/prisma-client-go prefetch

COPY . .

RUN go run github.com/steebchen/prisma-client-go generate
RUN go run github.com/playwright-community/playwright-go/cmd/playwright@latest install --with-deps
RUN go run github.com/playwright-community/playwright-go/cmd/playwright@latest install --with-deps firefox

ARG PLATFORM=linux
ARG ARCH=amd64
RUN CGO_ENABLED=0 GOARCH=${ARCH} GOOS=${PLATFORM} go build -a -installsuffix cgo -o service ./cmd/server/main.go

FROM ubuntu:22.04
# FROM ubuntu:22.04
FROM mcr.microsoft.com/playwright:v1.40.0-jammy

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive \
apt-get install -y --no-install-recommends \
ca-certificates \
build-essential \
xorg \
gnome-core \
libgtk-3-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# RUN apt-get update && \
# DEBIAN_FRONTEND=noninteractive \
# apt-get install -y --no-install-recommends \
# ca-certificates \
# build-essential \
# xorg \
# gnome-core \
# libgtk-3-dev && \
# apt-get clean && \
# rm -rf /var/lib/apt/lists/*

WORKDIR /dojo-api

COPY --from=builder /app/service .
COPY --from=builder /app/.env .

EXPOSE 8080

CMD ["./service"]
CMD ["./service"]
190 changes: 181 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,186 @@
version: '3.8'
---
volumes:
postgres-volume:
redis-volume:
testnet-lite-volume:

services:
postgres:
image: postgres:latest
redis-service:
env_file:
- .env
image: redis/redis-stack-server:7.4.0-v0
environment:
# CHANGE THE PASSWORD TO A PASSWORD YOU WANT TO USE
REDIS_ARGS: "--requirepass ${REDIS_PASSWORD} --user ${REDIS_USERNAME} on >${REDIS_PASSWORD} ~* allcommands"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 5s
retries: 5
expose:
- 6379
volumes:
- redis-volume:/data

postgres-service:
env_file:
- .env
image: postgres:15.7
environment:
POSTGRES_DB: subnet_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME}"]
interval: 5s
timeout: 5s
retries: 5
ports:
- "5432:5432"
expose:
- 5432
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
- postgres-volume:/var/lib/postgresql/data

prisma-setup:
platform: linux/amd64
image: golang:1.22
env_file:
- .env
environment:
DATABASE_URL: postgresql://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}
working_dir: /app
volumes:
- ./go.mod:/app/go.mod
- ./go.sum:/app/go.sum
- ./schema.prisma:/app/schema.prisma
command:
- /bin/sh
- -c
- |
go install github.com/steebchen/prisma-client-go@latest
go run github.com/steebchen/prisma-client-go generate
go run github.com/steebchen/prisma-client-go db push
depends_on:
- postgres-service

node-subtensor-testnet:
container_name: node-subtensor-testnet
image: ghcr.io/opentensor/subtensor:pr-720
platform: linux/amd64
ports:
- "9944:9944"
- "30333:30333"
- "9933:9933"
expose:
- 9944
- 30333
- 9933
environment:
- CARGO_HOME=/var/www/node-subtensor/.cargo
volumes:
- testnet-lite-volume:/tmp/blockchain
command:
- /bin/bash
- -c
- |
node-subtensor \
--base-path /tmp/blockchain \
--chain raw_spec_testfinney.json \
--rpc-external --rpc-cors all \
--no-mdns \
--in-peers 500 --out-peers 500 \
--bootnodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr \
--sync warp
--reserved-nodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr \
--reserved-only
healthcheck:
test:
# [
# "CMD-SHELL",
# "docker logs node-subtensor-testnet 2>&1 | grep -q 'Imported #' && exit 0 || exit 1",
# ]
["CMD-SHELL", "exit 0"]
interval: 12s
timeout: 24s
retries: 10
start_period: 30s

sidecar:
image: docker.io/parity/substrate-api-sidecar:v19.0.2
read_only: true
environment:
# for testnet: wss://test.finney.opentensor.ai:443
# SAS_SUBSTRATE_URL: wss://test.finney.opentensor.ai:443
SAS_SUBSTRATE_URL: ws://node-subtensor-testnet:9944
expose:
- 8080
healthcheck:
# jank as fuck since no curl
test:
[
"CMD",
"node",
"-e",
"const http = require('http'); const options = { hostname: '127.0.0.1', port: 8080, path: '/blocks/head', method: 'GET' }; const req = http.request(options, (res) => { process.exit(res.statusCode === 200 ? 0 : 1); }); req.on('error', (error) => { console.error(error); process.exit(1); }); req.end();",
]
interval: 12s
timeout: 24s
retries: 10
start_period: 30s
depends_on:
node-subtensor-testnet:
condition: service_healthy

worker-api:
env_file:
- .env
platform: linux/amd64
build:
context: .
dockerfile: Dockerfile
environment:
RUNTIME_ENV: local
SERVER_PORT: 8081
SUBNET_UID: 98
VALIDATOR_MIN_STAKE: 20000
CORS_ALLOWED_ORIGINS: http://localhost*
SUBSTRATE_API_URL: sidecar:8080
# authentication
TOKEN_EXPIRY: 24
REDIS_HOST: redis-service
REDIS_PORT: 6379
# these envs get sourced from .env so we dont need to rebuild
# # postgres
# ETHEREUM_NODE: ${ETHEREUM_NODE}
# JWT_SECRET: ${JWT_SECRET}
# DB_NAME: ${DB_NAME}
# DB_HOST: ${DB_HOST}
# DB_USERNAME: ${DB_USERNAME}
# DB_PASSWORD: ${DB_PASSWORD}
# DATABASE_URL: postgresql://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}
# # aws s3 setup
# AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
# AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
# AWS_S3_BUCKET_NAME: ${AWS_S3_BUCKET_NAME}
# S3_PUBLIC_URL: ${S3_PUBLIC_URL}
# # redis
# REDIS_USERNAME: ${REDIS_USERNAME}
# REDIS_PASSWORD: ${REDIS_PASSWORD}
ports:
- "8080:8081"
depends_on:
redis-service:
condition: service_healthy
postgres-service:
condition: service_healthy
sidecar:
condition: service_healthy
prisma-setup:
condition: service_completed_successfully
command: ["./service", "--debug"]
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8081"]
interval: 10s
timeout: 10s
retries: 5
3 changes: 2 additions & 1 deletion schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ datasource db {
}

generator db {
provider = "go run github.com/steebchen/prisma-client-go"
provider = "go run github.com/steebchen/prisma-client-go"
binaryTargets = ["darwin-arm64", "debian-openssl-3.0.x"]
}

model ExternalUser {
Expand Down
17 changes: 8 additions & 9 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/joho/godotenv"
"github.com/playwright-community/playwright-go"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/rs/zerolog/pkgerrors"
Expand Down Expand Up @@ -51,14 +50,14 @@ func init() {
LoadDotEnv("AWS_S3_BUCKET_NAME")
LoadDotEnv("S3_PUBLIC_URL")

err = playwright.Install(
&playwright.RunOptions{
Browsers: []string{"firefox"},
},
)
if err != nil {
log.Fatal().Err(err).Msg("Error installing playwright")
}
// err = playwright.Install(
// &playwright.RunOptions{
// Browsers: []string{"firefox"},
// },
// )
// if err != nil {
// log.Fatal().Err(err).Msg("Error installing playwright")
// }

zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
Expand Down
Loading