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

Commit

Permalink
Kubernetes and Helm integration for medea-demo app (#41, #34)
Browse files Browse the repository at this point in the history
- create 'medea-demo' Helm chart
- configure 'medea-demo' deployment for Minikube and 'staging' Kubernetes clusters
- extend Makefile with Helm and Minikube usage commands
  • Loading branch information
alexlapa authored Aug 6, 2019
1 parent 7dca0ad commit f5d407d
Show file tree
Hide file tree
Showing 29 changed files with 1,090 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

/.cache/

/charts/

/target/
**/*.rs.bk
237 changes: 216 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ DEMO_IMAGE_NAME := instrumentisto/medea-demo

RUST_VER := 1.36

CURRENT_BRANCH := $(strip $(shell git branch | grep \* | cut -d ' ' -f2))




Expand Down Expand Up @@ -48,6 +50,27 @@ lint: cargo.lint
fmt: cargo.fmt


test: test.unit




####################
# Running commands #
####################

down.demo: docker.down.demo


# Run Coturn STUN/TURN server.
#
# Usage:
# make up.coturn

up.coturn:
docker-compose up


up.demo: docker.up.demo


Expand All @@ -60,7 +83,22 @@ up.dev:
$(MAKE) -j3 up.coturn up.jason up.medea


test: test.unit
# Run Jason E2E demo in development mode.
#
# Usage:
# make up.jason

up.jason:
npm run start --prefix=jason/e2e-demo


# Run Medea media server in development mode.
#
# Usage:
# make up.medea

up.medea:
cargo run --bin medea



Expand Down Expand Up @@ -198,31 +236,40 @@ release.jason:
wasm-pack publish


release.helm: helm.package.release




###################
# Docker commands #
###################

docker-env = $(strip $(if $(call eq,$(minikube),yes),\
$(subst export,,$(shell minikube docker-env | cut -d '\#' -f1)),))

# Build Docker image for demo application.
#
# Usage:
# make docker.build.demo [TAG=(dev|<tag>)]
# [minikube=(no|yes)]

docker-build-demo-image-name = $(DEMO_IMAGE_NAME)

docker.build.demo:
@make yarn proj=demo
docker build \
$(docker-env) \
docker build $(if $(call eq,$(minikube),yes),,--network=host) --force-rm \
-t $(docker-build-demo-image-name):$(if $(call eq,$(TAG),),dev,$(TAG)) \
jason/demo


# Build medea project Docker image.
#
# Usage:
# make docker.build.medea [TAG=(dev|<tag>)]
# [debug=(yes|no)] [no-cache=(no|yes)]
# make docker.build.medea [TAG=(dev|<tag>)] [debug=(yes|no)]
# [no-cache=(no|yes)]
# [minikube=(no|yes)]

docker-build-medea-image-name = $(MEDEA_IMAGE_NAME)

Expand All @@ -237,7 +284,8 @@ ifneq ($(no-cache),yes)
endif
$(call docker.build.clean.ignore)
@echo "!target/$(if $(call eq,$(debug),no),release,debug)/" >> .dockerignore
docker build --network=host --force-rm \
$(docker-env) \
docker build $(if $(call eq,$(minikube),yes),,--network=host) --force-rm \
$(if $(call eq,$(no-cache),yes),\
--no-cache --pull,) \
$(if $(call eq,$(IMAGE),),\
Expand Down Expand Up @@ -276,35 +324,178 @@ docker.up.demo: docker.down.demo



####################
# Running commands #
####################
##############################
# Helm and Minikube commands #
##############################

# Run Coturn STUN/TURN server.
helm-cluster = $(if $(call eq,$(cluster),),minikube,$(cluster))
helm-namespace = $(if $(call eq,$(helm-cluster),minikube),kube,staging)-system
helm-cluster-args = $(strip \
--kube-context=$(helm-cluster) --tiller-namespace=$(helm-namespace))

helm-chart = $(if $(call eq,$(chart),),medea-demo,$(chart))
helm-chart-dir = jason/demo/chart/medea-demo
helm-chart-vals-dir = jason/demo

helm-release = $(if $(call eq,$(release),),,$(release)-)$(helm-chart)
helm-release-namespace = $(strip \
$(if $(call eq,$(helm-cluster),staging),staging,default))

# Run Helm command in context of concrete Kubernetes cluster.
#
# Usage:
# make up.coturn
# make helm [cmd=(--help|'<command>')]
# [cluster=(minikube|staging)]

up.coturn:
docker-compose up
helm:
helm $(helm-cluster-args) $(if $(call eq,$(cmd),),--help,$(cmd))


# Run Jason E2E demo in development mode.
# Remove Helm release of project Helm chart from Kubernetes cluster.
#
# Usage:
# make up.jason
# make helm.down [chart=medea-demo] [release=<release-name>]
# [cluster=(minikube|staging)]

up.jason:
npm run start --prefix=jason/e2e-demo
helm.down:
$(if $(shell helm ls $(helm-cluster-args) | grep '$(helm-release)'),\
helm del --purge $(helm-cluster-args) $(helm-release) ,\
@echo "--> No '$(helm-release)' release found in $(helm-cluster) cluster")


# Run Medea media server in development mode.
# Upgrade (or initialize) Tiller (server side of Helm) of Minikube.
#
# Usage:
# make up.medea
# make helm.init [client-only=no [upgrade=(yes|no)]]
# [client-only=yes]

up.medea:
cargo run --bin medea
helm.init:
helm init --wait \
$(if $(call eq,$(client-only),yes),\
--client-only,\
--kube-context=minikube --tiller-namespace=kube-system \
$(if $(call eq,$(upgrade),no),,--upgrade))


# Lint project Helm chart.
#
# Usage:
# make helm.lint [chart=medea-demo]

helm.lint:
helm lint $(helm-chart-dir)/


# List all Helm releases in Kubernetes cluster.
#
# Usage:
# make helm.list [cluster=(minikube|staging)]

helm.list:
helm ls $(helm-cluster-args)


# Build Helm package from project Helm chart.
#
# Usage:
# make helm.package [chart=medea-demo]

helm-package-dir = .cache/helm/packages

helm.package:
@rm -rf $(helm-package-dir)
@mkdir -p $(helm-package-dir)/
helm package --destination=$(helm-package-dir)/ $(helm-chart-dir)/


# Build and publish project Helm package to GitHub Pages.
#
# Usage:
# make helm.package.release [chart=medea-demo] [build=(yes|no)]

helm.package.release:
ifneq ($(build),no)
@make helm.package chart=$(helm-chart)
endif
git fetch origin gh-pages:gh-pages
git checkout gh-pages
git reset --hard
@mkdir -p charts/
cp -rf $(helm-package-dir)/* charts/
if [ -n "$$(git add -v charts/)" ]; then \
helm repo index charts/ \
--url=https://instrumentisto.github.io/medea/charts ; \
git add -v charts/ ; \
git commit -m "Release '$(helm-chart)' Helm chart" ; \
fi
git checkout $(CURRENT_BRANCH)
git push origin gh-pages


# Run project Helm chart in Kubernetes cluster as Helm release.
#
# Usage:
# make helm.up [chart=medea-demo] [release=<release-name>]
# [cluster=minikube [rebuild=(no|yes) [no-cache=(no|yes)]]]
# [cluster=staging]
# [wait=(yes|no)]

helm.up:
ifeq ($(wildcard $(helm-chart-vals-dir)/my.$(helm-cluster).vals.yaml),)
touch $(helm-chart-vals-dir)/my.$(helm-cluster).vals.yaml
endif
ifeq ($(helm-cluster),minikube)
ifeq ($(helm-chart),medea-demo)
ifeq ($(rebuild),yes)
@make docker.build.demo minikube=yes TAG=dev
@make docker.build.medea no-cache=$(no-cache) minikube=yes TAG=dev
endif
endif
endif
helm upgrade --install --force $(helm-cluster-args) \
$(helm-release) $(helm-chart-dir)/ \
--namespace=$(helm-release-namespace) \
--values=$(helm-chart-vals-dir)/$(helm-cluster).vals.yaml \
--values=$(helm-chart-vals-dir)/my.$(helm-cluster).vals.yaml \
--set server.deployment.revision=$(shell date +%s) \
--set web-client.deployment.revision=$(shell date +%s) \
$(if $(call eq,$(wait),no),,\
--wait )


# Bootstrap Minikube cluster (local Kubernetes) for development environment.
#
# The bootsrap script is updated automatically to the latest version every day.
# For manual update use 'update=yes' command option.
#
# Usage:
# make minikube.boot [update=(no|yes)]
# [driver=(virtualbox|hyperkit|hyperv)]
# [k8s-version=<kubernetes-version>]

minikube.boot:
ifeq ($(update),yes)
$(call minikube.boot.download)
else
ifeq ($(wildcard $(HOME)/.minikube/bootstrap.sh),)
$(call minikube.boot.download)
else
ifneq ($(shell find $(HOME)/.minikube/bootstrap.sh -mmin +1440),)
$(call minikube.boot.download)
endif
endif
endif
@$(if $(cal eq,$(driver),),,MINIKUBE_VM_DRIVER=$(driver)) \
$(if $(cal eq,$(k8s-version),),,MINIKUBE_K8S_VER=$(k8s-version)) \
$(HOME)/.minikube/bootstrap.sh
define minikube.boot.download
$()
@mkdir -p $(HOME)/.minikube/
@rm -f $(HOME)/.minikube/bootstrap.sh
curl -fL -o $(HOME)/.minikube/bootstrap.sh \
https://raw.githubusercontent.com/instrumentisto/toolchain/master/minikube/bootstrap.sh
@chmod +x $(HOME)/.minikube/bootstrap.sh
endef



Expand All @@ -317,7 +508,11 @@ up.medea:
cargo cargo.fmt cargo.lint \
docker.build.demo docker.build.medea docker.down.demo docker.up.demo \
docs docs.rust \
release.jason \
down.demo \
helm helm.down helm.init helm.lint helm.list \
helm.package helm.package.release helm.up \
minikube.boot \
release.jason release.helm \
test test.unit \
up up.coturn up.demo up.dev up.jason up.medea \
yarn
2 changes: 2 additions & 0 deletions dev/coturn/redis.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
requirepass turn
timeout 0
tcp-keepalive 60
maxmemory 16mb
maxmemory-policy allkeys-lfu
2 changes: 0 additions & 2 deletions dev/coturn/turnserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ fingerprint
no-cli
no-tls
no-dtls
min-port=49160
max-port=49200
realm=medea
redis-userdb="ip=127.0.0.1 port=6379 dbname=0 password=turn"
user=USER:PASS
8 changes: 8 additions & 0 deletions jason/demo/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store

chart/
!chart/medea-demo/conf/nginx.vh.conf

*.vals.yaml

yarn-error.log
2 changes: 2 additions & 0 deletions jason/demo/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/node_modules/

/my.*.vals.yaml

/yarn-error.log
2 changes: 1 addition & 1 deletion jason/demo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN cd /npm/ \
# https://hub.docker.com/_/nginx
FROM nginx:stable-alpine AS runtime

COPY conf/nginx.vh.conf /etc/nginx/conf.d/default.conf
COPY chart/medea-demo/conf/nginx.vh.conf /etc/nginx/conf.d/default.conf

COPY index.html /app/
COPY --from=dist /npm/node_modules/jason-alexlapa/ /app/js/
Expand Down
10 changes: 10 additions & 0 deletions jason/demo/chart/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[*.tpl]
indent_style = space
indent_size = 2
max_line_length = off

[*.txt]
max_line_length = off

[*.yaml]
max_line_length = off
3 changes: 3 additions & 0 deletions jason/demo/chart/medea-demo/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store

.gitignore
4 changes: 4 additions & 0 deletions jason/demo/chart/medea-demo/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
name: medea-demo
version: 0.1.0
appVersion: 0.1.0
Loading

0 comments on commit f5d407d

Please sign in to comment.