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
49 changes: 49 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Full DevOps Flow

on:
push:
branches: [ main, feature-test-pipeline ]

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# 1. Setup Node and Test
- name: Install Dependencies
run: npm ci
- name: Run Tests
run: npm test

# 2. Build and Push to Docker Hub
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
push: true
# Replace 'geetesh' with your actual Docker Hub username
tags: ${{ secrets.DOCKERHUB_USERNAME }}/github-actions-demo:latest

# deploy-local:
# needs: build-and-push
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
#
# - name: Set Kubernetes Context
# uses: azure/k8s-set-context@v3
# with:
# method: kubeconfig
# kubeconfig: ${{ secrets.KUBE_CONFIG }}
#
# - name: Deploy to K8s
# # This will fail until your K8s cluster is reachable from the internet
# # But it's the correct way to write the script!
# run: kubectl apply -f k8s-deployment.yaml
8 changes: 8 additions & 0 deletions .idea/.gitignore

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

7 changes: 7 additions & 0 deletions .idea/dictionaries/project.xml

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

12 changes: 12 additions & 0 deletions .idea/github-actions-demo-project.iml

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

13 changes: 13 additions & 0 deletions .idea/material_theme_project_new.xml

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

8 changes: 8 additions & 0 deletions .idea/modules.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ubuntu:latest
LABEL authors="geetesh"

ENTRYPOINT ["top", "-b"]

# Step 1: Build the app
FROM node:20 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# Step 2: Run the app
FROM node:20-slim
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package*.json ./
RUN npm install --only=production

EXPOSE 3000
CMD ["node", "dist/index.js"]
31 changes: 31 additions & 0 deletions k8s-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo-app
spec:
replicas: 2
selector:
matchLabels:
app: demo
template:
metadata:
labels:
app: demo
spec:
containers:
- name: demo-app
image: geeteshs/github-actions-demo:latest
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: demo-service
spec:
type: LoadBalancer
selector:
app: demo
ports:
- port: 80
targetPort: 3000
6 changes: 6 additions & 0 deletions package-lock.json

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

42 changes: 22 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,41 @@ let server;
// setup cors.

app.use(
cors({
origin: "*",
credentials: true,
optionSuccessStatus: 200,
})
cors({
origin: "*",
credentials: true,
optionSuccessStatus: 200,
})
);

// setup body parser.

app.use(body.json({ limit: "100kb" }));
app.use(body.json({limit: "100kb"}));

// load all routes.

app.use("/recipes", require("./routes/recipes"));

async function startServer() {
try {
// Load express app to listen on config port.
const port = 3000
server = app.listen(port, () => {
console.log(`Service ready on :${port}`)
});
} catch (error) {
console.error("Failed to connect to the database:", error);
process.exit(1);
}
try {
// Load express app to listen on config port.
const port = 3000
server = app.listen(port, () => {
console.log(`Service ready on :${port}`)
});
} catch (error) {
console.error("Failed to connect to the database:", error);
process.exit(1);
}
}

function stop() {
console.log("Stopping server");
server.close();
console.log("Stopping server");
server.close();
}

export { server, startServer, stop };
export {server, startServer, stop};

startServer();
startServer().then(r =>{

});