Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
610ef5d
Delete Jenkinsfile
mahmoud254 Aug 27, 2020
8b2943e
Set up CI with Azure Pipelines
mahmoud254 Sep 27, 2020
2acefbb
Update azure-pipelines.yml for Azure Pipelines
mahmoud254 Sep 27, 2020
9c47226
Delete azure-pipelines.yml
mahmoud254 Sep 27, 2020
1302d35
Update app.js
mahmoud254 Mar 21, 2021
e11cc9a
Create docker-image.yml
mahmoud254 Mar 25, 2021
59cc3ff
Update docker-image.yml
mahmoud254 Mar 25, 2021
b6fd82f
Update docker-image.yml
mahmoud254 Mar 25, 2021
0d9ff64
Update docker-image.yml
mahmoud254 Mar 25, 2021
480647e
Update docker-image.yml
mahmoud254 Mar 25, 2021
5aa4190
Update docker-image.yml
mahmoud254 Mar 25, 2021
a0ac5ff
Update docker-image.yml
mahmoud254 Mar 25, 2021
9662bca
Update docker-image.yml
mahmoud254 Mar 25, 2021
efc930a
Update app.js
mahmoud254 Mar 29, 2021
e0d1296
Delete docker-image.yml
mahmoud254 Mar 30, 2021
3fa7cde
Create docker-publish.yml
mahmoud254 Mar 30, 2021
ab7f6c0
Create Jenkinsfile
mahmoud254 May 4, 2021
b02d3bb
Delete Jenkinsfile
mahmoud254 May 4, 2021
7dec8c5
Create Jenkinsfile
mahmoud254 Sep 27, 2021
a308b44
Update Jenkinsfile
mahmoud254 Sep 27, 2021
d59b458
Update Jenkinsfile
mahmoud254 Sep 27, 2021
c7d5c97
Update Jenkinsfile
mahmoud254 Sep 27, 2021
3a1b8b2
Update Jenkinsfile
mahmoud254 Sep 27, 2021
9891c6f
Update Jenkinsfile
mahmoud254 Sep 27, 2021
0735e4d
Delete Jenkinsfile
mahmoud254 Sep 27, 2021
d17154a
Create Jenkinsfile
mahmoud254 Sep 28, 2021
a0c7b62
Update Jenkinsfile
mahmoud254 Sep 28, 2021
8527821
Update Jenkinsfile
mahmoud254 Sep 28, 2021
8b23b90
Delete Jenkinsfile
mahmoud254 Oct 6, 2021
d0d205b
Update app.js
mahmoud254 Jul 23, 2022
76b82f9
Update docker-publish.yml
mahmoud254 Feb 4, 2023
187822e
Update app.js
mahmoud254 May 6, 2023
6f0b360
Update app.js
mahmoud254 May 4, 2024
a409e93
Update app.js
mahmoud254 May 3, 2025
c622d0e
add k8s manifests
May 1, 2026
2d41994
gitaction added
May 2, 2026
49b58f7
app.js updated
May 5, 2026
dacd6e7
update DB connection
May 5, 2026
851dee4
add gitignore
May 6, 2026
8225228
update nodeapp
May 6, 2026
1e20dc4
update docker file
May 6, 2026
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
21 changes: 21 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Docker
on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master

jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run tests
run: |
docker build . --file dockerfile -t mahmom/jenkins_iti:v1.10
docker login -u ${{ secrets.DOCKER_USERNAME}} -p ${{secrets.DOCKER_PASSWORD}}
docker push mahmom/jenkins_iti:v1.10
61 changes: 61 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: nodejs-workflow

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:

testing:
runs-on: self-hosted
steps:
- name: checkout repo
uses: actions/checkout@v4

- name: SonarQube scan
uses: SonarSource/sonarqube-scan-action@v2
env:
SONAR_HOST_URL: http://localhost:9001
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.projectKey=nodejs-workflow
-Dsonar.sources=.

- name: Quality Gate
uses: SonarSource/sonarqube-quality-gate-action@v1
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

build:
needs: testing
runs-on: self-hosted
steps:
- name: checkout repo
uses: actions/checkout@v4

- name: docker login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: build image
run: |
docker build -t danamostafa/nodejs:latest .
docker push danamostafa/nodejs:latest

deployment:
needs: build
if: github.ref == 'refs/heads/master'
runs-on: self-hosted
steps:
- name: checkout repo
uses: actions/checkout@v4

