Skip to content
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
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
2 changes: 1 addition & 1 deletion data-ingestion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
60 changes: 60 additions & 0 deletions servers/rust-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je crois pas que tu ais besoin de local dans la compilation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pas sur de comprendre ce comment

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"]
30 changes: 26 additions & 4 deletions servers/rust-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
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.