Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added converter service to prod #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ FROM python:3.7-stretch

RUN apt-get update && mkdir -p /app

WORKDIR /app

COPY requirements.txt /app/
RUN pip install -r requirements.txt

COPY /src/ /app/

ENV FLASK_APP "api.py"
WORKDIR /app

RUN pip3 install --no-cache-dir -r requirements.txt

#ENV FLASK_APP "api.py"

CMD [ "python3.7", "api.py"]

45 changes: 30 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
DOCKER_REPO ?= gcr.io/online-bridge-hackathon-2020
# Project / Org
GCP_PROJECT ?= globalbridge-app
GKE_ZONE ?= europe-west4-b

# Service / App
GKE_CLUSTER_NAME ?= prod-cluster
RELEASE_NAME ?= converter
K8S_NS ?= prod-${RELEASE_NAME}
EXTERNAL_ADDRESS ?= ${RELEASE_NAME}.prod.globalbridge.app

# Docker Config
DOCKER_REPO ?= gcr.io/${GCP_PROJECT}
VERSION ?= $(shell cat VERSION)
DOCKER_TAG=${DOCKER_REPO}/data-converter-api:${VERSION}
DOCKER_TAG = ${DOCKER_REPO}/${RELEASE_NAME}:${VERSION}

EXTERNAL_ADDRES ?= data-converter.hackathon.globalbridge.app

DDS_K8S_NS ?= data-converter-api
GCP_PROJECT ?= online-bridge-hackathon-2020
GKE_CLUSTER_NAME ?= hackathon-cluster
GKE_ZONE ?= europe-west3-b
ifeq (${SILENT},1)
VERBOSE_TEST :=
else
VERBOSE_TEST := -v
endif


release: build push

build:
libdds/.git:
git submodule update --init
Comment on lines +26 to +27
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no submodules which means the submodule target should be dropped.


build:
docker build -t ${DOCKER_TAG} .

push:
docker push ${DOCKER_TAG}

deploy: set_gcp_context ensure_ns
helm upgrade --install data-converter-api ./chart \
helm upgrade --install ${RELEASE_NAME} ./chart \
--set image="${DOCKER_TAG}" \
--set externalHostname="${EXTERNAL_ADDRES}" \
--namespace ${DDS_K8S_NS} \
--history-max=10
--set externalHostname="${EXTERNAL_ADDRESS}" \
--namespace ${K8S_NS} \
# --history-max=10

uninstall: set_gcp_context
helm del data-converter-api --namespace ${DDS_K8S_NS}
helm del ${RELEASE_NAME} --namespace ${K8S_NS}

set_gcp_context:
gcloud container clusters get-credentials ${GKE_CLUSTER_NAME} --zone ${GKE_ZONE} --project ${GCP_PROJECT}

ensure_ns:
kubectl create ns ${DDS_K8S_NS} || :
kubectl create ns ${K8S_NS} || :

run_local_tests:
python3 -m unittest discover
python3 -m unittest discover ${VERBOSE_TEST}
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1
0.0.2
2 changes: 1 addition & 1 deletion chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
description: A helm chart for Data-Converter API
name: data-converter-api
name: converter
version: 0.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ kind: Deployment
metadata:
name: {{ .Release.Name }}-deployment
labels:
app: data-converter-api
app: {{ .Release.Name }}
spec:
replicas: {{ int .Values.replicas }}
selector:
matchLabels:
app: data-converter-api
app: {{ .Release.Name }}
template:
metadata:
labels:
app: data-converter-api
app: {{ .Release.Name }}
spec:
containers:
- name: api
Expand All @@ -25,20 +25,20 @@ spec:
- flask
- run
- --host=0.0.0.0
- --port=5000
- --port={{ .Values.targetPort }}
ports:
- containerPort: 5000
- containerPort: {{ .Values.targetPort }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-service
spec:
selector:
app: data-converter-api
app: {{ .Release.Name }}
ports:
- port: 80
targetPort: 5000
targetPort: {{ .Values.targetPort }}
protocol: TCP
name: http
---
Expand All @@ -50,7 +50,7 @@ metadata:
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
cert-manager.io/cluster-issuer: letsencrypt-production
labels:
app: data-converter-api
app: {{ .Release.Name }}
name: {{ .Release.Name }}-ingress
spec:
tls:
Expand Down
7 changes: 4 additions & 3 deletions chart/values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
image: gcr.io/online-bridge-hackathon-2020/data-converter-api:0.0.0-dev
image: gcr.io/globalbridge-app/converter
replicas: 1
externalHostname: data-converter.hackathon.globalbridge.app
tlsSecret: data-converter-api-tls-secret
externalHostname: converter.prod.globalbridge.app
tlsSecret: converter-tls-secret
targetPort: 5000
5 changes: 5 additions & 0 deletions src/api.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#!/usr/bin/env python

import sys
sys.path.append('/home/kiat/.local/lib/python3.7/site-packages/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?


from flask import Flask, request
from flask_cors import CORS
from flask_restful import Resource, Api
Expand Down