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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ COPY . .

RUN pip install -r "requirements.txt"

EXPOSE 8080
EXPOSE 5500

ENTRYPOINT ["python", "lbg.py"]
77 changes: 69 additions & 8 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,80 @@
pipeline {
agent any
stages {
stage('Init') {
steps {
script {
if (env.GIT_BRANCH == 'origin/main') {
sh'''
kubectl create ns prod || echo "----- prod namespace already exists -----"
'''
} else if (env.GIT_BRANCH == 'origin/dev') {
sh'''
kubectl create ns dev || echo "----- dev namespace already exists -----"
'''
} else {
sh'echo "unrecognised branch"'
}
}
}
}
stage('Build') {
steps {
sh '''

'''
}
script {
if (env.GIT_BRANCH == 'origin/main') {
sh'''
docker build -t rhyssevans/rhys-project-jenk:latest -t rhyssevans/rhys-project-jenk:v${BUILD_NUMBER} .
'''
} else if (env.GIT_BRANCH == 'origin/dev') {
sh'''
docker build -t rhyssevans/rhys-project-jenk:latest -t rhyssevans/rhys-project-jenk:v${BUILD_NUMBER} .
'''
} else {
sh'echo "unrecognised branch"'
}
}
}
}


stage('Push') {
steps {
script {
if (env.GIT_BRANCH == 'origin/main') {
sh'''
docker push rhyssevans/rhys-project-jenk:latest
docker push rhyssevans/rhys-project-jenk:v${BUILD_NUMBER}
'''
} else if (env.GIT_BRANCH == 'origin/dev') {
sh'''
docker push rhyssevans/rhys-project-jenk:latest
docker push rhyssevans/rhys-project-jenk:v${BUILD_NUMBER}
'''
} else {
sh'echo "unrecognised branch"'
}
}
}
}

stage('Deploy') {
steps {
sh '''

'''
script {
if (env.GIT_BRANCH == 'origin/main') {
sh'''
kubectl apply -f ./kubernetes -n prod
kubectl set image deployment/flask-deployment flask-container=rhyssevans/rhys-project-jenk:v${BUILD_NUMBER} -n prod
'''
} else if (env.GIT_BRANCH == 'origin/dev') {
sh'''
kubectl apply -f ./kubernetes -n dev
kubectl set image deployment/flask-deployment flask-container=rhyssevans/rhys-project-jenk:v${BUILD_NUMBER} -n dev
'''
} else {
sh'echo "unrecognised branch"'
}
}
}
}
}
}
}
35 changes: 35 additions & 0 deletions kubernetes/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: flask-deployment
labels:
app: flask
spec:
replicas: 8
selector:
matchLabels:
app: flask
template:
metadata:
labels:
app: flask
spec:
containers:
- name: flask-container
image: rhyssevans/rhys-project-jenk:latest
imagePullPolicy: Always
ports:
- containerPort: 5500
---
apiVersion: v1
kind: Service
metadata:
name: flask-service
spec:
type: ClusterIP
selector:
app: flask
ports:
- protocol: TCP
port: 5500
targetPort: 5500
62 changes: 62 additions & 0 deletions kubernetes/service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
nginx.conf: |
events {}
http {
server {
listen 80;
location / {
proxy_pass http://flask-service:5500;
}
}
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 8
selector:
matchLabels:
app: nginx
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
template:
metadata:
labels:
app: nginx
spec:
volumes:
- name: nginx-volume
configMap:
name: nginx-config
containers:
- name: nginx
image: nginx:latest
imagePullPolicy: Always
ports:
- containerPort: 80
volumeMounts:
- name: nginx-volume
mountPath: /etc/nginx/
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
2 changes: 1 addition & 1 deletion lbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
mimetypes.add_type('text/javascript', '.js')

# set up the app with listening socket for http requests and appropriate hostname
PORT = 8080
PORT = 5500
HOST = '0.0.0.0'

# get app to serve static files from the public directory
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ trio
trio-websocket
urllib3
Werkzeug==2.3
wsproto
wsproto
20 changes: 13 additions & 7 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
<body>
<div class="container-sm px-4">
<div class="row gx-5">
<h1>REST Application</h1>
<h1>Hello Lucy how are you?</h1>
<div class="col-6">
<form class="mb-2">
<h2>Create</h2>
<input type="text" id="inputName" class="form-control" placeholder="enter item name to create" />
<input type="text" id="inputDescription" class="form-control mt-2" placeholder="enter item description to create" />
<input type="number" id="inputPrice" class="form-control mt-2" placeholder="enter item price to create" />
<input type="text" id="inputDescription" class="form-control mt-2"
placeholder="enter item description to create" />
<input type="number" id="inputPrice" class="form-control mt-2"
placeholder="enter item price to create" />
<button type="button" class="btn btn-primary mt-2" id="buttonCreate">POST</button>
<input type="text" style="display: none;" />
</form>
Expand All @@ -29,10 +31,14 @@ <h2>Read One</h2>

<form class="mb-2">
<h2>Update</h2>
<input type="number" id="inputUpdateID" class="form-control" placeholder="enter id of item to update" />
<input type="text" id="inputUpdateName" class="form-control mt-2" placeholder="enter name of item to update" />
<input type="text" id="inputUpdateDescription" class="form-control mt-2" placeholder="enter description of item to update" />
<input type="number" id="inputUpdatePrice" class="form-control mt-2" placeholder="enter price of item to update" />
<input type="number" id="inputUpdateID" class="form-control"
placeholder="enter id of item to update" />
<input type="text" id="inputUpdateName" class="form-control mt-2"
placeholder="enter name of item to update" />
<input type="text" id="inputUpdateDescription" class="form-control mt-2"
placeholder="enter description of item to update" />
<input type="number" id="inputUpdatePrice" class="form-control mt-2"
placeholder="enter price of item to update" />
<button type="button" class="btn btn-primary mt-2" id="buttonUpdate">PUT</button>
</form>

Expand Down