Skip to content

Commit 32fa65c

Browse files
committedMar 20, 2025
chore: add api to docker setup
1 parent 2e24dc1 commit 32fa65c

File tree

7 files changed

+94
-31
lines changed

7 files changed

+94
-31
lines changed
 

‎.dockerignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.env
22
*.env
3-
.env.*
3+
.env.*
4+
target/
5+
**/target/
6+
venv

‎Cargo.lock

+16-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Dockerfile.api

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Declare the Python version build argument globally.
2+
ARG PYTHON_VERSION=3.10-slim
3+
4+
# Since the Api relies on types defined in bankai-core, we need python to be able to build it
5+
# A bit annoying, but is only required for building, and untangling the deps is not trivial
6+
7+
# Stage 1: Build the daemon binary with Rust
8+
FROM python:${PYTHON_VERSION} AS builder
9+
10+
# Install curl
11+
# Install required dependencies for building
12+
RUN apt-get update && apt-get install -y \
13+
pkg-config \
14+
libssl3 \
15+
libssl-dev \
16+
curl \
17+
build-essential
18+
19+
# Install Rust
20+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
21+
ENV PATH="/root/.cargo/bin:${PATH}"
22+
23+
WORKDIR /app
24+
COPY . .
25+
26+
# Build the application in release mode
27+
RUN cargo build --release -p bankai-api
28+
29+
# Runtime stage
30+
FROM debian:bookworm-slim
31+
32+
WORKDIR /app
33+
34+
# Install runtime dependencies
35+
RUN apt-get update && apt-get install -y ca-certificates libssl-dev && rm -rf /var/lib/apt/lists/*
36+
37+
# Copy the binary from the builder stage
38+
COPY --from=builder /app/target/release/bankai-api /app/
39+
40+
# Expose the port the API runs on
41+
EXPOSE 3001
42+
43+
# Run the binary
44+
CMD ["/app/bankai-api"]

‎Dockerfile ‎Dockerfile.daemon

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ gcc \
4646
libgmp-dev \
4747
&& ln -s /usr/bin/python3 /usr/bin/python
4848

49-
5049
# Copy the entire repository including .git
5150
COPY . .
5251

‎crates/api/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
[package]
2-
name = "api"
2+
name = "bankai-api"
33
version = "0.1.0"
44
edition = "2021"
55

6+
[[bin]]
7+
name = "bankai-api"
8+
path = "src/main.rs"
9+
610
[dependencies]
711
axum.workspace = true
812
tokio.workspace = true

‎crates/core/src/utils/constants.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub const SLOTS_PER_EPOCH: u64 = 32; // For mainnet
22
pub const SLOTS_PER_SYNC_COMMITTEE: u64 = 8192; // For mainnet
33
pub const TARGET_BATCH_SIZE: u64 = 32; // Defines how many epochs in one batch
44
pub const EPOCHS_PER_SYNC_COMMITTEE: u64 = 256; // For mainnet
5-
pub const MAX_CONCURRENT_JOBS_IN_PROGRESS: u64 = 3; // Define the limit of how many jobs can be in state "in progress" concurrently
5+
pub const MAX_CONCURRENT_JOBS_IN_PROGRESS: u64 = 8; // Define the limit of how many jobs can be in state "in progress" concurrently
66
pub const MAX_CONCURRENT_PIE_GENERATIONS: usize = 1; // Define how many concurrent trace (pie file) generation jobs are allowed to not exhaust resources
77
pub const MAX_CONCURRENT_RPC_DATA_FETCH_JOBS: usize = 1; // Define how many data fetching jobs can be performed concurrently to not overload RPC
88
pub const STARKNET_SEPOLIA: &str = "0x534e5f5345504f4c4941";

‎docker-compose.yml

+24-11
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ services:
44
daemon:
55
build:
66
context: .
7-
dockerfile: Dockerfile
7+
dockerfile: Dockerfile.daemon
88
env_file:
99
- .env.docker
1010
depends_on:
1111
db:
1212
condition: service_healthy
1313
volumes:
1414
- batches_data:/app/batches
15-
# Send container logs to stdout, which Docker captures
16-
# So that Promtail can scrape them, or you can use Docker logging driver
1715
logging:
1816
driver: "json-file"
1917
options:
@@ -22,7 +20,20 @@ services:
2220
restart: unless-stopped
2321
stop_grace_period: 10s
2422
stop_signal: SIGTERM
25-
23+
24+
bankai-api:
25+
build:
26+
context: .
27+
dockerfile: Dockerfile.api
28+
ports:
29+
- "3001:3001"
30+
env_file:
31+
- .env.docker
32+
depends_on:
33+
- db
34+
restart: unless-stopped
35+
networks:
36+
- bankai-network
2637
db:
2738
image: postgres:15-alpine
2839
env_file:
@@ -76,20 +87,22 @@ services:
7687
environment:
7788
- GF_SECURITY_ADMIN_USER=admin
7889
- GF_SECURITY_ADMIN_PASSWORD=secret
79-
# If you'd like to persist dashboards etc:
80-
# volumes:
81-
# - grafana_data:/var/lib/grafana
90+
volumes:
91+
- grafana_data:/var/lib/grafana
8292
restart: unless-stopped
8393

8494
volumes:
8595
postgres_data:
8696
name: postgres_data
8797
batches_data:
8898
name: batches_data
89-
# For Loki data, if you want persistence:
9099
loki_data:
91100
name: loki_data
92101
promtail_positions:
93-
name: promtail_positions
94-
# grafana_data:
95-
# name: grafana_data
102+
name: promtail_positions
103+
grafana_data:
104+
name: grafana_data
105+
106+
networks:
107+
bankai-network:
108+
driver: bridge

0 commit comments

Comments
 (0)
Please sign in to comment.