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
7 changes: 7 additions & 0 deletions .dockerignore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.env
.vs
npm_debug.log
.git
.gitignore
node_module
README.md
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .vs/ShopingKaro/v17/.wsuo
Binary file not shown.
12 changes: 12 additions & 0 deletions .vs/ShopingKaro/v17/DocumentLayout.backup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Version": 1,
"WorkspaceRootPath": "C:\\Users\\Poornima\\Documents\\Poornima\\Interview\\ShopingKaro\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}
37 changes: 37 additions & 0 deletions .vs/ShopingKaro/v17/DocumentLayout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"Version": 1,
"WorkspaceRootPath": "C:\\Users\\Poornima\\Documents\\Poornima\\Interview\\ShopingKaro\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\Poornima\\Documents\\Poornima\\Interview\\ShopingKaro\\Dockerfile.txt||{8B382828-6202-11D1-8870-0000F87579D2}",
"RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:Dockerfile.txt||{8B382828-6202-11D1-8870-0000F87579D2}"
}
],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 0,
"Children": [
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "Dockerfile.txt",
"DocumentMoniker": "C:\\Users\\Poornima\\Documents\\Poornima\\Interview\\ShopingKaro\\Dockerfile.txt",
"RelativeDocumentMoniker": "Dockerfile.txt",
"ToolTip": "C:\\Users\\Poornima\\Documents\\Poornima\\Interview\\ShopingKaro\\Dockerfile.txt",
"RelativeToolTip": "Dockerfile.txt",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAA8AAAAYAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.003109|",
"WhenOpened": "2025-05-23T10:51:30.993Z",
"EditorCaption": ""
}
]
}
]
}
]
}
7 changes: 7 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\package-lock.json",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
16 changes: 16 additions & 0 deletions Dockerfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#Stage 1: Build
FROM node:18-slim As builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY ..
#Stage 2: Production
FROM node:18-slim
#Non root user
RUN groupadd -r appuser && useradd -r appuser
WORKDIR /app
COPY --from=builder /app .
RUN chown -R appuser:appuser /app
USER appuser
EXPOSE 3000
CMD ["node", "index.js"]
36 changes: 36 additions & 0 deletions app-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: shopingkaro-app
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
selector:
matchLabels:
app: shopingkaro
template:
metadata:
labels:
app: shopingkaro
spec:
containers:
- name: shopingkaro
image: shopingkaro-backend:latest
ports:
- containerPort: 3000
env:
- name: DB_URI
valueFrom:
secretKeyRef:
name: mongodb-secret
key: uri
- name: NODE_ENV
valueFrom:
configMapKeyRef:
name: app-config
key: NODE_ENV

18 changes: 18 additions & 0 deletions app-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: shopingkaro-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: shopingkaro.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: shopingkaro-service
port:
number: 80
10 changes: 10 additions & 0 deletions app-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: shopingkaro-service
spec:
selector:
app: shopingkaro
ports:
- port: 80
targetPort: 3000
7 changes: 7 additions & 0 deletions configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
NODE_ENV: production
JWT_SECRET: supersecurejwtkey
18 changes: 18 additions & 0 deletions hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: shopingkaro-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: shopingkaro-app
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
10 changes: 10 additions & 0 deletions mongo-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongo-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
10 changes: 10 additions & 0 deletions mongo-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: mongo-service
spec:
ports:
- port: 27017
selector:
app: mongo
clusterIP: None
42 changes: 42 additions & 0 deletions mongo-statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mongo
spec:
serviceName: "mongo"
replicas: 1
selector:
matchLabels:
app: mongo
template:
metadata:
labels:
app: mongo
spec:
containers:
- name: mongo
image: mongo:6
ports:
- containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mongodb-secret
key: username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongodb-secret
key: password
volumeMounts:
- name: mongo-storage
mountPath: /data/db
volumeClaimTemplates:
- metadata:
name: mongo-storage
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 5Gi
44 changes: 44 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
#KhushiBaby Docker Optimization challenges
1. Key Optimization:
Multi-Stage Builds: Separates build and production stages to ensure only necessary files are included in the final image.

Slim Base Image: Utilizes node:18-slim to reduce image size.

Non-Root User: Runs the application as a non-root user (appuser) to enhance security.

Efficient Dependency Installation: Uses npm ci --omit=dev to install only production dependencies, ensuring faster and more reliable builds.

.dockerignore Usage: Excludes unnecessary files and directories from the Docker context to minimize image size.



2. Optimization reduced image size, leading to faster deployment and reduced resource consumption.


3.Security Checklist

Non-Root Execution: Application runs as a non-root user to limit potential vulnerabilities.

Minimal Base Image: Reduces attack surface by using a slim base image.

Exclusion of Dev Dependencies: Ensures only necessary packages are included in the production image.

.dockerignore: Prevents sensitive files (e.g., .env, .git) from being added to the image.


4. Building and running docker image locally
1. Clone the Repository:

2. Build the Docker Image:

docker build -t shopingkaro-app .


3. Run the Docker Container:

docker run -p 3000:3000 shopingkaro-app

The application will be accessible at http://localhost:3000.



# ShopingKaro

ShopingKaro is a web application developed in Node.js that allows users to easily browse and shop for various products. With a user-friendly interface and a variety of features, ShopingKaro aims to provide a seamless online shopping experience.
Expand Down
9 changes: 9 additions & 0 deletions secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: mongodb-secret
type: Opaque
data:
username: bW9uZ291c2Vy
password: c2VjcmV0cGFzcw==
uri: bW9uZ29kYjovL21vbmdvdXNlcjpzZWNyZXRwYXNzQG1vbmdvLXNlcnZpY2U6MjcwMTcvc2hvcGluZ2thcm8=