From f9be038e20fc7b0abccb1244e12469c4563e86cb Mon Sep 17 00:00:00 2001 From: PCMBarber <57707405+PCMBarber@users.noreply.github.com> Date: Wed, 22 Feb 2023 08:26:28 +0000 Subject: [PATCH 01/21] Update Dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 31d103cf..1b0e88ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,6 @@ RUN pip install pyhamcrest # COPY lbg.py . COPY . . # COPY models.py . -EXPOSE 8081 +EXPOSE 8080 -ENTRYPOINT ["python", "lbg.py"] \ No newline at end of file +ENTRYPOINT ["python", "lbg.py"] From 7ad720b8ebca04e7072fec8d24f10acf5cc6e819 Mon Sep 17 00:00:00 2001 From: PCMBarber <57707405+PCMBarber@users.noreply.github.com> Date: Wed, 22 Feb 2023 08:26:57 +0000 Subject: [PATCH 02/21] Update Jenkinsfile --- Jenkinsfile | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d2a1d6eb..3e6673ef 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,23 +4,16 @@ pipeline { stage('Build') { steps { sh ''' - docker build -t lbg7-20220905/lbg-api:latest -t imcalled/lbg-api:$BUILD_NUMBER . - docker push lbg7-20220905/lbg-api:latest - docker push lbg7-20220905/lbg-api:$BUILD_NUMBER - docker tag lbg7-20220905/lbg-api:latest gcr.io/lbg7-20220905/kun-lbg:v1 - docker push lbg7-20220905/lbg-api:latest gcr.io/lbg7-20220905/kun-lbg:v1 + ''' } } stage('Deploy') { steps { sh ''' - ssh -i '~/.ssh/id_rsa' jenkins@35.242.152.138 << EOF - docker stop lbg-container - docker rm lbg-container - docker run -d -p 8080:8080 --name lbg-container lbg7-20220905/lbg-api:latest + ''' } } } -} \ No newline at end of file +} From d1e18d1f2a667cebae0338d0a53fdd4eeb2dd523 Mon Sep 17 00:00:00 2001 From: PCMBarber <57707405+PCMBarber@users.noreply.github.com> Date: Wed, 22 Feb 2023 08:27:19 +0000 Subject: [PATCH 03/21] Delete docker.sh --- docker.sh | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 docker.sh diff --git a/docker.sh b/docker.sh deleted file mode 100644 index 9cdf0d1e..00000000 --- a/docker.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash/ -docker build -t imcalled/lbg-api:latest . -docker push imcalled/lbg-api:latest - -docker stop lbg-container -docker rm lbg-container -docker run -d -p 8080:8080 --name lbg-container imcalled/lbg-api:latest \ No newline at end of file From cb143b5a623a9cb69d2fe420160f36ae3e9760a0 Mon Sep 17 00:00:00 2001 From: PCMBarber <57707405+PCMBarber@users.noreply.github.com> Date: Wed, 22 Feb 2023 08:29:36 +0000 Subject: [PATCH 04/21] Create .dockerignore --- .dockerignore | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..05fac220 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +documentation/ +kubernetes/ + +.gitignore +.dockerignore + +Dockerfile +Jenkinsfile +LICENSE +*.md From 1a94f0f7066c35a2ce26882f4728d611eccdd12b Mon Sep 17 00:00:00 2001 From: PCMBarber <57707405+PCMBarber@users.noreply.github.com> Date: Wed, 22 Feb 2023 08:30:34 +0000 Subject: [PATCH 05/21] Update Dockerfile --- Dockerfile | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1b0e88ae..016bb2fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,11 @@ FROM python:latest -RUN pip install Flask -RUN pip install Flask-API -RUN pip install sqlalchemy -RUN pip install Flask-SQLAlchemy -RUN pip install selenium -RUN pip install behave -RUN pip install requests -RUN pip install pyhamcrest +WORKDIR /app -# COPY lbg.py . COPY . . -# COPY models.py . + +RUN pip install -r "requirements.txt" + EXPOSE 8080 ENTRYPOINT ["python", "lbg.py"] From dd15d48f4e06d6409b59cb784fc7ede94b6b9ee6 Mon Sep 17 00:00:00 2001 From: PCMBarber <57707405+PCMBarber@users.noreply.github.com> Date: Wed, 22 Feb 2023 08:31:48 +0000 Subject: [PATCH 06/21] Update requirements.txt --- requirements.txt | 68 ++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/requirements.txt b/requirements.txt index 628bd059..14254ba4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,34 +1,34 @@ -async-generator==1.10 -attrs==22.1.0 -behave==1.2.6 -certifi==2022.6.15 -cffi==1.15.1 -charset-normalizer==2.1.1 -click==8.1.3 -colorama==0.4.5 -Flask==2.2.2 -Flask-API==3.0.post1 -Flask-SQLAlchemy==2.5.1 -greenlet==1.1.3 -h11==0.13.0 -idna==3.3 -itsdangerous==2.1.2 -Jinja2==3.1.2 -MarkupSafe==2.1.1 -outcome==1.2.0 -parse==1.19.0 -parse-type==0.6.0 -pycparser==2.21 -PyHamcrest==2.0.4 -PySocks==1.7.1 -requests==2.28.1 -selenium==4.4.3 -six==1.16.0 -sniffio==1.3.0 -sortedcontainers==2.4.0 -SQLAlchemy==1.4.40 -trio==0.21.0 -trio-websocket==0.9.2 -urllib3==1.26.12 -Werkzeug==2.2.2 -wsproto==1.2.0 +async-generator +attrs +behave +certifi +cffi +charset-normalizer +click +colorama +Flask +Flask-API +Flask-SQLAlchemy +greenlet +h11 +idna +itsdangerous +Jinja2 +MarkupSafe +outcome +parse +parse-type +pycparser +PyHamcrest +PySocks +requests +selenium +six +sniffio +sortedcontainers +SQLAlchemy +trio +trio-websocket +urllib3 +Werkzeug +wsproto From 8bf3f037b61ee8d9cde4665c66284565f1987e40 Mon Sep 17 00:00:00 2001 From: PCMBarber <57707405+PCMBarber@users.noreply.github.com> Date: Wed, 22 Feb 2023 08:33:19 +0000 Subject: [PATCH 07/21] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 139ccb35..cfe33f3e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # REST API starter -This application is the start point for Sprint 1 of the Lloyds Bank Group Modern Engineering Bootcamp Project Specification. +This is a Python Flask REST API, serving a simple frontend for use in LBG programs ## Installation @@ -91,4 +91,4 @@ In a new terminal window use the command ~~~ bash behave .\features\restapp.feature -~~~ \ No newline at end of file +~~~ From f769a0a24b8a93c129aac322312f861e0f01c51d Mon Sep 17 00:00:00 2001 From: PCMBarber <57707405+PCMBarber@users.noreply.github.com> Date: Wed, 22 Feb 2023 09:07:33 +0000 Subject: [PATCH 08/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cfe33f3e..4a5b021c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ In order to run the application, from your git bash terminal run: ~~~ bash python lbg.py -API Listening on http://localhost:8080 +API Listening on http://localhost:8080/index.html ~~~ ## Stopping the application From 414862e9be25501de9bddf35cca6b8b1745a5bff Mon Sep 17 00:00:00 2001 From: PCMBarber <57707405+PCMBarber@users.noreply.github.com> Date: Wed, 22 Feb 2023 09:55:53 +0000 Subject: [PATCH 09/21] Update lbg.py --- lbg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbg.py b/lbg.py index 7e6ddff3..d1f6ce2d 100644 --- a/lbg.py +++ b/lbg.py @@ -17,7 +17,7 @@ mimetypes.add_type('text/javascript', '.js') # set up the app with listening socket for http requests and appropriate hostname -PORT = 8081 +PORT = 8080 HOST = '0.0.0.0' # get app to serve static files from the public directory From 57aa7409c94d843b1c2ffcac2d43cc2ea8b6b797 Mon Sep 17 00:00:00 2001 From: PCMBarber <57707405+PCMBarber@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:08:26 +0100 Subject: [PATCH 10/21] Update lbg.py, removed reference to docker.sh --- lbg.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lbg.py b/lbg.py index d1f6ce2d..40e7f1aa 100644 --- a/lbg.py +++ b/lbg.py @@ -1,8 +1,6 @@ """ LBG learning-oriented CRUD-based RESTful API using standard Flask routing """ -# import script to generate new docker image of application -import os # import Flask microframework and associated tools from flask import Flask, request, jsonify @@ -207,6 +205,5 @@ def delete_one(_id): # module import protection if __name__ == '__main__': # get app to serve - os.system("docker.sh") print(f'API Listening on http://{HOST}:{PORT}') app.run(host=HOST, port=PORT, debug=True) From de199a655f0bf23ecd2cc3c4995ab99c05270704 Mon Sep 17 00:00:00 2001 From: PCMBarber <57707405+PCMBarber@users.noreply.github.com> Date: Fri, 10 Nov 2023 07:20:05 +0000 Subject: [PATCH 11/21] Update lbg.test.py Fixed broken tests --- lbg.test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lbg.test.py b/lbg.test.py index b03d6e71..f77f49fa 100644 --- a/lbg.test.py +++ b/lbg.test.py @@ -35,7 +35,7 @@ def test_create_post_request_status(self): Create (Post) request. Note. API will need to be running(!) """ response = requests.post(BASE_URL + '/create', json = {'name': 'Tool', 'description': 'Hammer', 'price': 10.5}) - self.assertEqual(response.status_code, HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) @unittest.skip("Skip this test for now using this decorator...") def test_create_post_request_type(self): @@ -53,9 +53,9 @@ def test_response_contains_expected_json_fields(self): Test to see if RESTful API returns an object with the correct fields for a simple Read (GET) request. Note. API will need to be running(!) """ - item = requests.post(BASE_URL + '/create', json = {'name': 'Vegetable', 'description': 'Leek', 'price': .7}) - response = requests.get(BASE_URL + '/read/3') - self.assertEqual(response.json(), {"_id":3, 'name': 'Vegetable', 'description': 'Leek', 'price': .7}) + item = requests.post(BASE_URL + '/create', json = {'name': 'Vegetable', 'description': 'Leek', 'price': 0.7}) + response = requests.get(BASE_URL + '/read/2') + self.assertEqual(response.json(), {"_id":2, 'name': 'Vegetable', 'description': 'Leek', 'price': 0.7}) @classmethod def tearDownClass(cls): From c9613d2a60e3ef86dbabe6b352726d5e673dc270 Mon Sep 17 00:00:00 2001 From: PCMBarber <57707405+PCMBarber@users.noreply.github.com> Date: Fri, 10 Nov 2023 07:31:28 +0000 Subject: [PATCH 12/21] Update lbg.test.py Fixed tear down class --- lbg.test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lbg.test.py b/lbg.test.py index f77f49fa..0057e0e7 100644 --- a/lbg.test.py +++ b/lbg.test.py @@ -60,6 +60,7 @@ def test_response_contains_expected_json_fields(self): @classmethod def tearDownClass(cls): requests.delete(BASE_URL + '/delete/1') + requests.delete(BASE_URL + '/delete/2') # module import protection From 50983df5904322fdf9004b87fd590a3b6041036d Mon Sep 17 00:00:00 2001 From: PCMBarber <57707405+PCMBarber@users.noreply.github.com> Date: Fri, 10 Nov 2023 10:10:53 +0000 Subject: [PATCH 13/21] Update requirements.txt --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 14254ba4..c0b18168 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ cffi charset-normalizer click colorama -Flask +Flask==2.2 Flask-API Flask-SQLAlchemy greenlet @@ -30,5 +30,5 @@ SQLAlchemy trio trio-websocket urllib3 -Werkzeug +Werkzeug==2.3 wsproto From 5fc7c93217d9e1b1dbd2437e3c8b5a261ce5459a Mon Sep 17 00:00:00 2001 From: Wecancode1 Date: Fri, 12 Jul 2024 11:35:33 +0100 Subject: [PATCH 14/21] first commit and onl --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a5b021c..a76834ac 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,11 @@ -# REST API starter +# + + +we hope we trust we want this to work + + + + REST API starter This is a Python Flask REST API, serving a simple frontend for use in LBG programs From eef7a4c730c4e0e707322401347c472a1b31bb5a Mon Sep 17 00:00:00 2001 From: Dan-308 Date: Fri, 12 Jul 2024 11:43:47 +0100 Subject: [PATCH 15/21] First test --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a76834ac..141d6159 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ we hope we trust we want this to work +In Money We Trust From 56a8597030e62e83bbb5ec9088930a01c98e7a25 Mon Sep 17 00:00:00 2001 From: Dan-308 Date: Fri, 12 Jul 2024 12:01:43 +0100 Subject: [PATCH 16/21] Editted Read.me --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 141d6159..f15aba33 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ we hope we trust we want this to work -In Money We Trust +In Money We Trust - Dan was here From 829518bcd8f0082d778a8b5539ad73e6423e90d9 Mon Sep 17 00:00:00 2001 From: Dan-308 Date: Fri, 12 Jul 2024 12:08:10 +0100 Subject: [PATCH 17/21] Added to readme.txt --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f15aba33..c6b133c4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ we hope we trust we want this to work -In Money We Trust - Dan was here +In Money We Trust - Dan was here! From 8b135dc59a0319e93eb2631a2cef29598bcebf8b Mon Sep 17 00:00:00 2001 From: BR-QA-training Date: Fri, 12 Jul 2024 12:13:21 +0100 Subject: [PATCH 18/21] first commit by br --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 141d6159..b1a3925a 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ we hope we trust we want this to work In Money We Trust +THIS IS A TEST WITH A NEW CHANGE BY BR REST API starter From 93ba193cd7e6b3ed92d8f0dae26001b08e5b2a52 Mon Sep 17 00:00:00 2001 From: BR-QA-training Date: Fri, 19 Jul 2024 09:59:10 +0100 Subject: [PATCH 19/21] Dockerfile updated to remove workdir instruction --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 016bb2fb..2d369a4c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ FROM python:latest -WORKDIR /app - COPY . . RUN pip install -r "requirements.txt" From a37df6fec8a2bd8127296f8b9abf54f6030a5360 Mon Sep 17 00:00:00 2001 From: Wecancode1 <59051683+Wecancode1@users.noreply.github.com> Date: Fri, 19 Jul 2024 10:24:04 +0100 Subject: [PATCH 20/21] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2d369a4c..05058760 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM python:latest COPY . . -RUN pip install -r "requirements.txt" +RUN pip3 install -r "requirements.txt" EXPOSE 8080 From e74eccaf0383f4262e99d2bef71e9310f572c596 Mon Sep 17 00:00:00 2001 From: Wecancode1 <59051683+Wecancode1@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:26:56 +0100 Subject: [PATCH 21/21] Update Jenkinsfile --- Jenkinsfile | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3e6673ef..b8094068 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,18 +1,25 @@ pipeline { agent any + environment { + GCR_CREDENTIALS_ID = 'jenkins-secret' // The ID you provided in Jenkins credentials + IMAGE_NAME = 't3-image' + GCR_URL = 'europe-west1-docker.pkg.dev/lbg-mea-20/repo-t3' + } stages { - stage('Build') { - steps { - sh ''' - - ''' - } - } - stage('Deploy') { + stage('Build and Push to GCR') { steps { - sh ''' - - ''' + script { + // Authenticate with Google Cloud + withCredentials([file(credentialsId: GCR_CREDENTIALS_ID, variable: 'GOOGLE_APPLICATION_CREDENTIALS')]) { + sh 'gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS' + } + // Configure Docker to use gcloud as a credential helper + sh 'gcloud auth configure-docker --quiet' + // Build the Docker image + sh "docker build -t ${GCR_URL}/${IMAGE_NAME}:${BUILD_NUMBER} ." + // Push the Docker image to GCR + sh "docker push ${GCR_URL}/${IMAGE_NAME}:${BUILD_NUMBER}" + } } } }