Skip to content

Commit

Permalink
dockerizing and openapi playground
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Sep 26, 2024
1 parent 056a75c commit e6d85a6
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
DATABASE_URL=postgres://mina:whatever@localhost:5432/archive
RUST_LOG=debug,error,mina_mesh=info
RUST_ENV=production
84 changes: 84 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ cynic-querygen = "3.7.3"
indoc = "2.0.5"

[dependencies]
aide = { version = "0.13.4", features = ["axum", "scalar"] }
anyhow = "1.0.86"
axum = { version = "0.7.5", features = ["macros"] }
clap = { version = "4.5.11", features = ["derive", "env"] }
cynic = { version = "3.7.3", features = ["http-reqwest-blocking"] }
dotenv = "0.15.0"
envy = "0.4.2"
futures = "0.3.30"
mesh = { path = "./mesh_generated" }
Expand Down
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM rust

WORKDIR /app

COPY Cargo.toml Cargo.lock ./
COPY mesh_generated/ ./mesh_generated
COPY mina_mesh/ ./mina_mesh

RUN cargo build --release

ENTRYPOINT ["/app/target/release/mina-mesh", "serve"]
54 changes: 54 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
services:
mina_mesh:
build: .
entrypoint:
- bash
- -c
- sleep 1000
environment:
MINA_PROXY_GRAPHQL_URL: "https://mainnet.minaprotocol.network/graphql"
ARCHIVE_DATABASE_URL: "postgres://postgres:postgres@postgres:5432/archive"
GENESIS_BLOCK_IDENTIFIER_HEIGHT: "359605"
GENESIS_BLOCK_IDENTIFIER_STATE_HASH: "3NK4BpDSekaqsG6tx8Nse2zJchRft2JpnbvMiog55WCr5xJZaKeP"
depends_on:
postgres:
condition: service_healthy
postgres:
container_name: archive-db
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: archive
healthcheck:

Check warning on line 23 in docker-compose.yaml

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (healthcheck)
test: [
"CMD-SHELL",
"psql -U postgres -d archive -tAc \"SELECT COUNT(*) FROM pg_database WHERE datname='archive';\" | grep -q '^1$'",

Check warning on line 26 in docker-compose.yaml

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (psql)

Check warning on line 26 in docker-compose.yaml

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (datname)
]
interval: 5s
timeout: 10s
retries: 10
volumes:
- "./archive/postgresql/data:/var/lib/postgresql/data"
ports:
- "5432:5432"
bootstrap_db:
image: "minaprotocol/mina-archive:3.0.0-93e0279-bullseye"

Check warning on line 36 in docker-compose.yaml

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (minaprotocol)
# image: 'gcr.io/o1labs-192920/mina-archive:3.0.0-dc6bf78-bullseye' # Use this image for Devnet

Check warning on line 37 in docker-compose.yaml

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (Devnet)
command: >
bash -c '
exit 0; #comment out to activate auto-import
curl -O https://673156464838-mina-archive-node-backups.s3.us-west-2.amazonaws.com/mainnet/mainnet-archive-dump-$(date +%F_0000).sql.tar.gz;
tar -zxvf mainnet-archive-dump-$(date +%F_0000).sql.tar.gz;

Check warning on line 42 in docker-compose.yaml

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (zxvf)
psql postgres://postgres:postgres@postgres:5432/archive -c "

Check warning on line 43 in docker-compose.yaml

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (psql)
ALTER SYSTEM SET max_connections = 500;
ALTER SYSTEM SET max_locks_per_transaction = 100;
ALTER SYSTEM SET max_pred_locks_per_relation = 100;
ALTER SYSTEM SET max_pred_locks_per_transaction = 5000;
"
psql postgres://postgres:postgres@postgres:5432/archive -f mainnet-archive-dump-$(date +%F_0000).sql;

Check warning on line 49 in docker-compose.yaml

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (psql)
'
# For Devnet Network, replace "mainnet" references with "devnet" in the block above

