Skip to content

Commit ec7d724

Browse files
eyo-chenEyo Chen
andauthored
feat: add docker (#23)
Co-authored-by: Eyo Chen <[email protected]>
1 parent d2cd502 commit ec7d724

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
POLYGON_API_KEY=your_polygon_api_key
1+
MONGO_URL=mongodb://mongodb:27017

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM python:3.12-slim
2+
3+
WORKDIR /app
4+
5+
# Install dependencies
6+
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
curl \
8+
build-essential \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
# Install uv
12+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
13+
mv /root/.local/bin/uv /usr/local/bin/uv
14+
15+
# Ensure PATH includes /usr/local/bin
16+
ENV PATH="/usr/local/bin:$PATH"
17+
18+
# Copy project files
19+
COPY . .
20+
21+
# Run uv sync
22+
RUN uv sync --frozen --no-cache
23+
24+
# Expose port
25+
EXPOSE 50051
26+
27+
# Run the application
28+
CMD ["uv", "run", "src/index.py"]

src/index.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import logging
2+
import os
13
import grpc
24
import proto.stock_pb2_grpc as stock_pb2_grpc
35
from concurrent import futures
@@ -11,16 +13,22 @@
1113

1214
load_dotenv()
1315

16+
logger = logging.getLogger(__name__)
17+
logger.setLevel(logging.INFO)
18+
19+
1420

1521
def serve():
16-
client = MongoClient("mongodb://localhost:27017")
22+
client = MongoClient(os.getenv("MONGO_URI"))
23+
logger.info("connected to mongodb")
24+
1725
stock_repo = StockRepository(client, "stock_db")
1826
portfolio_repo = PortfolioRepository(client, "stock_db")
1927
stock_usecase = StockUsecase(stock_repo, portfolio_repo)
2028
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
2129
stock_pb2_grpc.add_StockServiceServicer_to_server(StockService(stock_usecase), server)
2230
server.add_insecure_port("[::]:50051")
23-
print("server is running...")
31+
logger.info("server is running...")
2432
server.start()
2533
server.wait_for_termination()
2634

0 commit comments

Comments
 (0)