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 diff --git a/Dockerfile b/Dockerfile index 31d103cf..05058760 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,9 @@ 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 - -# COPY lbg.py . COPY . . -# COPY models.py . -EXPOSE 8081 -ENTRYPOINT ["python", "lbg.py"] \ No newline at end of file +RUN pip3 install -r "requirements.txt" + +EXPOSE 8080 + +ENTRYPOINT ["python", "lbg.py"] diff --git a/Jenkinsfile b/Jenkinsfile index d2a1d6eb..b8094068 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,26 +1,26 @@ 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 ''' - 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') { + stage('Build and Push to GCR') { 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 - ''' + 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}" + } } } } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 139ccb35..df9751ee 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,15 @@ -# REST API starter +# -This application is the start point for Sprint 1 of the Lloyds Bank Group Modern Engineering Bootcamp Project Specification. + +we hope we trust we want this to work +In Money We Trust - Dan was here! + + +THIS IS A TEST WITH A NEW CHANGE BY BR + + REST API starter + +This is a Python Flask REST API, serving a simple frontend for use in LBG programs ## Installation @@ -16,7 +25,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 @@ -91,4 +100,4 @@ In a new terminal window use the command ~~~ bash behave .\features\restapp.feature -~~~ \ No newline at end of file +~~~ 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 diff --git a/lbg.py b/lbg.py index 7e6ddff3..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 @@ -17,7 +15,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 @@ -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) diff --git a/lbg.test.py b/lbg.test.py index b03d6e71..0057e0e7 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,13 +53,14 @@ 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): requests.delete(BASE_URL + '/delete/1') + requests.delete(BASE_URL + '/delete/2') # module import protection diff --git a/requirements.txt b/requirements.txt index 628bd059..c0b18168 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==2.2 +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==2.3 +wsproto