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

Commit

Permalink
Implement and dockerize demo application (#38, #34)
Browse files Browse the repository at this point in the history
- add jason/demo app
- extend Makefile commands

Additionally:
- create 1k rooms on Medea start
- increase logger buffer to 2048 and block on logger overflow
- dockerize Yarn usage in Makefile
  • Loading branch information
alexlapa authored Jul 25, 2019
1 parent c02e701 commit 7dca0ad
Show file tree
Hide file tree
Showing 16 changed files with 413 additions and 52 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ indent_size = 2
indent_style = space
indent_size = 2

[*.html]
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab
indent_size = 4
Expand All @@ -40,3 +44,7 @@ indent_size = 4
[hooks/*]
indent_style = space
indent_size = 2

[**/nginx{/*,.*}.conf]
indent_style = space
indent_size = 2
4 changes: 4 additions & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--cache-folder ".cache/yarn/"
--non-interactive true

network-timeout 600000
98 changes: 82 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ eq = $(if $(or $(1),$(2)),$(and $(findstring $(1),$(2)),\
# Project parameters #
######################

IMAGE_NAME := $(strip $(shell grep 'COMPOSE_IMAGE_NAME=' .env | cut -d '=' -f2))
MEDEA_IMAGE_NAME := $(strip \
$(shell grep 'COMPOSE_IMAGE_NAME=' .env | cut -d '=' -f2))
DEMO_IMAGE_NAME := instrumentisto/medea-demo

RUST_VER := 1.36

Expand All @@ -26,7 +28,7 @@ RUST_VER := 1.36
# Aliases #
###########

build: docker.build
build: docker.build.medea


# Resolve all project dependencies.
Expand All @@ -46,12 +48,15 @@ lint: cargo.lint
fmt: cargo.fmt


# Run all project application locally in development mode.
up.demo: docker.up.demo


# Run Medea and Jason development environment.
#
# Usage:
# make up
# make up.dev

up:
up.dev:
$(MAKE) -j3 up.coturn up.jason up.medea


Expand Down Expand Up @@ -103,12 +108,22 @@ cargo.lint:
# for example: make yarn cmd='upgrade'
#
# Usage:
# make yarn [cmd=(install|<yarn-cmd>)]
# make yarn [cmd=('install --pure-lockfile'|<yarn-cmd>)]
# [proj=(e2e|demo)]
# [dockerized=(yes|no)]

yarn-cmd =
yarn-cmd = $(if $(call eq,$(cmd),),install --pure-lockfile,$(cmd))
yarn-proj-dir = $(if $(call eq,$(proj),demo),jason/demo,jason/e2e-demo)

yarn:
yarn --cwd=jason/e2e-demo/ $(if $(call eq,$(cmd),),install,$(cmd))
ifneq ($(dockerized),no)
docker run --rm --network=host -v "$(PWD)":/app -w /app \
-u $(shell id -u):$(shell id -g) \
node:latest \
make yarn cmd='$(yarn-cmd)' proj=$(proj) dockerized=no
else
yarn --cwd=$(yarn-proj-dir) $(yarn-cmd)
endif



Expand Down Expand Up @@ -168,19 +183,50 @@ endif



######################
# Releasing commands #
######################

# Build and publish Jason application to npm
#
# Usage:
# make release.jason

release.jason:
@rm -rf jason/pkg/
wasm-pack build -t web jason
wasm-pack publish




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

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

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

docker.build.demo:
@make yarn proj=demo
docker build \
-t $(docker-build-demo-image-name):$(if $(call eq,$(TAG),),dev,$(TAG)) \
jason/demo


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

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

docker.build:
docker.build.medea:
ifneq ($(no-cache),yes)
docker run --rm --network=host -v "$(PWD)":/app -w /app \
-u $(shell id -u):$(shell id -g) \
Expand All @@ -201,14 +247,33 @@ endif
--build-arg rustc_opts=$(if \
$(call eq,$(debug),no),--release,) \
--build-arg cargo_home=.cache/cargo,) \
-t $(docker-build-image-name):$(if $(call eq,$(TAG),),dev,$(TAG)) .
-t $(docker-build-medea-image-name):$(if $(call eq,$(TAG),),dev,$(TAG)) .
$(call docker.build.clean.ignore)
define docker.build.clean.ignore
@sed -i $(if $(call eq,$(shell uname -s),Darwin),'',) \
/^!target\/d .dockerignore
endef


# Stop demo application in Docker Compose environment
# and remove all related containers.
#
# Usage:
# make docker.down.demo

docker.down.demo:
docker-compose -f jason/demo/docker-compose.yml down --rmi=local -v


# Run demo application in Docker Compose environment.
#
# Usage:
# make docker.up.demo

docker.up.demo: docker.down.demo
docker-compose -f jason/demo/docker-compose.yml up




####################
Expand Down Expand Up @@ -248,10 +313,11 @@ up.medea:
# .PHONY section #
##################

.PHONY: build cargo cargo.fmt cargo.lint \
docker.build \
.PHONY: build \
cargo cargo.fmt cargo.lint \
docker.build.demo docker.build.medea docker.down.demo docker.up.demo \
docs docs.rust \
release.jason \
test test.unit \
up up.coturn up.jason up.medea \
up up.coturn up.demo up.dev up.jason up.medea \
yarn

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

/yarn-error.log
28 changes: 28 additions & 0 deletions jason/demo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Stage 'dist' creates project distribution.
#

# https://hub.docker.com/_/node
FROM node:alpine AS dist

COPY / /npm/

RUN cd /npm/ \
&& yarn install --pure-lockfile




#
# Stage 'runtime' creates final Docker image to use in runtime.
#

# https://hub.docker.com/_/nginx
FROM nginx:stable-alpine AS runtime

COPY conf/nginx.vh.conf /etc/nginx/conf.d/default.conf

COPY index.html /app/
COPY --from=dist /npm/node_modules/jason-alexlapa/ /app/js/

WORKDIR /app
10 changes: 10 additions & 0 deletions jason/demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Medea Demo
==========

Demo application for performing video calls via [Medea] media server.





[Medea]: https://github.com/instrumentisto/medea
18 changes: 18 additions & 0 deletions jason/demo/conf/nginx.vh.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
server {
listen 80 default_server;
server_name _;

root /app;
index index.html;
charset utf-8;

location = /js/jason_alexlapa_bg.wasm {
types { } default_type "application/wasm";
}

# Disable unnecessary access logs.
location = /favicon.ico {
access_log off;
log_not_found off;
}
}
36 changes: 36 additions & 0 deletions jason/demo/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: "2"

services:
webclient:
container_name: demo-webclient
image: instrumentisto/medea-demo:dev
ports:
- "80:80"
- "6379:6379" # coturn redis
- "8080:8080" # medea ws
volumes:
- ./conf/nginx.vh.conf:/etc/nginx/conf.d/default.conf
medea:
container_name: demo-medea
image: instrumentisto/medea:dev
depends_on: ["coturn-db"]
environment:
MEDEA_LOG.LEVEL: "DEBUG"
network_mode: service:webclient
coturn:
container_name: demo-coturn
image: instrumentisto/coturn:4.5
depends_on: ["coturn-db"]
command:
- --log-file=stdout
volumes:
- ../../dev/coturn/turnserver.conf:/etc/coturn/turnserver.conf:ro
- ../../.cache/coturn/data:/var/lib/coturn
network_mode: host
coturn-db:
container_name: demo-coturn-db
image: redis:alpine
command: ["redis-server", "/etc/redis.conf"]
volumes:
- ../../dev/coturn/redis.conf:/etc/redis.conf:ro
network_mode: service:webclient
Loading

0 comments on commit 7dca0ad

Please sign in to comment.