From ee76a7a1921a7a5901bbff57e9cc467c37ba60ef Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Thu, 21 Nov 2024 15:05:04 +0000 Subject: [PATCH 1/8] updated Dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 016bb2fb..3c296bf1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:latest +FROM python3.6 WORKDIR /app @@ -6,6 +6,6 @@ COPY . . RUN pip install -r "requirements.txt" -EXPOSE 8080 +EXPOSE 5050 ENTRYPOINT ["python", "lbg.py"] From 678ffe2a5a3bd2f2830632b959b75c931c1bde98 Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Thu, 21 Nov 2024 15:33:22 +0000 Subject: [PATCH 2/8] this should work --- Dockerfile | 2 +- Jenkinsfile | 77 ++++++++++++++++++++++++++++++++++---- kubernetes/application.yml | 35 +++++++++++++++++ kubernetes/service.yml | 62 ++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3c296bf1..8dd9df76 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,6 @@ COPY . . RUN pip install -r "requirements.txt" -EXPOSE 5050 +EXPOSE 5500 ENTRYPOINT ["python", "lbg.py"] diff --git a/Jenkinsfile b/Jenkinsfile index 3e6673ef..2b8665f4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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 . -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 . -n dev + kubectl set image deployment/flask-deployment flask-container=rhyssevans/rhys-project-jenk:v${BUILD_NUMBER} -n dev + ''' + } else { + sh'echo "unrecognised branch"' + } + } } } } -} +} \ No newline at end of file diff --git a/kubernetes/application.yml b/kubernetes/application.yml index e69de29b..558ec64a 100644 --- a/kubernetes/application.yml +++ b/kubernetes/application.yml @@ -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 \ No newline at end of file diff --git a/kubernetes/service.yml b/kubernetes/service.yml index e69de29b..6bfef775 100644 --- a/kubernetes/service.yml +++ b/kubernetes/service.yml @@ -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 \ No newline at end of file From 8df42d30c7d0af74e4b055c8d15a7b5f6f2900ef Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Thu, 21 Nov 2024 15:35:15 +0000 Subject: [PATCH 3/8] this should work --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8dd9df76..7b1f7c85 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python3.6 +FROM python:3.6 WORKDIR /app From 9e972248442413c84e042cb3e40ae49d78079e52 Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Thu, 21 Nov 2024 15:46:18 +0000 Subject: [PATCH 4/8] updating python version --- Dockerfile | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7b1f7c85..e04671b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.6 +FROM python:latest WORKDIR /app diff --git a/requirements.txt b/requirements.txt index c0b18168..275f0178 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,4 +31,4 @@ trio trio-websocket urllib3 Werkzeug==2.3 -wsproto +wsproto \ No newline at end of file From 742287dd2dd623af19e05883eeeafaac94496a3d Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Thu, 21 Nov 2024 15:54:40 +0000 Subject: [PATCH 5/8] file directory added --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2b8665f4..25cf3985 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -62,12 +62,12 @@ pipeline { script { if (env.GIT_BRANCH == 'origin/main') { sh''' - kubectl apply -f . -n prod + 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 . -n dev + kubectl apply -f ./kubernetes -n dev kubectl set image deployment/flask-deployment flask-container=rhyssevans/rhys-project-jenk:v${BUILD_NUMBER} -n dev ''' } else { From 8221db72bec53e6b9f132fda4cf1dde3d6de0cce Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Thu, 21 Nov 2024 16:10:57 +0000 Subject: [PATCH 6/8] changing port in lbg.py --- lbg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbg.py b/lbg.py index 40e7f1aa..02b37224 100644 --- a/lbg.py +++ b/lbg.py @@ -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 From 3e6e3bc0bf5ab2d59b7593798b881b84d59e4b51 Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Fri, 22 Nov 2024 10:21:15 +0000 Subject: [PATCH 7/8] renaming in index --- static/index.html | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/static/index.html b/static/index.html index c5efb345..c46bd1ce 100644 --- a/static/index.html +++ b/static/index.html @@ -8,13 +8,15 @@
-

REST Application

+

Rhys' Application

Create

- - + +
@@ -29,10 +31,14 @@

Read One

Update

- - - - + + + +
From 801da0476432fb08fd0059da5f17a231aef0a875 Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Fri, 22 Nov 2024 14:38:34 +0000 Subject: [PATCH 8/8] lucy --- static/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/index.html b/static/index.html index c46bd1ce..393cea13 100644 --- a/static/index.html +++ b/static/index.html @@ -8,7 +8,7 @@
-

Rhys' Application

+

Hello Lucy how are you?

Create