Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Commit

Permalink
Добавить развёртывание в одну команду
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf1996 committed May 21, 2018
1 parent 4866f64 commit fe0f081
Show file tree
Hide file tree
Showing 17 changed files with 243 additions and 43 deletions.
113 changes: 85 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,58 @@ build_all: \
build_stats \
build_gateway \

# не работает, надо лапками вводить команду у себя для работы
use_kubernetes_docker:
eval $(minikube docker-env)
@eval $$(minikube docker-env)

# выкатываем с тегом
docker_image_build_gateway_minikube:
@eval $$(minikube docker-env);\
$(MAKE) -C python/gateway docker_build

docker_image_build_data_minikube:
@eval $$(minikube docker-env);\
$(MAKE) -C python/data docker_build

docker_image_build_stats_minikube:
@eval $$(minikube docker-env);\
$(MAKE) -C python/stats docker_build

docker_image_build_receiver_minikube:
@eval $$(minikube docker-env);\
$(MAKE) -C python/receiver docker_build

docker_images_minikube_build: \
docker_image_build_gateway_minikube \
docker_image_build_data_minikube \
docker_image_build_stats_minikube \
docker_image_build_receiver_minikube

#выкатываем без перетеггирования
docker_image_build_gateway_minikube_curr:
@eval $$(minikube docker-env);\
$(MAKE) -C python/gateway docker_build_curr

docker_image_build_data_minikube_curr:
@eval $$(minikube docker-env);\
$(MAKE) -C python/data docker_build_curr

docker_image_build_stats_minikube_curr:
@eval $$(minikube docker-env);\
$(MAKE) -C python/stats docker_build_curr

docker_image_build_receiver_minikube_curr:
@eval $$(minikube docker-env);\
$(MAKE) -C python/receiver docker_build_curr


docker_images_minikube_build_curr: \
docker_image_build_gateway_minikube_curr \
docker_image_build_data_minikube_curr \
docker_image_build_stats_minikube_curr \
docker_image_build_receiver_minikube_curr

# просто выкатываем образы
docker_image_build_gateway:
$(MAKE) -C python/gateway docker_build

Expand Down Expand Up @@ -88,68 +137,76 @@ rebuild_protobuf:

# data kubernetes
kubernetes_data_service:
kubectl apply -f kuber/data-service.yaml
$(MAKE) -C python/data kubernetes_service

kubernetes_data_deployment:
kubectl apply -f kuber/data-deployment.yaml
$(MAKE) -C python/data kubernetes_deployment

kubernetes_data_deployment_remove:
kubectl delete deployment -l app=data
$(MAKE) -C python/data kubernetes_deployment_remove

kubernetes_data_service_remove:
kubectl delete service -l name=data
$(MAKE) -C python/data kubernetes_service_remove


#Собираем новый образ и запускаем
kubernetes_data_buildnload:
@eval $$(minikube docker-env); \
$(MAKE) -C python/data kubernetes_buildnload

# stats kubernetes
kubernetes_stats_service:
kubectl apply -f kuber/stats-service.yaml
$(MAKE) -C python/stats kubernetes_service

kubernetes_stats_deployment:
kubectl apply -f kuber/stats-deployment.yaml
$(MAKE) -C python/stats kubernetes_deployment

kubernetes_stats_deployment_remove:
kubectl delete deployment -l app=stats
$(MAKE) -C python/stats kubernetes_deployment_remove

kubernetes_stats_service_remove:
kubectl delete service -l name=stats
$(MAKE) -C python/stats kubernetes_service_remove

kubernetes_stats_buildnload:
@eval $$(minikube docker-env); \
$(MAKE) -C python/stats kubernetes_buildnload


# gateway kubernetes
kubernetes_gateway_service:
kubectl apply -f kuber/gateway-service.yaml
$(MAKE) -C python/gateway kubernetes_service

kubernetes_gateway_deployment:
kubectl apply -f kuber/gateway-deployment.yaml
$(MAKE) -C python/gateway kubernetes_deployment

kubernetes_gateway_deployment_remove:
kubectl delete deployment -l app=gateway
$(MAKE) -C python/gateway kubernetes_deployment_remove

kubernetes_gateway_service_remove:
kubectl delete service -l name=gateway
$(MAKE) -C python/gateway kubernetes_service_remove

kubernetes_gateway_buildnload:
@eval $$(minikube docker-env); \
$(MAKE) -C python/gateway kubernetes_buildnload


# reciever kubernetes
kubernetes_reciever_service:
kubectl apply -f kuber/reciever-service.yaml
$(MAKE) -C python/receiver kubernetes_service

kubernetes_reciever_deployment:
kubectl apply -f kuber/reciever-deployment.yaml
$(MAKE) -C python/receiver kubernetes_deployment

kubernetes_reciever_deployment_remove:
kubectl delete deployment -l app=reciever
$(MAKE) -C python/receiver kubernetes_deployment_remove

kubernetes_reciever_service_remove:
kubectl delete service -l name=reciever
$(MAKE) -C python/receiver kubernetes_service_remove

# # rabbitmq
# kubernetes_rabbitmq_service:
# kubectl apply -f kuber/rabbitmq-service.yaml

# kubernetes_rabbitmq_controller:
# kubectl apply -f kuber/rabbitmq-controller.yaml

# kubernetes_rabbitmq_controller_remove:
# kubectl delete pod -l component=rabbitmq
kubernetes_receiver_buildnload:
@eval $$(minikube docker-env); \
$(MAKE) -C python/receiver kubernetes_buildnload

# kubernetes_rabbitmq_service_remove:
# kubectl delete service -l name=rabbitmq

