mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-25 01:22:28 +00:00
Added k8s deployment
This commit is contained in:
parent
28f29d159a
commit
ce83fb3981
@ -1,18 +1,22 @@
|
|||||||
image: gsiupm/dockermake:latest
|
# 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
|
# When using dind, it's wise to use the overlayfs driver for
|
||||||
# improved performance.
|
# improved performance.
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
DOCKER_DRIVER: overlay
|
|
||||||
DOCKERFILE: Dockerfile
|
|
||||||
IMAGENAME: $CI_REGISTRY_IMAGE
|
IMAGENAME: $CI_REGISTRY_IMAGE
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
- push
|
- push
|
||||||
|
- deploy
|
||||||
- clean
|
- clean
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
|
||||||
|
|
||||||
.test: &test_definition
|
.test: &test_definition
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
@ -28,11 +32,8 @@ test-2.7:
|
|||||||
variables:
|
variables:
|
||||||
PYTHON_VERSION: "2.7"
|
PYTHON_VERSION: "2.7"
|
||||||
|
|
||||||
|
|
||||||
.image: &image_definition
|
.image: &image_definition
|
||||||
stage: push
|
stage: push
|
||||||
before_script:
|
|
||||||
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
|
|
||||||
script:
|
script:
|
||||||
- make -e push-$PYTHON_VERSION
|
- make -e push-$PYTHON_VERSION
|
||||||
only:
|
only:
|
||||||
@ -57,9 +58,16 @@ push-latest:
|
|||||||
- master
|
- master
|
||||||
- triggers
|
- triggers
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
stage: deploy
|
||||||
|
environment: test
|
||||||
|
script:
|
||||||
|
- make -e deploy
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
stage: clean
|
stage: clean
|
||||||
script:
|
script:
|
||||||
- make -e clean
|
- make -e clean
|
||||||
only:
|
when: manual
|
||||||
- master
|
|
35
Makefile
35
Makefile
@ -9,6 +9,15 @@ IMAGEWTAG=$(IMAGENAME):$(VERSION)
|
|||||||
DEVPORT=5000
|
DEVPORT=5000
|
||||||
action="test-${PYMAIN}"
|
action="test-${PYMAIN}"
|
||||||
|
|
||||||
|
KUBE_CA_PEM_FILE=""
|
||||||
|
KUBE_URL=""
|
||||||
|
KUBE_TOKEN=""
|
||||||
|
KUBECTL=docker run --rm -v $(KUBE_CA_PEM_FILE):/tmp/ca.pem -v $$PWD:/tmp/cwd/ -i lachlanevenson/k8s-kubectl --server="$(KUBE_URL)" --token="$(KUBE_TOKEN)" --certificate-authority="/tmp/ca.pem" -n $(KUBE_NAMESPACE)
|
||||||
|
CI_REGISTRY=docker.io
|
||||||
|
CI_REGISTRY_USER=gitlab
|
||||||
|
CI_BUILD_TOKEN=""
|
||||||
|
|
||||||
|
|
||||||
all: build run
|
all: build run
|
||||||
|
|
||||||
.FORCE:
|
.FORCE:
|
||||||
@ -37,7 +46,7 @@ quick_build: $(addprefix build-, $(PYMAIN))
|
|||||||
build: $(addprefix build-, $(PYVERSIONS))
|
build: $(addprefix build-, $(PYVERSIONS))
|
||||||
|
|
||||||
build-%: version Dockerfile-%
|
build-%: version Dockerfile-%
|
||||||
docker build -t '$(IMAGEWTAG)-python$*' -f Dockerfile-$* .;
|
docker build -t '$(IMAGEWTAG)-python$*' --cache-from $(IMAGENAME):python$* -f Dockerfile-$* .;
|
||||||
|
|
||||||
quick_test: $(addprefix test-,$(PYMAIN))
|
quick_test: $(addprefix test-,$(PYMAIN))
|
||||||
|
|
||||||
@ -53,8 +62,8 @@ dev: dev-$(PYMAIN)
|
|||||||
|
|
||||||
test-all: $(addprefix test-,$(PYVERSIONS))
|
test-all: $(addprefix test-,$(PYVERSIONS))
|
||||||
|
|
||||||
test-%: build-%
|
test-%:
|
||||||
docker run --rm --entrypoint /usr/local/bin/python -w /usr/src/app $(IMAGEWTAG)-python$* setup.py test
|
docker run --rm --entrypoint /usr/local/bin/python -w /usr/src/app $(IMAGENAME):python$* setup.py test
|
||||||
|
|
||||||
test: test-$(PYMAIN)
|
test: test-$(PYMAIN)
|
||||||
|
|
||||||
@ -71,8 +80,8 @@ pip_test-%: sdist
|
|||||||
pip_test: $(addprefix pip_test-,$(PYVERSIONS))
|
pip_test: $(addprefix pip_test-,$(PYVERSIONS))
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@docker ps -a | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[0] != "${VERSION}"){ print $$1;}}' | xargs docker rm -v 2>/dev/null|| true
|
@docker ps -a | grep $(IMAGENAME) | awk '{ split($$2, vers, "-"); if(vers[0] != "${VERSION}"){ print $$1;}}' | xargs docker rm -v 2>/dev/null|| true
|
||||||
@docker images | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[0] != "${VERSION}"){ print $$1":"$$2;}}' | xargs docker rmi 2>/dev/null|| true
|
@docker images | grep $(IMAGENAME) | awk '{ split($$2, vers, "-"); if(vers[0] != "${VERSION}"){ print $$1":"$$2;}}' | xargs docker rmi 2>/dev/null|| true
|
||||||
@docker stop $(addprefix $(NAME)-dev,$(PYVERSIONS)) 2>/dev/null || true
|
@docker stop $(addprefix $(NAME)-dev,$(PYVERSIONS)) 2>/dev/null || true
|
||||||
@docker rm $(addprefix $(NAME)-dev,$(PYVERSIONS)) 2>/dev/null || true
|
@docker rm $(addprefix $(NAME)-dev,$(PYVERSIONS)) 2>/dev/null || true
|
||||||
|
|
||||||
@ -93,12 +102,17 @@ run-%: build-%
|
|||||||
|
|
||||||
run: run-$(PYMAIN)
|
run: run-$(PYMAIN)
|
||||||
|
|
||||||
push-latest: build-$(PYMAIN)
|
push-latest: $(addprefix push-latest-,$(PYVERSIONS))
|
||||||
docker tag '$(IMAGEWTAG)-python$(PYMAIN)' '$(IMAGEWTAG)'
|
docker tag '$(IMAGEWTAG)-python$(PYMAIN)' '$(IMAGEWTAG)'
|
||||||
docker tag '$(IMAGEWTAG)-python$(PYMAIN)' '$(IMAGENAME)'
|
docker tag '$(IMAGEWTAG)-python$(PYMAIN)' '$(IMAGENAME)'
|
||||||
docker push '$(IMAGENAME):latest'
|
docker push '$(IMAGENAME):latest'
|
||||||
docker push '$(IMAGEWTAG)'
|
docker push '$(IMAGEWTAG)'
|
||||||
|
|
||||||
|
push-latest-%: build-%
|
||||||
|
docker tag $(IMAGENAME):$(VERSION)-python$* $(IMAGENAME):python$*
|
||||||
|
docker push $(IMAGENAME):$(VERSION)-python$*
|
||||||
|
docker push $(IMAGENAME):python$*
|
||||||
|
|
||||||
push-%: build-%
|
push-%: build-%
|
||||||
docker push $(IMAGENAME):$(VERSION)-python$*
|
docker push $(IMAGENAME):$(VERSION)-python$*
|
||||||
|
|
||||||
@ -109,4 +123,11 @@ push: $(addprefix push-,$(PYVERSIONS))
|
|||||||
ci:
|
ci:
|
||||||
gitlab-runner exec docker --docker-volumes /var/run/docker.sock:/var/run/docker.sock --env CI_PROJECT_NAME=$(NAME) ${action}
|
gitlab-runner exec docker --docker-volumes /var/run/docker.sock:/var/run/docker.sock --env CI_PROJECT_NAME=$(NAME) ${action}
|
||||||
|
|
||||||
.PHONY: test test-% test-all build-% build test pip_test run yapf push-main push-% dev ci version .FORCE
|
deploy:
|
||||||
|
$(KUBECTL) delete -n senpy secret $(CI_REGISTRY) || true
|
||||||
|
@$(KUBECTL) create -n $(NAME) secret docker-registry $(CI_REGISTRY) --docker-server=$(CI_REGISTRY) --docker-username=$(CI_REGISTRY_USER) --docker-email=$(CI_REGISTRY_USER) --docker-password=$(CI_BUILD_TOKEN)
|
||||||
|
$(KUBECTL) apply -f /tmp/cwd/k8s/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: test test-% test-all build-% build test pip_test run yapf push-main push-% dev ci version .FORCE deploy
|
||||||
|
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-latest
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
role: senpy-latest
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: senpy-latest
|
||||||
|
image: gsiupm/senpy:latest
|
||||||
|
args:
|
||||||
|
- "--default-plugins"
|
||||||
|
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-ingress
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- host: latest.senpy.cluster.gsi.dit.upm.es
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
backend:
|
||||||
|
serviceName: senpy-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-latest
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
ports:
|
||||||
|
- port: 5000
|
||||||
|
protocol: TCP
|
||||||
|
selector:
|
||||||
|
role: senpy-latest
|
Loading…
Reference in New Issue
Block a user