- name: apply k8s manifest file
run: kubectl apply -f k8s/
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.scannerwork/
node_modules/
package-lock.json

25 changes: 0 additions & 25 deletions Jenkinsfile

This file was deleted.

11 changes: 8 additions & 3 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
FROM node:12
COPY nodeapp /nodeapp
FROM node:18

WORKDIR /nodeapp

COPY nodeapp/package*.json ./
RUN npm install
CMD ["node", "/nodeapp/app.js"]

COPY nodeapp .

CMD ["node", "app.js"]
10 changes: 10 additions & 0 deletions k8s/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-config
namespace: nodejs
data:
DB_HOST: mysql
DB_USER: root
DB_NAME: mydb
DB_PORT: "3306"
78 changes: 78 additions & 0 deletions k8s/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodejs-deployment
namespace: nodejs
labels:
app: backend

spec:
replicas: 2

selector:
matchLabels:
app: backend

template:
metadata:
labels:
app: backend

spec:
containers:
- name: nodejs
image: danamostafa/nodejs:latest

ports:
- containerPort: 3000

env:
- name: DB_HOST
valueFrom:
configMapKeyRef:
name: mysql-config
key: DB_HOST

- name: DB_USER
valueFrom:
configMapKeyRef:
name: mysql-config
key: DB_USER

- name: DB_NAME
valueFrom:
configMapKeyRef:
name: mysql-config
key: DB_NAME

- name: DB_PORT
valueFrom:
configMapKeyRef:
name: mysql-config
key: DB_PORT

- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secret
key: MYSQL_ROOT_PASSWORD

resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "250m"
memory: "256Mi"

readinessProbe:
httpGet:
path: /
port: 3000
initialDelaySeconds: 5

livenessProbe:
httpGet:
path: /
port: 3000
initialDelaySeconds: 10
12 changes: 12 additions & 0 deletions k8s/mysqlsev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: nodejs
spec:
clusterIP: None
selector:
app: mysql
ports:
- port: 3306
targetPort: 3306
14 changes: 14 additions & 0 deletions k8s/nodejsev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: nodejs
namespace: nodejs
spec:
type: NodePort
selector:
app: backend
ports:
- port: 3000
targetPort: 3000
nodePort: 30828

6 changes: 6 additions & 0 deletions k8s/ns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Namespace
metadata:
name: nodejs
labels:
name: development
13 changes: 13 additions & 0 deletions k8s/pv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
spec:
capacity:
storage: 1Gi

accessModes:
- ReadWriteOnce

hostPath:
path: /data/mysql
17 changes: 17 additions & 0 deletions k8s/pvc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
namespace: nodejs

spec:
volumeName: mysql-pv

storageClassName: ""

accessModes:
- ReadWriteOnce

resources:
requests:
storage: 1Gi
7 changes: 7 additions & 0 deletions k8s/secret.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: mysql-secret
namespace: nodejs
data:
MYSQL_ROOT_PASSWORD: bXlwYXNzd29yZA==
48 changes: 48 additions & 0 deletions k8s/statefulset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
namespace: nodejs

spec:
serviceName: mysql
replicas: 1

selector:
matchLabels:
app: mysql

template:
metadata:
labels:
app: mysql

spec:
containers:
- name: mysql
image: mysql:8.0

ports:
- containerPort: 3306

env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secret
key: MYSQL_ROOT_PASSWORD

- name: MYSQL_DATABASE
valueFrom:
configMapKeyRef:
name: mysql-config
key: DB_NAME

volumeMounts:
- name: mysql-storage
mountPath: /var/lib/mysql

volumes:
- name: mysql-storage
persistentVolumeClaim:
claimName: mysql-pvc
21 changes: 20 additions & 1 deletion nodeapp/app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
const mysql = require('mysql2');
const express = require('express')
const app = express()
const port = 3000
const host= process.env.DB_HOST
const user= process.env.DB_USER
const password= process.env.DB_PASSWORD
const database= process.env.DB_NAME;

const connection = mysql.createConnection({
host: host,
user: user,
password: password,
database: database
});
connection.connect((err) => {
if (err) throw err;
console.log('Connected!');
});

app.get('/', (req, res) => {
res.send('Hello World!')
})

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
})


5 changes: 4 additions & 1 deletion nodeapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1" }
"express": "^4.17.1",
"mysql": "^2.18.1",
"mysql2": "^3.22.3"
}
}