From 08712b608724611c102d533665447b85372db1bd Mon Sep 17 00:00:00 2001 From: heisdinesh Date: Sun, 31 Aug 2025 23:08:00 +0530 Subject: [PATCH 1/2] chore: 1st iteration of docker setup. --- Dockerfile.api | 17 +++++++++++++++++ Dockerfile.ui | 32 ++++++++++++++++++++++++++++++++ docker-compose.yml | 20 ++++++++++++++++++++ src/api/__init__.py | 2 +- 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 Dockerfile.api create mode 100644 Dockerfile.ui create mode 100644 docker-compose.yml diff --git a/Dockerfile.api b/Dockerfile.api new file mode 100644 index 0000000..857c371 --- /dev/null +++ b/Dockerfile.api @@ -0,0 +1,17 @@ +FROM python:3.11-slim + +WORKDIR /app + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY src ./src + +ENV KINFIN_PORT=8000 +ENV RESULTS_BASE_DIR=/data/output +ENV SESSION_INACTIVITY_THRESHOLD=24 +ENV KINFIN_LIMIT_INIT=1/minute +ENV KINFIN_LIMIT_STANDARD=60/minute +ENV KINFIN_LIMIT_LOW=300/minute + +CMD ["python", "src/main.py", "serve", "-p", "8000"] diff --git a/Dockerfile.ui b/Dockerfile.ui new file mode 100644 index 0000000..c003e4e --- /dev/null +++ b/Dockerfile.ui @@ -0,0 +1,32 @@ +# FROM node:18-alpine +# WORKDIR /app + +# COPY src/ui/package*.json ./ +# RUN npm install --legacy-peer-deps + +# COPY src/ui ./ +# RUN npm run build + +# # install 'serve' globally +# RUN npm install -g serve + +# EXPOSE 3000 +# CMD ["serve", "-s", "dist", "-l", "3000"] +# Frontend: KinFin UI +FROM node:20-alpine + +WORKDIR /app + +# Install deps +COPY src/ui/package*.json ./ +RUN npm install --legacy-peer-deps + +# Copy frontend code +COPY src/ui/ ./ + +# Build static files +RUN npm run build + +# Serve using vite preview +EXPOSE 5173 +CMD ["npm", "run", "preview", "--", "--host", "0.0.0.0", "--port", "5173"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..04d5e6c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +services: + api: + build: + context: . + dockerfile: Dockerfile.api + container_name: kinfin-api + volumes: + - ./data:/app/data + ports: + - "8000:8000" # change if your API uses a different port + depends_on: + - ui + + ui: + build: + context: . + dockerfile: Dockerfile.ui + container_name: kinfin-ui + ports: + - "5173:80" diff --git a/src/api/__init__.py b/src/api/__init__.py index 2603a62..2793a9c 100644 --- a/src/api/__init__.py +++ b/src/api/__init__.py @@ -82,4 +82,4 @@ def hello(): app.include_router(router) - uvicorn.run(app=app, port=args.port) + uvicorn.run(app=app, host="0.0.0.0", port=args.port) From 9fb1ee43e8f7bb42a20edc0c907fe769847cb3ec Mon Sep 17 00:00:00 2001 From: heisdinesh Date: Thu, 4 Sep 2025 14:29:58 +0530 Subject: [PATCH 2/2] fix: 1. UI routes can be refreshed, added nginx conf. 2. Path issue fixed in Dockerfile.api --- Dockerfile.api | 4 ++-- Dockerfile.ui | 31 +++++++------------------------ docker-compose.yml | 7 ++++--- nginx.conf | 10 ++++++++++ 4 files changed, 23 insertions(+), 29 deletions(-) create mode 100644 nginx.conf diff --git a/Dockerfile.api b/Dockerfile.api index 857c371..befe178 100644 --- a/Dockerfile.api +++ b/Dockerfile.api @@ -6,9 +6,9 @@ COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY src ./src - +ENV KINFIN_WORKDIR=/kinfin ENV KINFIN_PORT=8000 -ENV RESULTS_BASE_DIR=/data/output +ENV RESULTS_BASE_DIR=/kinfin/output ENV SESSION_INACTIVITY_THRESHOLD=24 ENV KINFIN_LIMIT_INIT=1/minute ENV KINFIN_LIMIT_STANDARD=60/minute diff --git a/Dockerfile.ui b/Dockerfile.ui index c003e4e..dcb5f88 100644 --- a/Dockerfile.ui +++ b/Dockerfile.ui @@ -1,32 +1,15 @@ -# FROM node:18-alpine -# WORKDIR /app -# COPY src/ui/package*.json ./ -# RUN npm install --legacy-peer-deps - -# COPY src/ui ./ -# RUN npm run build - -# # install 'serve' globally -# RUN npm install -g serve - -# EXPOSE 3000 -# CMD ["serve", "-s", "dist", "-l", "3000"] -# Frontend: KinFin UI -FROM node:20-alpine +FROM node:20-alpine AS build WORKDIR /app - -# Install deps COPY src/ui/package*.json ./ RUN npm install --legacy-peer-deps - -# Copy frontend code COPY src/ui/ ./ - -# Build static files RUN npm run build -# Serve using vite preview -EXPOSE 5173 -CMD ["npm", "run", "preview", "--", "--host", "0.0.0.0", "--port", "5173"] +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/docker-compose.yml b/docker-compose.yml index 04d5e6c..1edb8ef 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,10 +6,9 @@ services: container_name: kinfin-api volumes: - ./data:/app/data + - /home/dinesh/tmp/kinfin:/kinfin # FIXED path ports: - - "8000:8000" # change if your API uses a different port - depends_on: - - ui + - "8000:8000" ui: build: @@ -18,3 +17,5 @@ services: container_name: kinfin-ui ports: - "5173:80" + depends_on: + - api diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..4f90f67 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,10 @@ +server { + listen 80; + + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri /index.html; + } +}