Skip to content

Commit

Permalink
Merge pull request #19 from deep-diver/gke-deployment
Browse files Browse the repository at this point in the history
Gke deployment
  • Loading branch information
deep-diver committed Jul 1, 2021
2 parents 36a7b66 + 7c932c9 commit 7acad70
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 17 deletions.
54 changes: 54 additions & 0 deletions gke/deployment.yaml
@@ -0,0 +1,54 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: clip-search
name: clip-search
spec:
replicas: 1
selector:
matchLabels:
app: clip-search
template:
metadata:
labels:
app: clip-search
spec:
containers:
# image registry URI should be replaced once GitHub Action is set up
- image: gcr.io/titanium-vision-318200/search_service
name: search-service-p4sml
imagePullPolicy: Always
ports:
- containerPort: 8080
protocol: TCP
livenessProbe:
httpGet:
path: /alive
port: 8080
initialDelaySeconds: 90
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 90
periodSeconds: 10
resources:
limits:
cpu: 1500m
memory: 4G
---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: clip-search-hpa

spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: clip-search
minReplicas: 1
maxReplicas: 3
targetCPUUtilizationPercentage: 80
8 changes: 8 additions & 0 deletions gke/gke-managed-certificate.yaml
@@ -0,0 +1,8 @@
apiVersion: networking.gke.io/v1
kind: ManagedCertificate
metadata:
name: gde
spec:
domains:
# should be replaced once GitHub Action is set up
- mlgde.com
19 changes: 19 additions & 0 deletions gke/ingress.yaml
@@ -0,0 +1,19 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: gde
annotations:
kubernetes.io/ingress.global-static-ip-name: gde
networking.gke.io/managed-certificates: gde
kubernetes.io/ingress.class: "gce"
spec:
rules:
- http:
paths:
- path: /*
pathType: ImplementationSpecific
backend:
service:
name: gde
port:
number: 80
12 changes: 12 additions & 0 deletions gke/service.yaml
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: gde
spec:
selector:
app: clip-search
type: ClusterIP
ports:
- protocol: TCP
port: 80
targetPort: 8080
5 changes: 4 additions & 1 deletion server/Dockerfile
Expand Up @@ -3,6 +3,9 @@ WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
# this information should be replaced once GitHub Action is set up
ENV PIXABAY_API_KEY="22176616-358d1b190a298ff59f96b35a1"
ENV REDIS_IN_USE="true"
ENV REDISHOST="10.195.86.155"
EXPOSE 8080
CMD ["gunicorn", "-b 8080", "-t 60", "main:app"]
CMD [ "python3", "main.py" ]
30 changes: 27 additions & 3 deletions server/main.py
@@ -1,9 +1,12 @@
from perform_search import Searcher
from flask import Flask, jsonify, request
from flask_cors import CORS

from flask_healthz import healthz
from flask_healthz import HealthError

app = Flask(__name__)
app.register_blueprint(healthz, url_prefix="/")

cors = CORS(
app,
resources={
Expand All @@ -12,11 +15,32 @@
},
)

def printok():
print("Everything is fine")

def liveness():
try:
printok()
except Exception:
raise HealthError("Can't connect to the file")

def readiness():
try:
printok()
except Exception:
raise HealthError("Can't connect to the file")

app.config.update(
HEALTHZ = {
"alive": "main.liveness",
"ready": "main.readiness",
}
)

searcher = Searcher()

MAX_PIXABAY_SEARCH = 30


@app.route("/search", methods=["GET"])
def get_images():
tag = request.args.get("t").lower()
Expand All @@ -36,4 +60,4 @@ def test():


if __name__ == "__main__":
app.run(port=8080, debug=True)
app.run(host='0.0.0.0', port=8080, debug=True)
31 changes: 18 additions & 13 deletions server/perform_search.py
Expand Up @@ -3,6 +3,7 @@
from pixabay_utils import fetch_images_tag
from direct_redis import DirectRedis

redis = os.environ.get("REDIS_IN_USE", "false").lower()
redis_host = os.environ.get("REDISHOST", "localhost")
redis_port = int(os.environ.get("REDISPORT", 6379))
redis_client = DirectRedis(host=redis_host, port=redis_port)
Expand All @@ -21,20 +22,24 @@ def get_similar_images(self, keyword, semantic_query, pixabay_max, top_k):
:param top_k: Top-k images to return.
:return: Tuple of top_k URLs and the similarity scores of the images present inside the URLs.
"""
images_redis_key = keyword + "_images"
urls_redis_key = keyword + "_urls"

if redis_client.exists(images_redis_key) and redis_client.exists(
urls_redis_key
):
keyword_images = redis_client.get(images_redis_key)
keyword_image_urls = redis_client.get(urls_redis_key)

if redis == "true":
images_redis_key = keyword + "_images"
urls_redis_key = keyword + "_urls"

if redis_client.exists(images_redis_key) and redis_client.exists(
urls_redis_key
):
keyword_images = redis_client.get(images_redis_key)
keyword_image_urls = redis_client.get(urls_redis_key)
else:
(keyword_images, keyword_image_urls) = fetch_images_tag(
keyword, pixabay_max
)
redis_client.set(images_redis_key, keyword_images)
redis_client.set(urls_redis_key, keyword_image_urls)
else:
(keyword_images, keyword_image_urls) = fetch_images_tag(
keyword, pixabay_max
)
redis_client.set(images_redis_key, keyword_images)
redis_client.set(urls_redis_key, keyword_image_urls)
(keyword_images, keyword_image_urls) = fetch_images_tag(keyword, pixabay_max)

(top_indices, top_scores) = self.similarity_model.perform_sim_search(
keyword_images, semantic_query, top_k
Expand Down
1 change: 1 addition & 0 deletions server/requirements.txt
Expand Up @@ -8,3 +8,4 @@ flask
gunicorn==19.3.0
flask-cors
direct-redis
flask-healthz

0 comments on commit 7acad70

Please sign in to comment.