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
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
documentation/
kubernetes/

.gitignore
.dockerignore

Dockerfile
Jenkinsfile
LICENSE
*.md
18 changes: 5 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
RUN pip3 install -r "requirements.txt"

EXPOSE 8080

ENTRYPOINT ["python", "lbg.py"]
38 changes: 19 additions & 19 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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}"
}
}
}
}
}
}
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down Expand Up @@ -91,4 +100,4 @@ In a new terminal window use the command

~~~ bash
behave .\features\restapp.feature
~~~
~~~
7 changes: 0 additions & 7 deletions docker.sh

This file was deleted.

5 changes: 1 addition & 4 deletions lbg.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
9 changes: 5 additions & 4 deletions lbg.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down
68 changes: 34 additions & 34 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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