Check warning on line 51 in docker-compose.yaml

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (Devnet)

Check warning on line 51 in docker-compose.yaml

View workflow job for this annotation

GitHub Actions / cspell

Unknown word (devnet)
depends_on:
postgres:
condition: service_healthy
8 changes: 8 additions & 0 deletions src/commands/serve.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use aide::scalar::Scalar;
use anyhow::Result;
use axum::{
debug_handler,
Expand Down Expand Up @@ -27,8 +28,12 @@ pub struct ServeCommand {

impl ServeCommand {
pub async fn run(self) -> Result<()> {
dotenv::dotenv()?;
tracing_subscriber::fmt::init();
let scalar_handler = Scalar::new(OPENAPI_SPEC.to_string()).with_title("Mina Mesh").axum_handler();
let mina_mesh = self.config.to_mina_mesh().await?;
let router = Router::new()
.route("/", get(scalar_handler))
.route("/account/balance", post(handle_account_balance))
.route("/block", post(handle_block))
.route("/call", post(handle_call))
Expand Down Expand Up @@ -100,3 +105,6 @@ async fn handle_implemented_methods() -> impl IntoResponse {
"network_status",
])
}

static OPENAPI_SPEC: &str =
"https://raw.githubusercontent.com/coinbase/mesh-specifications/7f9f2f691f1ab1f7450e376d031e60d997dacbde/api.json";
20 changes: 10 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ use crate::{graphql::GraphQLClient, MinaMesh};

#[derive(Debug, Args)]
pub struct MinaMeshConfig {
#[arg(long, env, default_value_t = mina_proxy_url())]
pub mina_proxy_url: String,
#[arg(long, env, default_value_t = database_url())]
pub database_url: String,
#[arg(long, env, default_value_t = genesis_block_identifier_height())]
#[arg(long, env = "MINA_PROXY_URL", default_value_t = mina_proxy_url())]
pub proxy_url: String,
#[arg(long, env = "MINA_ARCHIVE_DATABASE_URL", default_value_t = database_url())]
pub archive_database_url: String,
#[arg(long, env = "MINA_GENESIS_BLOCK_IDENTIFIER_HEIGHT", default_value_t = genesis_block_identifier_height())]
pub genesis_block_identifier_height: i64,
#[arg(long, env, default_value_t = genesis_block_identifier_state_hash())]
#[arg(long, env = "MINA_GENESIS_BLOCK_IDENTIFIER_STATE_HASH", default_value_t = genesis_block_identifier_state_hash())]
pub genesis_block_identifier_state_hash: String,
}

impl MinaMeshConfig {
pub async fn to_mina_mesh(self) -> Result<MinaMesh> {
Ok(MinaMesh {
graphql_client: GraphQLClient::new(self.mina_proxy_url),
pg_pool: PgPool::connect(self.database_url.as_str()).await?,
graphql_client: GraphQLClient::new(self.proxy_url.to_owned()),
pg_pool: PgPool::connect(self.archive_database_url.as_str()).await?,
genesis_block_identifier: BlockIdentifier::new(
self.genesis_block_identifier_height,
self.genesis_block_identifier_state_hash.to_owned(),
Expand All @@ -33,8 +33,8 @@ impl MinaMeshConfig {
impl Default for MinaMeshConfig {
fn default() -> Self {
Self {
mina_proxy_url: mina_proxy_url(),
database_url: database_url(),
proxy_url: mina_proxy_url(),
archive_database_url: database_url(),
genesis_block_identifier_height: genesis_block_identifier_height(),
genesis_block_identifier_state_hash: genesis_block_identifier_state_hash(),
}
Expand Down
2 changes: 2 additions & 0 deletions words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ RUSTFLAGS
codegen
coinbases
deamon
dotenv
dprint
dsherret
dyntest
Expand All @@ -23,6 +24,7 @@ microschemas
mina
navroot
nocapture
openapi
preprocess
querygen
reqwest
Expand Down

0 comments on commit e6d85a6

Please sign in to comment.