# устанавливаем dns
kubernetes_install_dns:
Expand Down
39 changes: 35 additions & 4 deletions python/data/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,41 @@ docker_container_remove:
docker_run_container:
docker run -p 5000:5000 -d --name $(CONTAINERNAME) $(IMAGENAME)

docker_build:
docker build -t $(IMAGENAME) .

docker_run: \
docker_stop \
docker_container_remove \
docker_run_container
docker_run_container

docker_build: \
version_file_increment \
docker_build_curr

docker_build_curr:
o=`cut -f1 VERSION`; \
docker build -t $(IMAGENAME):$$o . ;

kubernetes_service:
kubectl apply -f kuber/data-service.yaml

kubernetes_deployment:
kubectl apply -f kuber/data-deployment.yaml

kubernetes_deployment_remove:
kubectl delete deployment -l app=data

kubernetes_service_remove:
kubectl delete service -l name=data

version_file_increment:
o=`cut -f1 VERSION`; \
n=`expr $$o + 1`; \
echo $$n > VERSION; \

kubernetes_buildnload: \
docker_build \
kubernetes_update_image

kubernetes_update_image:
o=`cut -f1 VERSION`; \
echo "image version is ", $$o; \
kubectl set image deployment/data-deployment $(IMAGENAME)=$(IMAGENAME):$$o
1 change: 1 addition & 0 deletions python/data/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ spec:
containers:
- name: data
imagePullPolicy: Never
image: data:latest
image: data
ports:
- containerPort: 5000
File renamed without changes.
37 changes: 37 additions & 0 deletions python/gateway/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,40 @@ stop:

build:
cp -r ../../depends/python depends

kubernetes_service:
kubectl apply -f kuber/reciever-service.yaml

kubernetes_deployment:
kubectl apply -f kuber/reciever-deployment.yaml

kubernetes_deployment_remove:
kubectl delete deployment -l app=gateway

kubernetes_service_remove:
kubectl delete service -l name=gateway

docker_build: \
version_file_increment \
docker_build_curr

docker_build_curr:
o=`cut -f1 VERSION`; \
docker build -t $(IMAGENAME):$$o . ;

kubernetes_service_remove:
kubectl delete service -l name=gateway

version_file_increment:
o=`cut -f1 VERSION`; \
n=`expr $$o + 1`; \
echo $$n > VERSION; \

kubernetes_buildnload: \
docker_build \
kubernetes_update_image

kubernetes_update_image:
o=`cut -f1 VERSION`; \
echo "image version is ", $$o; \
kubectl set image deployment/gateway-deployment $(IMAGENAME)=$(IMAGENAME):$$o
1 change: 1 addition & 0 deletions python/gateway/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6
File renamed without changes.
37 changes: 34 additions & 3 deletions python/receiver/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,41 @@ docker_container_remove:
docker_run_container:
docker run -p 5000:5000 -d --name $(CONTAINERNAME) $(IMAGENAME)

docker_build:
docker build -t $(IMAGENAME) .
docker_build: \
version_file_increment \
docker_build_curr

docker_build_curr:
o=`cut -f1 VERSION`; \
docker build -t $(IMAGENAME):$$o . ;

docker_run: \
docker_stop \
docker_container_remove \
docker_run_container
docker_run_container

kubernetes_service:
kubectl apply -f kuber/reciever-service.yaml

kubernetes_deployment:
kubectl apply -f kuber/reciever-deployment.yaml

kubernetes_deployment_remove:
kubectl delete deployment -l app=reciever

kubernetes_service_remove:
kubectl delete service -l name=reciever

version_file_increment:
o=`cut -f1 VERSION`; \
n=`expr $$o + 1`; \
echo $$n > VERSION; \

kubernetes_buildnload: \
docker_build \
kubernetes_update_image

kubernetes_update_image:
o=`cut -f1 VERSION`; \
echo "image version is ", $$o; \
kubectl set image deployment/reciever-deployment $(IMAGENAME)=$(IMAGENAME):$$o
1 change: 1 addition & 0 deletions python/receiver/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
17 changes: 13 additions & 4 deletions python/receiver/app/data_broker/data_broker.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import pika
import json
import time
import logging

log = logging.getLogger("flask.app")

class DataBroker:
_SENSOR_DATA_QUEUE = 'sensor_data'

def __init__(self, host, port=5672):
credentials = pika.PlainCredentials('user','user')
self._connection = pika.BlockingConnection(pika.ConnectionParameters(host=host, port=port,credentials=credentials ))
self._connection = pika.BlockingConnection(pika.ConnectionParameters(host=host, port=port,credentials=credentials, heartbeat=0))
self._chanel = self._connection.channel()

self._declare_sensor_data_queue()

def declare_queue(self, queue_cls):
Expand All @@ -18,8 +20,15 @@ def declare_queue(self, queue_cls):
def _declare_sensor_data_queue(self):
self._chanel.queue_declare(queue=DataBroker._SENSOR_DATA_QUEUE)

def send_sensor_data(self, sensor_data):
sensor_data['timestamp'] = sensor_data['timestamp'].strftime("%Y-%m-%dT%H:%M:%S")
def _send_data(self, sensor_data):
self._chanel.basic_publish(exchange='',
routing_key='sensor_data',
body=json.dumps(sensor_data))

def send_sensor_data(self, sensor_data):
sensor_data['timestamp'] = sensor_data['timestamp'].strftime("%Y-%m-%dT%H:%M:%S")
try:
self._send_data(sensor_data)
except pika.exceptions.ConnectionClosed as e:
log.error("failed to connect {}".format(str(e)))
self._send_data(sensor_data)
File renamed without changes.
Loading

0 comments on commit fe0f081

Please sign in to comment.