Skip to content
Open
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ node_modules
dist
dist-ssr
*.local
.env

# Editor directories and files
.vscode/*
!.vscode/extensions.json
Expand All @@ -21,4 +21,4 @@ dist-ssr
*.ntvs*
*.njsproj
*.sln
*.sw?
*.sw?
4 changes: 4 additions & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
.git
.env
4 changes: 4 additions & 0 deletions client/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
VITE_SERVER_ENDPOINT = http://51.20.77.21:3000/api
VITE_TOKEN_KEY = thinkify
VITE_USER_ROLE = role
VITE_COOKIE_EXPIRES = 1
31 changes: 31 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ---- Build Stage ----
FROM node:20-alpine AS build

WORKDIR /app

COPY package.json .
RUN npm install

COPY . .

ARG VITE_SERVER_ENDPOINT
ARG VITE_TOKEN_KEY
ARG VITE_USER_ROLE
ARG VITE_COOKIE_EXPIRES

ENV VITE_SERVER_ENDPOINT=$VITE_SERVER_ENDPOINT
ENV VITE_TOKEN_KEY=$VITE_TOKEN_KEY
ENV VITE_USER_ROLE=$VITE_USER_ROLE
ENV VITE_COOKIE_EXPIRES=$VITE_COOKIE_EXPIRES

RUN npm run build

# ---- Serve Stage ----
FROM nginx:1.25-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;"]
29 changes: 29 additions & 0 deletions client/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
server {
listen 80;
server_name _;

root /usr/share/nginx/html;
index index.html;

# Docker's internal DNS resolver — forces nginx to re-resolve at runtime
resolver 127.0.0.11 valid=10s;

# Proxy all /api requests to the Express backend
location /api {
set $upstream http://server:3000;
proxy_pass $upstream;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
}

# React Router fallback
location / {
try_files $uri $uri/ /index.html;
}

gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
}
15 changes: 1 addition & 14 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
version: '3.8'

services:

mongodb:
image: mongo:7
container_name: thinkify-mongodb
restart: unless-stopped
volumes:
- mongo_data:/data/db
networks:
- thinkify-net

server:
build:
context: ./server
dockerfile: Dockerfile
container_name: thinkify-server
restart: unless-stopped
ports:
- "3000:3000"
environment:
PORT: 3000
DATABASE_URL: mongodb://mongodb:27017/
DATABASE_NAME: thinkify
BCRYPT_GEN_SALT_NUMBER: 10
JWT_SECRET_KEY: thinkify_super_secret_jwt_key_2024
COOKIE_EXPIRES: 5d
COOKIE_KEY: thinkify
UPLOAD_DIRECTORY: uploads
CLIENT_ORIGIN: http://51.20.77.21
volumes:
- uploads_data:/app/uploads
depends_on:
- mongodb
networks:
- thinkify-net

client:
build:
context: ./client
dockerfile: Dockerfile
args:
VITE_SERVER_ENDPOINT: http://51.20.77.21/api
VITE_TOKEN_KEY: thinkify
VITE_USER_ROLE: role
VITE_COOKIE_EXPIRES: 1
container_name: thinkify-client
restart: unless-stopped
ports:
- "80:80"
depends_on:
- server
networks:
- thinkify-net

volumes:
mongo_data:
uploads_data:

networks:
thinkify-net:
driver: bridge
46 changes: 46 additions & 0 deletions k8s/apply.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
set -e

echo "==> Namespace"
kubectl apply -f namespace.yml

echo "==> ConfigMap"
kubectl apply -f config-map.yml

echo "==> Secret"
kubectl apply -f secret.yml

echo "==> MongoDB Service (Headless)"
kubectl apply -f mongodb-service.yml

echo "==> MongoDB StatefulSet"
kubectl apply -f mongodb-statfulset.yml

echo "==> Waiting for MongoDB..."
kubectl rollout status statefulset/mongodb -n thinkify --timeout=120s

echo "==> PVC"
kubectl apply -f pvc.yml

echo "==> Server Deployment"
kubectl apply -f server-deployment.yml

echo "==> Server Service"
kubectl apply -f server-service.yml

echo "==> Waiting for Server..."
kubectl rollout status deployment/server -n thinkify --timeout=60s

echo "==> Client Deployment"
kubectl apply -f client-deployment.yml

echo "==> Client Service"
kubectl apply -f client-service.yml

echo "==> Ingress"
kubectl apply -f ingress.yml

echo ""
echo "Done. App: http://51.20.77.21"
echo "Pods: kubectl get pods -n thinkify"
echo "Ingress: kubectl get ingress -n thinkify"
36 changes: 36 additions & 0 deletions k8s/client-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: client
namespace: thinkify
labels:
app: client
spec:
replicas: 1
selector:
matchLabels:
app: client
template:
metadata:
labels:
app: client
spec:
containers:
- name: client
image: manthan010/thinkify-client:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "200m"
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 5
15 changes: 15 additions & 0 deletions k8s/client-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: client
namespace: thinkify
labels:
app: client
spec:
type: ClusterIP
selector:
app: client
ports:
- name: http
port: 80
targetPort: 80
13 changes: 13 additions & 0 deletions k8s/config-map.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: thinkify-config
namespace: thinkify
data:
PORT: "3000"
DATABASE_NAME: "thinkify"
BCRYPT_GEN_SALT_NUMBER: "10"
COOKIE_EXPIRES: "5d"
COOKIE_KEY: "thinkify"
UPLOAD_DIRECTORY: "uploads"
CLIENT_ORIGIN: "http://51.20.77.21"
Loading