Multi tenancy example using spring boot and the Hibernate SCHEMA strategy.
Pre-requisites
- Java 1.8
- Docker
- Docker-compose
apt-get install apparmor lxc cgroup-lite
wget -qO- https://get.docker.com/ | sh
sudo usermod -aG docker YourUserNameHere
sudo service docker restart
MAKE SURE YOU HAVE AN UP TO DATE VERSION OF DOCKER COMPOSE
To check the version:
docker-compose --version
To install the 1.6.0:
sudo su
curl -L https://github.com/docker/compose/releases/download/1.6.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
exit
docker-compose up
docker-compose up mysql
./gradlew bootRun
docker-compose up mysql
mysql -u root -p1234 -h 127.0.0.1 -e "GRANT ALL ON *.* TO 'myuser'@'%'; FLUSH PRIVILEGES;"
mysql -u myuser -pmypass -h 127.0.0.1 < db_migration.sql
At this point there should be two identical databases tenant_a
and tenant_b
with privileges such that the myuser
account can access both
./gradlew clean build buildDocker
docker-compose up api
curl -H "X-TenantID:tenant_a" localhost:8080/person/1
curl -i -X POST -H "X-TenantID:tenant_a" -H "Content-Type:application/json" -d '{ "firstName" : "Frodo", "lastName" : "Baggins" }' http://localhost:8080/person/