feat: add docker deployment

This commit is contained in:
dboures 2023-03-14 20:46:49 -05:00
parent 74a042df9d
commit aa114539c0
No known key found for this signature in database
GPG Key ID: AB3790129D478852
7 changed files with 86 additions and 3 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
**/target

5
.env-example Normal file
View File

@ -0,0 +1,5 @@
RPC_URL=http://solana-mainnet-api.rpc-node.com
DATABASE_URL=
SQLX_OFFLINE=true
MAX_PG_POOL_CONNS_WORKER=5
MAX_PG_POOL_CONNS_SERVER=15

19
Dockerfile.server Normal file
View File

@ -0,0 +1,19 @@
FROM lukemathwalker/cargo-chef:latest-rust-1.67.1-slim AS chef
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path server-recipe.json
FROM chef AS builder
COPY --from=planner server-recipe.json server-recipe.json
RUN apt-get update && apt-get install -y libudev-dev clang pkg-config libssl-dev build-essential cmake
RUN rustup component add rustfmt
RUN cargo chef cook --release --recipe-path server-recipe.json
# Build application
COPY . .
RUN cargo build --release --bin server
# We do not need the Rust toolchain to run the binary!
FROM debian:bullseye-slim AS runtime
COPY --from=builder /target/release/server /usr/local/bin
ENTRYPOINT ["/usr/local/bin/server"]

19
Dockerfile.worker Normal file
View File

@ -0,0 +1,19 @@
FROM lukemathwalker/cargo-chef:latest-rust-1.67.1-slim AS chef
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path worker-recipe.json
FROM chef AS builder
COPY --from=planner worker-recipe.json worker-recipe.json
RUN apt-get update && apt-get install -y libudev-dev clang pkg-config libssl-dev build-essential cmake
RUN rustup component add rustfmt
RUN cargo chef cook --release --recipe-path worker-recipe.json
# Build application
COPY . .
RUN cargo build --release --bin worker
# We do not need the Rust toolchain to run the binary!
FROM debian:bullseye-slim AS runtime
COPY --from=builder /target/release/worker /usr/local/bin
ENTRYPOINT ["/usr/local/bin/worker"]

33
docker-compose.yml Normal file
View File

@ -0,0 +1,33 @@
services:
server:
env_file: .env
build:
dockerfile: Dockerfile.server
depends_on:
- "db"
entrypoint:
- "/usr/local/bin/server"
- "/etc/markets.json"
ports:
- 127.0.0.1:8080:8080
restart: always
volumes:
- ./markets.json:/etc/markets.json
worker:
env_file: .env
build:
dockerfile: Dockerfile.worker
depends_on:
- "db"
restart: always
entrypoint:
- "/usr/local/bin/worker"
- "/etc/markets.json"
volumes:
- ./markets.json:/etc/markets.json
volumes:
data:

View File

@ -12,6 +12,7 @@ use openbook_candles::{
utils::{Config, WebContext},
};
use traders::{get_top_traders_by_base_volume, get_top_traders_by_quote_volume};
use std::env;
mod candles;
mod markets;
@ -23,7 +24,9 @@ async fn main() -> std::io::Result<()> {
dotenv::dotenv().ok();
env_logger::init();
let path_to_markets_json: String = dotenv::var("PATH_TO_MARKETS_JSON").unwrap();
let args: Vec<String> = env::args().collect();
assert!(args.len() == 2);
let path_to_markets_json = &args[1];
let rpc_url: String = dotenv::var("RPC_URL").unwrap();
let database_url: String = dotenv::var("DATABASE_URL").unwrap();
let max_pg_pool_connections: u32 = dotenv::var("MAX_PG_POOL_CONNS_SERVER")
@ -37,7 +40,7 @@ async fn main() -> std::io::Result<()> {
max_pg_pool_connections,
};
let markets = load_markets(&path_to_markets_json);
let markets = load_markets(path_to_markets_json);
let market_infos = fetch_market_infos(&config, markets).await.unwrap();
let pool = connect_to_database(&config).await.unwrap();

View File

@ -12,12 +12,15 @@ use openbook_candles::utils::Config;
use solana_sdk::pubkey::Pubkey;
use std::{collections::HashMap, str::FromStr};
use tokio::sync::mpsc;
use std::env;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenv::dotenv().ok();
let path_to_markets_json: String = dotenv::var("PATH_TO_MARKETS_JSON").unwrap();
let args: Vec<String> = env::args().collect();
assert!(args.len() == 2);
let path_to_markets_json = &args[1];
let rpc_url: String = dotenv::var("RPC_URL").unwrap();
let database_url: String = dotenv::var("DATABASE_URL").unwrap();
let max_pg_pool_connections: u32 = dotenv::var("MAX_PG_POOL_CONNS_WORKER")