Want to learn how to manage and deploy Magnolia in a microservices architecture? Here we will present the main patterns identified in such an architecture and describe how to implement them with Magnolia. We demonstrate an experimental approach based on Docker to create and orchestrate several microservices connected to Magnolia.
5. NOT A FREE LUNCH
Distributed systems are complex
๏ Testability
๏ Eventual consistency
๏ Operational complexity
http://highscalability.com/blog/2014/4/8/microservices-not-a-free-lunch.html
15. WHICH SERVICES?
References must be checked
- Question / Answer
- Question / User
- Answer / User
- Rating / Answer
- Rating / Question
Users have only one vote
Answers are single threaded
USERS
QUESTIONS ANSWERS
RATINGS
23. TIPS & TRICKS
๏ Follows the recommendations of
the Filesystem Hierarchy Standard
๏ Configuration through
environment variables
- INSTANCE_TYPE
- DB_TYPE
- DB_SCHEMA
- DB_USERNAME
- DB_PASSWORD
- DEVELOP_MODE
- CLUSTER_ID
๏ Tomcat & JVM settings can be
customised
COPY setenv.sh $CATALINA_BASE/bin/setenv.sh
๏ Map a volume from the host to the
container to persist the JCR
repository
-v /var/lib/magnolia/repositories:/var/lib/
magnolia/repositories
๏ Map a volume from the host to the
container for the resources
-v $MAGNOLIA_WEB_RESOURCES:/var/opt/magnolia
25. FROM DEV …
Build a clone of the production environment locally with Docker Compose
db-author:
image: postgres
environment:
- POSTGRES_USER=magnolia
- POSTGRES_PASSWORD=mysecretpassword
author:
image: nicolasbarbe/ms-frontend:1.0-SNAPSHOT
command: run
ports:
- "3000:8080"
links:
- db-author:db
environment:
- INSTANCE_TYPE=author
- DB_TYPE=postgresql
- DB_ADDRESS=db
- DB_PORT=5432
- DB_SCHEMA=magnolia
- DB_USERNAME=magnolia
- DB_PASSWORD=mysecretpassword
Create a new container for
the database
Create a network link between
the database and magnolia
Create another container for Magnolia
Configure the instance as an author
and to use the postgresql driver
Thanks to the link, we don’t have to specify the
database IP address
26. … TO PROD
๏ Use a full Docker stack
- Reuse the same Docker Compose definition
- If the architectures are slightly different use extends keyword
- Use Docker Swarm to deploy on multiple hosts
- Use Docker Machine to provision the hosts
๏ But, wait, Docker Compose/Swarm are still in Beta
- Use Kubernetes if you want a cluster with dynamic provisioning and hosts allocation
- Use Ansible if you want static hosts provisioning and allocation (see my blog post*)
๏ In all cases use the same Docker Images !
* http://nicolasbarbe.com/2015/07/13/magnolia-devops-automate-deployment/
27. SERVICE DISCOVERY
Build a Service Registry to let Magnolia discovers the services automatically
The Service Registry
- Defines microservices in a YAML file
- Discovers the services through
environment variables, Java system
properties, from the JCR or by value
- Injects services in the templates
- Provides a generic connector to
build dedicated content apps in
YAML
services:
questions:
connection:
host: QUESTIONS_QUERIES_HOST
port: QUESTIONS_QUERIES_PORT
type: env
apiVersion: v1
resource:
name: question
properties:
- name: id
type: Integer
- name: title
type: String
- name: description
https://github.com/nicolasbarbe/magnolia-http-utils