diff --git a/README.md b/README.md index 1190272..3e46863 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,22 @@ Based on the dataset from : [Huge Stock Market Dataset](https://www.kaggle.com/d ## Getting Started -### Running the Database +### With Docker Compose (Recommended) + +Start both database and Rust server: + +```bash +docker-compose up --build +``` + +The Rust server is now available on `http://localhost:4444` + +### Running only the Database Start the database using Docker Compose: ```bash -docker-compose up -d +docker-compose up -d timescaledb ``` This will start a PostgreSQL + TimescaleDB instance on port 5432 with default credentials: @@ -29,3 +39,9 @@ To stop the database: docker-compose down ``` +### Running Servers Individually + +For detailed instructions on running each server locally: + +- **Rust Server**: See [servers/rust-server/README.md](servers/rust-server/README.md) +- **Python Server**: See [servers/python-server/README.md](servers/python-server/README.md) \ No newline at end of file diff --git a/data-ingestion/README.md b/data-ingestion/README.md index 1852348..1f631e0 100644 --- a/data-ingestion/README.md +++ b/data-ingestion/README.md @@ -6,7 +6,7 @@ Data pipeline to ingest stock market datasets into a Time Series Database. ### Prerequisites -1. Make sure the Database is running (to startup the database look [here](../README.md#running-the-database)) +1. Make sure the Database is running (to startup the database look [here](../README.md#running-only-the-database)) 2. Defines the required environment variables ```sh diff --git a/docker-compose.yml b/docker-compose.yml index 3e04360..6a1c7db 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,24 @@ services: POSTGRES_DB: ${POSTGRES_DB:-finwar} volumes: - db_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U finwar"] + interval: 5s + timeout: 5s + retries: 5 + + rust-server: + build: + context: ./servers/rust-server + dockerfile: Dockerfile + ports: + - "4444:4444" + environment: + DATABASE_URL: postgresql://${POSTGRES_USER:-finwar}:${POSTGRES_PASSWORD:-password}@timescaledb:5432/${POSTGRES_DB:-finwar} + RUST_LOG: info + depends_on: + timescaledb: + condition: service_healthy volumes: db_data: diff --git a/servers/rust-server/Dockerfile b/servers/rust-server/Dockerfile new file mode 100644 index 0000000..106f746 --- /dev/null +++ b/servers/rust-server/Dockerfile @@ -0,0 +1,60 @@ +FROM docker.io/library/rust:1.89-slim-bookworm AS base + +RUN apt-get update && apt-get install -y \ + pkg-config \ + libssl-dev \ + && rm -rf /var/lib/apt/lists/* + +RUN cargo install cargo-chef --version ^0.1 +RUN cargo install sccache --version ^0.7 + +ENV RUSTC_WRAPPER=sccache SCCACHE_DIR=/sccache + +FROM base AS planner +WORKDIR /app +COPY Cargo.toml Cargo.lock ./ +COPY entity ./entity +COPY migration ./migration +COPY src ./src +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=$SCCACHE_DIR,sharing=locked \ + cargo chef prepare --recipe-path recipe.json + +FROM base AS builder + +WORKDIR /build + +COPY --from=planner /app/recipe.json recipe.json +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=$SCCACHE_DIR,sharing=locked \ + cargo chef cook --release --recipe-path recipe.json + +COPY Cargo.toml Cargo.lock ./ +COPY local ./local +COPY templates ./templates +COPY entity ./entity +COPY migration ./migration +COPY src ./src + +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=$SCCACHE_DIR,sharing=locked \ + cargo build --release + +FROM debian:bookworm-slim + +RUN apt-get update && apt-get install -y \ + ca-certificates \ + libssl3 \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY --from=builder /build/target/release/finwar-market /app/finwar-market +COPY templates ./templates +COPY local ./local + +ENV RUST_LOG=info + +EXPOSE 4444 + +CMD ["/app/finwar-market"] \ No newline at end of file diff --git a/servers/rust-server/README.md b/servers/rust-server/README.md index 9434c55..2ab6105 100644 --- a/servers/rust-server/README.md +++ b/servers/rust-server/README.md @@ -23,7 +23,7 @@ cargo install sea-orm-cli ### Database Operations ```bash # Start PostgreSQL container -docker-compose up -d +docker-compose up -d timescaledb # Run migrations (from migration/ directory) sea-orm-cli migrate down @@ -40,11 +40,33 @@ sea-orm-cli migrate reset ``` ### Environment Setup -- Set `DATABASE_URL=postgres://finwar:password@localhost/finwar` +- Set `DATABASE_URL=postgres://finwar:password@localhost/finwar` as an env variable or in a .env - Default server runs on `0.0.0.0:4444` - Stock data loaded from `./local/data/Stocks/` directory ### Running the Server + +#### Local Development ```bash -cargo run # Runs migrations automatically on startup -``` \ No newline at end of file +cargo run +``` + +#### Docker + +**Build the image:** +```bash +docker build -t finwar-rust-server . +``` + +**Run only the server container:** +```bash +docker run -p 4444:4444 -e DATABASE_URL=postgresql://finwar:password@host.docker.internal:5432/finwar finwar-rust-server +``` + +**Or use docker-compose (recommended):** +```bash +# From project root +docker-compose up rust-server +``` + +This starts both the database and Rust server with proper networking. \ No newline at end of file