Skip to content

Commit a9127dc

Browse files
committed
fix: fixed dockerfile for security and made google cloud compliant
1 parent 17fe6a8 commit a9127dc

5 files changed

Lines changed: 70 additions & 18 deletions

File tree

Dockerfile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@ FROM python:3.12-slim
33
WORKDIR /app
44

55
# Set environment variables
6-
ENV APP_NAME=rag_chat_api
7-
ENV PYTHONDONTWRITEBYTECODE=1
8-
ENV PYTHONUNBUFFERED=1
6+
ENV APP_NAME=rag_chat_api \
7+
PYTHONDONTWRITEBYTECODE=1 \
8+
PYTHONUNBUFFERED=1 \
9+
# GOOGLE_API_KEY and GITHUB_TOKEN should be passed securely at runtime
10+
CHROMA_PATH=/app/db/chroma \
11+
DATA_STORE_PATH=/app/db/knowledge_base
912

1013
# Install system dependencies
1114
RUN apt-get update && apt-get install -y --no-install-recommends \
1215
build-essential \
1316
libmagic1 \
14-
&& apt-get clean \
1517
&& rm -rf /var/lib/apt/lists/*
1618

1719
# Create necessary directories with proper permissions
18-
RUN mkdir -p db/chroma && \
19-
chmod -R 755 db
20+
RUN mkdir -p /app/db/chroma && \
21+
chmod -R 755 /app/db
2022

21-
# IMPORTANT: Copy and install requirements first
23+
# Copy and install requirements first to leverage caching
2224
COPY requirements.txt .
2325
RUN pip install --no-cache-dir -r requirements.txt
2426

2527
# Copy pre-built ChromaDB (if it exists locally)
2628
COPY db/chroma /app/db/chroma
27-
28-
# Set proper permissions for the ChromaDB
2929
RUN chmod -R 755 /app/db/chroma
3030

3131
# Copy configuration files
32-
COPY .env.prod ./.env.prod
33-
COPY docker-entrypoint.sh ./
34-
RUN chmod +x ./docker-entrypoint.sh
32+
COPY .env.prod /app/.env.prod
33+
COPY docker-entrypoint.sh /app/
34+
RUN chmod +x /app/docker-entrypoint.sh
3535

3636
# Copy source code
37-
COPY embeddings.py api.py ./
37+
COPY embeddings.py api.py /app/
3838

3939
# Expose the API port
4040
EXPOSE 8000
4141

4242
# Command to run the application
43-
ENTRYPOINT ["./docker-entrypoint.sh"]
43+
ENTRYPOINT ["/app/docker-entrypoint.sh"]
4444
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]

Dockerfile.bak

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
FROM python:3.12-slim
2+
3+
WORKDIR /app
4+
5+
# Set environment variables
6+
ENV APP_NAME=rag_chat_api
7+
ENV PYTHONDONTWRITEBYTECODE=1
8+
ENV PYTHONUNBUFFERED=1
9+
10+
# Install system dependencies
11+
RUN apt-get update && apt-get install -y --no-install-recommends \
12+
build-essential \
13+
libmagic1 \
14+
&& apt-get clean \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
# Create necessary directories with proper permissions
18+
RUN mkdir -p db/chroma && \
19+
chmod -R 755 db
20+
21+
# IMPORTANT: Copy and install requirements first
22+
COPY requirements.txt .
23+
RUN pip install --no-cache-dir -r requirements.txt
24+
25+
# Copy pre-built ChromaDB (if it exists locally)
26+
COPY db/chroma /app/db/chroma
27+
28+
# Set proper permissions for the ChromaDB
29+
RUN chmod -R 755 /app/db/chroma
30+
31+
# Copy configuration files
32+
COPY .env.prod ./.env.prod
33+
COPY docker-entrypoint.sh ./
34+
RUN chmod +x ./docker-entrypoint.sh
35+
36+
# Copy source code
37+
COPY embeddings.py api.py ./
38+
39+
# Expose the API port
40+
EXPOSE 8000
41+
42+
# Command to run the application
43+
ENTRYPOINT ["./docker-entrypoint.sh"]
44+
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]

deploy.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ set -e
55
./prepare-db.sh
66

77
# Build and start the Docker containers
8-
docker-compose up -d
8+
# docker-compose up -d
9+
10+
docker buildx build \
11+
--platform linux/amd64 \
12+
-t rndmcodeguy/rag-chat-api:v1.0.2 \
13+
--build-arg GOOGLE_API_KEY=$GOOGLE_API_KEY \
14+
--build-arg GITHUB_TOKEN=$GITHUB_TOKEN \
15+
--build-arg CHROMA_PATH=$CHROMA_PATH \
16+
--build-arg DATA_STORE_PATH=$DATA_STORE_PATH \
17+
--push . \
918

1019
echo "API is running at http://localhost:8000"
1120
echo "To test it, try: curl -X POST http://localhost:8000/query -H 'Content-Type: application/json' -d '{\"query\":\"How to install rcg?\"}'"

docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ services:
22
api:
33
build: .
44
container_name: api
5+
image: rndmcodeguy/rag-chat-api:v1.0.1
56
ports:
67
- "8000:8000"
78
volumes:
@@ -11,6 +12,7 @@ services:
1112
- CHROMA_PATH=/app/db/chroma
1213
- DATA_STORE_PATH=/app/db/knowledge_base
1314
- GOOGLE_API_KEY=${GOOGLE_API_KEY}
15+
- GITHUB_TOKEN=${GITHUB_TOKEN}
1416
restart: unless-stopped
1517

1618
volumes:

prepare-db.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#!/bin/bash
22
set -e
33

4-
# Fetch the latest docs from source
5-
6-
74
# Ensure the ChromaDB exists locally
85
if [ ! -d "db/chroma" ] || [ ! "$(ls -A db/chroma)" ]; then
96
echo "No ChromaDB found. Generating embeddings..."

0 commit comments

Comments
 (0)