Skip to content
Merged
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
57 changes: 45 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ on:

permissions:
contents: read
packages: write # --> Allows Github Actions to upload to the Container Registery
packages: write

jobs:
lint-and-typecheck:
name: Lint & Typecheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run ESLint
run: npm run lint

- name: Typecheck
run: npx tsc --noEmit

Expand All @@ -38,21 +38,21 @@ jobs:
needs: [lint-and-typecheck]
steps:
- uses: actions/checkout@v4
- name: Login to Container Registery

- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Lowercase Repository Name
run: |
echo "REPO=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}

- name: Build Docker Image
- name: Lowercase repository name
run: echo "REPO=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}

- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
Expand All @@ -68,3 +68,36 @@ jobs:
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=${{ secrets.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET }}
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID }}
NEXT_PUBLIC_FIREBASE_APP_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_APP_ID }}

kubernetes-validate:
name: K8s Manifest Check
runs-on: ubuntu-latest
needs: [docker-build-test]
steps:
- uses: actions/checkout@v4

- name: Install kubeval with local schemas
run: |
wget -q https://github.com/instrumenta/kubeval/releases/download/v0.16.1/kubeval-linux-amd64.tar.gz
tar xf kubeval-linux-amd64.tar.gz
sudo mv kubeval /usr/local/bin/kubeval
wget -q https://github.com/instrumenta/kubernetes-json-schema/archive/refs/heads/master.zip
unzip -q master.zip
echo "SCHEMA_DIR=$(pwd)/kubernetes-json-schema-master" >> $GITHUB_ENV

- name: Validate K8s manifests
run: |
kubeval --schema-location file://${SCHEMA_DIR} kubernetes/deployment.yaml
kubeval --schema-location file://${SCHEMA_DIR} kubernetes/service.yaml
kubeval --ignore-missing-schemas kubernetes/ingress.yaml

deploy:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [kubernetes-validate]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4

- name: Deploy
run: echo "K8s deployment triggered for $(git rev-parse --short HEAD)"
32 changes: 32 additions & 0 deletions KUBERNETES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kubernetes: The Infrastructure Finale

SystemCraft's journey started with **Docker** for isolation, moved to **Nginx** for reverse proxying, and now concludes with **Kubernetes** for robust orchestration.

## 📁 Manifests Structure
- `deployment.yaml`: Defing a 3-replica stateful-ready application with resource limits.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix typo in manifest description.

Line 6 has a spelling error: DefingDefining.

✍️ Suggested doc fix
-- `deployment.yaml`: Defing a 3-replica stateful-ready application with resource limits.
+- `deployment.yaml`: Defining a 3-replica stateful-ready application with resource limits.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- `deployment.yaml`: Defing a 3-replica stateful-ready application with resource limits.
- `deployment.yaml`: Defining a 3-replica stateful-ready application with resource limits.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@KUBERNETES.md` at line 6, Fix the typo in the KUBERNETES.md description for
`deployment.yaml`: change the word "Defing" to "Defining" in the line that reads
"`deployment.yaml`: Defing a 3-replica stateful-ready application with resource
limits." so the manifest description is correct.

- `service.yaml`: Internal connectivity via `ClusterIP`.
- `ingress.yaml`: External routing via Nginx Ingress Controller (completing the Nginx journey).

## 🚀 Deployment Strategy
The CI/CD pipeline in `.github/workflows/ci.yml` is now integrated with these manifests:
1. **Validation**: Every PR dry-runs the manifests to ensure zero syntax errors.
2. **Build**: Docker images are pushed to GitHub Container Registry (GHCR).
3. **Deploy**: Push to `main` triggers the deployment notification.

## 🛠️ Local Testing (Minikube/Kind)
To test the manifests locally:

```bash
# Create namespace
kubectl create namespace system-craft

# Apply manifests
kubectl apply -f kubernetes/ -n system-craft

# Verify pods
kubectl get pods -n system-craft
```

---

*This completes the full cycle: Dev -> Containerize -> Proxy -> Orchestrate.*
43 changes: 43 additions & 0 deletions kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: system-craft
labels:
app: system-craft
spec:
replicas: 3
selector:
matchLabels:
app: system-craft
template:
metadata:
labels:
app: system-craft
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1001
containers:
- name: system-craft
image: ghcr.io/shashank0701-byte/system-craft/systemcraft-web:latest
ports:
- containerPort: 3000
resources:
limits:
cpu: "500m"
memory: "512Mi"
requests:
cpu: "250m"
memory: "256Mi"
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
env:
- name: NODE_ENV
value: "production"
- name: MONGODB_URL
valueFrom:
secretKeyRef:
name: mongodb-secret
key: uri
23 changes: 23 additions & 0 deletions kubernetes/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: system-craft-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
tls:
- hosts:
- system-craft-kohl.vercel.app
secretName: system-craft-tls
rules:
- host: system-craft-kohl.vercel.app
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: system-craft-service
port:
number: 80
12 changes: 12 additions & 0 deletions kubernetes/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: system-craft-service
spec:
selector:
app: system-craft
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: ClusterIP
Binary file added recent_changes.txt
Binary file not shown.
Loading
Loading