mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-25 01:22:28 +00:00
Add CI/CD and k8s
This commit is contained in:
parent
62142482dc
commit
54da48b548
50
.gitlab-ci.yml
Normal file
50
.gitlab-ci.yml
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# Uncomment if you want to use docker-in-docker
|
||||||
|
# image: gsiupm/dockermake:latest
|
||||||
|
# services:
|
||||||
|
# - docker:dind
|
||||||
|
# When using dind, it's wise to use the overlayfs driver for
|
||||||
|
# improved performance.
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- test
|
||||||
|
- build
|
||||||
|
- push
|
||||||
|
- deploy
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- make -e login
|
||||||
|
|
||||||
|
test:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- make -e test
|
||||||
|
|
||||||
|
build:
|
||||||
|
stage: build
|
||||||
|
script:
|
||||||
|
- make -e docker-build
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- fix-makefiles
|
||||||
|
|
||||||
|
push:
|
||||||
|
stage: push
|
||||||
|
script:
|
||||||
|
- make -e docker-push
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- fix-makefiles
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
stage: deploy
|
||||||
|
script:
|
||||||
|
- make -e deploy
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- fix-makefiles
|
||||||
|
|
||||||
|
clean :
|
||||||
|
stage: clean
|
||||||
|
script:
|
||||||
|
- make -e clean
|
||||||
|
when: manual
|
18
Makefile
18
Makefile
@ -1,30 +1,28 @@
|
|||||||
PYVERSION=2.7
|
PYVERSION=2.7
|
||||||
NAME=senpycommunity
|
NAME=senpycommunity
|
||||||
REPO=gsiupm
|
REPO=gsiupm
|
||||||
VERSION=test
|
|
||||||
PLUGINS= $(filter %/, $(wildcard */))
|
PLUGINS= $(filter %/, $(wildcard */))
|
||||||
DOCKER_FLAGS=
|
IMAGENAME=gsiupm/senpy-plugins-community
|
||||||
|
DOCKER_FLAGS=-p 5000:5000
|
||||||
|
|
||||||
ifdef SENPY_FOLDER
|
ifdef SENPY_FOLDER
|
||||||
DOCKER_FLAGS+=-v $(realpath $(SENPY_FOLDER)):/usr/src/app/
|
DOCKER_FLAGS+= -v $(realpath $(SENPY_FOLDER)):/usr/src/app/
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
all: build run
|
all: build run
|
||||||
|
|
||||||
build: clean Dockerfile
|
|
||||||
docker build -t '$(REPO)/$(NAME):$(VERSION)-python$(PYVERSION)' -f Dockerfile .;
|
|
||||||
|
|
||||||
test-%:
|
test-%:
|
||||||
docker run $(DOCKER_FLAGS) -v $$PWD/$*:/senpy-plugins/ --rm -ti '$(REPO)/$(NAME):$(VERSION)-python$(PYVERSION)' --only-test $(TEST_FLAGS)
|
docker run $(DOCKER_FLAGS) -v $$PWD/$*:/senpy-plugins/ --rm -ti '$(REPO)/$(NAME):$(VERSION)-python$(PYVERSION)' --only-test $(TEST_FLAGS)
|
||||||
|
|
||||||
test: test-.
|
test: test-.
|
||||||
|
|
||||||
clean:
|
clean-docker:
|
||||||
@docker ps -a | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[1] != "${VERSION}"){ print $$1;}}' | xargs docker rm 2>/dev/null|| true
|
@docker ps -a | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[1] != "${VERSION}"){ print $$1;}}' | xargs docker rm 2>/dev/null|| true
|
||||||
@docker images | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[1] != "${VERSION}"){ print $$1":"$$2;}}' | xargs docker rmi 2>/dev/null|| true
|
@docker images | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[1] != "${VERSION}"){ print $$1":"$$2;}}' | xargs docker rmi 2>/dev/null|| true
|
||||||
|
|
||||||
run: build
|
.PHONY:: test test-% build-% build test test_pip run clean
|
||||||
docker run $(DOCKER_FLAGS) --rm -p 5000:5000 -ti '$(REPO)/$(NAME):$(VERSION)-python$(PYMAIN)'
|
|
||||||
|
include .makefiles/base.mk
|
||||||
|
include .makefiles/k8s.mk
|
||||||
|
|
||||||
.PHONY: test test-% build-% build test test_pip run clean
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
from senpy.plugins import Analysis
|
from senpy.plugins import Analysis
|
||||||
from senpy.models import Response, Entry
|
from senpy.models import Response, Entry
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class ExamplePlugin(Analysis):
|
class ExamplePlugin(Analysis):
|
||||||
'''A *VERY* simple plugin that exemplifies the development of Senpy Plugins'''
|
'''A *VERY* simple plugin that exemplifies the development of Senpy Plugins'''
|
||||||
@ -21,8 +18,8 @@ class ExamplePlugin(Analysis):
|
|||||||
custom_attribute = "42"
|
custom_attribute = "42"
|
||||||
|
|
||||||
def analyse_entry(self, entry, params):
|
def analyse_entry(self, entry, params):
|
||||||
logger.debug('Analysing with the example.')
|
self.log.debug('Analysing with the example.')
|
||||||
logger.debug('The answer to this response is: %s.' % params['parameter'])
|
self.log.debug('The answer to this response is: %s.' % params['parameter'])
|
||||||
resp = Response()
|
resp = Response()
|
||||||
entry['example:reversed'] = entry.text[::-1]
|
entry['example:reversed'] = entry.text[::-1]
|
||||||
entry['example:the_answer'] = params['parameter']
|
entry['example:the_answer'] = params['parameter']
|
||||||
|
8
k8s/README.md
Normal file
8
k8s/README.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Deploy senpy to a kubernetes cluster.
|
||||||
|
The files are templates, which need to be expanded with something like envsubst.
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
|
||||||
|
```
|
||||||
|
cat k8s/*.ya*ml | envsubst | kubectl apply -n senpy -f -
|
||||||
|
```
|
24
k8s/senpy-deployment.yaml
Normal file
24
k8s/senpy-deployment.yaml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
apiVersion: extensions/v1beta1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: senpy-$NAME-latest
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
role: $NAME-latest
|
||||||
|
app: test
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: senpy-latest
|
||||||
|
image: $IMAGEWTAG
|
||||||
|
imagePullPolicy: Always
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: "512Mi"
|
||||||
|
cpu: "1000m"
|
||||||
|
ports:
|
||||||
|
- name: web
|
||||||
|
containerPort: 5000
|
14
k8s/senpy-ingress.yaml
Normal file
14
k8s/senpy-ingress.yaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
apiVersion: extensions/v1beta1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: senpy-$NAME-ingress
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- host: senpy.cluster.gsi.dit.upm.es
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
backend:
|
||||||
|
serviceName: senpy-$NAME-latest
|
||||||
|
servicePort: 5000
|
12
k8s/senpy-svc.yaml
Normal file
12
k8s/senpy-svc.yaml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: senpy-$NAME-latest
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
ports:
|
||||||
|
- port: 5000
|
||||||
|
protocol: TCP
|
||||||
|
selector:
|
||||||
|
role: $NAME-latest
|
Loading…
Reference in New Issue
Block a user