diff --git a/.gitignore b/.gitignore index fb348d9..aa7f4f7 100644 --- a/.gitignore +++ b/.gitignore @@ -47,4 +47,7 @@ dist-ssr/ *.sw? # Ignore pnpm lock file -pnpm-lock.yaml \ No newline at end of file +pnpm-lock.yaml + +# ignore the temp folder +vision/temp diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..46043ae --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,45 @@ +version: "3.8" +services: + backend: + build: + context: . + dockerfile: vision/Dockerfile + volumes: + - .:/app + - temp-data:/app/vision/temp + env_file: + - .env + ports: + - "8000:8000" + depends_on: + - redis + + worker: + build: + context: . + dockerfile: vision/Dockerfile + command: celery -A vision.config.celery_worker.celery_app worker --loglevel=info + env_file: + - .env + depends_on: + - redis + volumes: + - .:/app + - temp-data:/app/vision/temp + + frontend: + build: + context: ./frontend + dockerfile: Dockerfile + ports: + - "3000:80" + depends_on: + - backend + + redis: + image: redis:7 + # ports: + # - "6379:6379" + +volumes: + temp-data: diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..ae7a262 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,14 @@ +# Build stage +FROM node:18 AS build +WORKDIR /app +COPY package.json pnpm-lock.yaml ./ +RUN npm install -g pnpm && pnpm install +COPY . . +RUN pnpm run build + +# Serve with nginx +FROM nginx:alpine +COPY --from=build /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/frontend/nginx.conf b/frontend/nginx.conf new file mode 100644 index 0000000..2153caa --- /dev/null +++ b/frontend/nginx.conf @@ -0,0 +1,14 @@ +server { + listen 80; + server_name _; + root /usr/share/nginx/html; + + location / { + try_files $uri $uri/ /index.html; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} diff --git a/k8s/backend-deployment.yaml b/k8s/backend-deployment.yaml new file mode 100644 index 0000000..06e52bc --- /dev/null +++ b/k8s/backend-deployment.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: backend +spec: + replicas: 1 + selector: + matchLabels: + app: backend + template: + metadata: + labels: + app: backend + spec: + containers: + - name: backend + image: sumansahoo/qualiscan-backend:latest + ports: + - containerPort: 8000 + envFrom: + - secretRef: + name: backend-env diff --git a/k8s/backend-service.yaml b/k8s/backend-service.yaml new file mode 100644 index 0000000..2b04ed9 --- /dev/null +++ b/k8s/backend-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: backend +spec: + selector: + app: backend + ports: + - protocol: TCP + port: 8000 + targetPort: 8000 + type: ClusterIP diff --git a/k8s/frontend-deployment.yaml b/k8s/frontend-deployment.yaml new file mode 100644 index 0000000..0b15c14 --- /dev/null +++ b/k8s/frontend-deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: frontend +spec: + replicas: 1 + selector: + matchLabels: + app: frontend + template: + metadata: + labels: + app: frontend + spec: + containers: + - name: frontend + image: sumansahoo/qualiscan-frontend:latest + ports: + - containerPort: 80 diff --git a/k8s/frontend-service.yaml b/k8s/frontend-service.yaml new file mode 100644 index 0000000..638d7ce --- /dev/null +++ b/k8s/frontend-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: frontend +spec: + selector: + app: frontend + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: ClusterIP diff --git a/k8s/ingress.yaml b/k8s/ingress.yaml new file mode 100644 index 0000000..5db6454 --- /dev/null +++ b/k8s/ingress.yaml @@ -0,0 +1,25 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: qualiscan-ingress + annotations: + nginx.ingress.kubernetes.io/rewrite-target: /$1 +spec: + rules: + - host: qualiscan.local + http: + paths: + - pathType: Prefix + path: /api/(.*) + backend: + service: + name: backend + port: + number: 8000 + - pathType: Prefix + path: /(.*) + backend: + service: + name: frontend + port: + number: 80 diff --git a/k8s/redis-deployment.yaml b/k8s/redis-deployment.yaml new file mode 100644 index 0000000..c92c691 --- /dev/null +++ b/k8s/redis-deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redis +spec: + replicas: 1 + selector: + matchLabels: + app: redis + template: + metadata: + labels: + app: redis + spec: + containers: + - name: redis + image: redis:7 + ports: + - containerPort: 6379 diff --git a/k8s/redis-service.yaml b/k8s/redis-service.yaml new file mode 100644 index 0000000..9229df1 --- /dev/null +++ b/k8s/redis-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: redis +spec: + selector: + app: redis + ports: + - protocol: TCP + port: 6379 + targetPort: 6379 + type: ClusterIP diff --git a/k8s/worker-deployment.yaml b/k8s/worker-deployment.yaml new file mode 100644 index 0000000..9c28360 --- /dev/null +++ b/k8s/worker-deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: worker +spec: + replicas: 1 + selector: + matchLabels: + app: worker + template: + metadata: + labels: + app: worker + spec: + containers: + - name: worker + image: sumansahoo/qualiscan-backend:latest + command: ["celery", "-A", "vision.config.celery_worker.celery_app", "worker", "--loglevel=info"] + envFrom: + - secretRef: + name: backend-env diff --git a/requirements.txt b/requirements.txt index 323ef8c..8b3092f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,21 @@ +fastapi +uvicorn +opencv-python +numpy +pillow python-dotenv -requests \ No newline at end of file +google-generativeai +langchain-core +dataclasses-json +google-ai-generativelanguage +requests +charset-normalizer +backoff +supervision +pymongo +langchain-google-genai +aiohttp +celery[redis] +redis +inference-sdk +python-multipart diff --git a/vision/Dockerfile b/vision/Dockerfile new file mode 100644 index 0000000..7cb8fa7 --- /dev/null +++ b/vision/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.10-slim + +WORKDIR /app + +# Install system dependencies for OpenCV and threading +RUN apt-get update && apt-get install -y libgl1 libglib2.0-0 && rm -rf /var/lib/apt/lists/* + +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +EXPOSE 8000 + +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/vision/config/celery_worker.py b/vision/config/celery_worker.py index 6158e91..0fe5835 100644 --- a/vision/config/celery_worker.py +++ b/vision/config/celery_worker.py @@ -2,8 +2,8 @@ celery_app = Celery( "vision", - broker="redis://localhost:6379/0", # or your Redis/RabbitMQ URL - backend="redis://localhost:6379/0" + broker="redis://redis:6379/0", # or your Redis/RabbitMQ URL + backend="redis://redis:6379/0" ) # Include tasks modules