Skip to content

Commit

Permalink
Add Docker Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
denschu committed Jul 2, 2015
1 parent e1ee8ef commit 4ae3722
Show file tree
Hide file tree
Showing 21 changed files with 274 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,5 @@
/.settings/
/.project
/logs/
.vagrant
dump.rdb
45 changes: 38 additions & 7 deletions README.md
Expand Up @@ -14,21 +14,45 @@ An SSO mechanism is used for security, the infrastructure setup to support this
Clone this repository, jump into the subdirectory movie-database-vagrant and do

vagrant up

That will take a while (and it will change some of the application.properties files, don't be confused about that). Edit your /private/etc/hosts file and add the line

192.168.56.13 moviedatabase.com

When everything is started, access [http://moviedatabase.com](http://moviedatabase.com) in your browser for the application. Currently there are two users, admin/admin and user/user. For monitoring with Spring Boot Admin access [http://192.168.56.13:8083](http://192.168.56.13:8083).

This repo that you cloned is shared with the virtual machine. So you can change things in your IDE, log into the virtual machine and rebuild / restart changed services there.

### Build & Run with Docker

For the installation of Docker and Docker Compose please refer to [https://docs.docker.com/installation] and [https://docs.docker.com/compose/install].

Edit your /private/etc/hosts file and add the lines (on the Mac please verify the IP with "boot2docker ip")

192.168.59.103 moviedatabase.com

Clone this repository and do

./build.sh
docker-compose up

When everything is started, access [http://moviedatabase.com](http://moviedatabase.com) in your browser for the application. Currently there are two users, admin/admin and user/user. For monitoring with Spring Boot Admin access [http://192.168.59.103:8083](http://192.168.59.103:8083).

### Build & Run without virtualization

You need to have [Homebrew](http://brew.sh/) installed to do the following.

#### nginx
Follow [these](https://gist.github.com/netpoetica/5879685) instructions to install nginx. When editing the /private/etc/hosts file, add the line
Follow [these](https://gist.github.com/netpoetica/5879685) instructions to install nginx. When editing the /private/etc/hosts file, add the lines

127.0.0.1 moviedatabase.com
127.0.0.1 redis
127.0.0.1 monitoring
127.0.0.1 navigation
127.0.0.1 actors
127.0.0.1 movies
127.0.0.1 shop

Now copy [moviedatabase.conf](https://github.com/tobiasflohre/movie-database/blob/master/moviedatabase.conf) to /usr/local/etc/nginx/conf.d/. Start nginx with `sudo nginx`, stop it with `sudo nginx -s stop`.

#### Redis
Expand All @@ -47,32 +71,39 @@ Redis should now reply

PONG

Update application.properties in movie-database-movies and movie-database-actors and set
##### Mac

spring.redis.host=127.0.0.1

You can install Redis with Homebrew

brew install redis

And start it with

##### Mac and Windows
redis-server

One fast way to get Redis running is to use a Docker image. If you're on Mac or Windows, you'll need to install [Boot2Docker](http://boot2docker.io/) first and start it. My colleague Ben Ripkens wrote a [nice tool](https://github.com/bripkens/dock) to install standard Docker images fast. To install it, do the following
##### Alternative way for Mac and Windows

Another fast way to get Redis running is to use a Docker image. If you're on Mac or Windows, you'll need to install [Boot2Docker](http://boot2docker.io/) first and start it. My colleague Ben Ripkens wrote a [nice tool](https://github.com/bripkens/dock) to install standard Docker images fast. To install it, do the following

brew tap bripkens/dock
brew install dock

To install and startup Redis:

dock redis

Now Redis is running under 192.168.59.103:6379, which is exactly what the movie database expects. If you already have a Redis installed somewhere else, take a look at the `application.properties` files contained in the projects, there you may change the host and port used for connecting to Redis (for changing the port you need to add the property `spring.redis.port`, for a list of all Spring Boot properties take a look [here](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#common-application-properties)).

#### Running the applications

Now clone this repository and check out master. From command line you may just call `./buildAndStartup.sh`. This script stops boot2docker, nginx and all movie-database applications and then builds all applications, starts boot2docker and Redis, starts nginx, copies the static Angular app to a specific place and then starts all movie-database applications. You need to have `mvn` and `java` and `boot2docker` and `dock` and `grunt` and `bower` on your path for that (and maybe some other stuff, better take a look at the script). If you're not on OSX it should be easy to adapt the script to your OS. I piped the logs to `dev/null` because the applications themselves are logging to `/tmp`.
Now clone this repository and check out master. From command line you may just call `./build.sh` and then `./startup.sh`. The first script builds all the applactions and the second script stops all services and then starts all applications, starts Redis, starts nginx, copies the static Angular app to a specific place and then starts all movie-database applications. You need to have `mvn` and `java` and `grunt` and `bower` on your path for that (and maybe some other stuff, better take a look at the script). If you're not on OSX it should be easy to adapt the script to your OS. I piped the logs to `dev/null` because the applications themselves are logging to `/tmp`.

Alternatively start nginx and Redis yourself, build the Angular app yourself and copy it to the folder accessed by nginx, and then in your IDE import all Maven projects, then run the class `ShopApplication` in the project movie-database-shop-rest, the class `NavigationApplication` in the project movie-database-navigation, the class `ActorsApplication` in the project movie-database-actors, the class `MoviesApplication` in the project movie-database-movies and the class `MonitoringApplication`in the project movie-database-monitoring.

Then access [http://moviedatabase.com](http://moviedatabase.com) in your browser for the application. Currently there are two users, admin/admin and user/user. For monitoring with Spring Boot Admin access [http://localhost:8083](http://localhost:8083).

### Build & Run without security

If you really shy away from installing nginx and Redis, you may just start the applications without security. Remove the dependency to movie-database-security from movie-database-movies and movie-database-actors, then remove the reference to `SecurityConfiguration` from those two projects (making them compile-clean again). Now start `NavigationApplication` and `MoviesApplication` (or `ActorsApplication`) and browse to [http://localhost:8080/movie-app](http://localhost:8080/movie-app) ([http://localhost:8082/actor-app](http://localhost:8082/actor-app)). Navigation links won't work, search works.

## Build & Run (classic branch)
Expand Down
2 changes: 1 addition & 1 deletion Vagrantfile
Expand Up @@ -17,6 +17,6 @@ Vagrant.configure("2") do |config|
vb.customize ["modifyvm", :id, "--memory", "4096", "--cpus", "2"]
vb.name = "movie-database"
end

#config.vm.provision :shell, :inline => "sudo ln -fs /home/vagrant/share/vagrant-etc-hosts /etc/hosts"
config.vm.provision :shell, path: "init.sh"
end
10 changes: 10 additions & 0 deletions build.sh
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
echo "Build all services..."
mvn clean install
cd movie-database-shop-app
bower install
grunt
sudo chmod 777 /opt/moviedatabase
rm -rf /opt/moviedatabase/shop-app
cp -R dist/. /opt/moviedatabase/shop-app
cd ..
47 changes: 47 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,47 @@
# Security Storage
redis:
image: redis
movies:
build: movie-database-movies
ports:
- "8080:8080"
links:
- redis
- monitoring
- navigation
actors:
build: movie-database-actors
ports:
- "8082:8082"
links:
- redis
- monitoring
- navigation
navigation:
build: movie-database-navigation
ports:
- "8081:8081"
links:
- redis
- monitoring
shop:
build: movie-database-shop-rest
ports:
- "8084:8084"
links:
- redis
- monitoring
shopgui:
build: movie-database-shop-app
ports:
- "80:80"
links:
- movies
- actors
- navigation
- shop
monitoring:
build: movie-database-monitoring
ports:
- "8083:8083"

2 changes: 1 addition & 1 deletion init.sh
Expand Up @@ -19,7 +19,7 @@ fi
cd $MOVIE_DATABASE_HOME

# fix redis host
find . -type f -name application.properties -exec sed -i 's/192.168.59.103/127.0.0.1/g' {} \;''
#find . -type f -name application.properties -exec sed -i 's/192.168.59.103/127.0.0.1/g' {} \;''

mvn clean install

Expand Down
19 changes: 19 additions & 0 deletions movie-database-actors/Dockerfile
@@ -0,0 +1,19 @@
FROM java:7
MAINTAINER Dennis Schulte <mail@dennis-schulte.de>

# install updates
RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/*

# default log directory
#VOLUME ["/data/log"]

# copy spring boot jar as 'service.jar'
COPY target/movie-database-*.jar /service.jar

# service port
EXPOSE 8082

# define default jar name
ENTRYPOINT java $JVM_OPTS -jar /service.jar $ARGS
Expand Up @@ -2,11 +2,11 @@ spring.application.name=@pom.artifactId@
info.version=@pom.version@
info.stage=test
server.port=8082
moviedatabase.navigation.url.base=http://localhost:8081
moviedatabase.navigation.url.base=http://navigation:8081
spring.thymeleaf.cache=false
spring.redis.host=192.168.59.103
spring.redis.host=redis
server.context-path=/actor-app
spring.boot.admin.url=http://localhost:8083
spring.boot.admin.url=http://monitoring:8083
spring.boot.admin.client.url=http://moviedatabase.com/actor-app
http.mappers.jsonPrettyPrint=true
logging.file=/opt/moviedatabase/logs/@pom.artifactId@/@pom.artifactId@.log
19 changes: 19 additions & 0 deletions movie-database-monitoring/Dockerfile
@@ -0,0 +1,19 @@
FROM java:7
MAINTAINER Dennis Schulte <mail@dennis-schulte.de>

# install updates
RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/*

# default log directory
#VOLUME ["/data/log"]

# copy spring boot jar as 'service.jar'
COPY target/movie-database-*.jar /service.jar

# service port
EXPOSE 8083

# define default jar name
ENTRYPOINT java $JVM_OPTS -jar /service.jar $ARGS
19 changes: 19 additions & 0 deletions movie-database-movies/Dockerfile
@@ -0,0 +1,19 @@
FROM java:7
MAINTAINER Dennis Schulte <mail@dennis-schulte.de>

# install updates
RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/*

# default log directory
#VOLUME ["/data/log"]

# copy spring boot jar as 'service.jar'
COPY target/movie-database-*.jar /service.jar

# service port
EXPOSE 8080

# define default jar name
ENTRYPOINT java $JVM_OPTS -jar /service.jar $ARGS
@@ -1,12 +1,12 @@
spring.application.name=@pom.artifactId@
info.version=@pom.version@
info.stage=test
moviedatabase.navigation.url.base=http://localhost:8081
moviedatabase.navigation.url.base=http://navigation:8081
moviedatabase.actors.url.base=http://moviedatabase.com/actor-app
spring.thymeleaf.cache=false
spring.redis.host=192.168.59.103
spring.redis.host=redis
server.context-path=/movie-app
spring.boot.admin.url=http://localhost:8083
spring.boot.admin.url=http://monitoring:8083
spring.boot.admin.client.url=http://moviedatabase.com/movie-app
http.mappers.jsonPrettyPrint=true
logging.file=/opt/moviedatabase/logs/@pom.artifactId@/@pom.artifactId@.log
20 changes: 20 additions & 0 deletions movie-database-navigation/Dockerfile
@@ -0,0 +1,20 @@
#FROM registry.hub.docker.com/_/java/:oracle-java7
FROM java:7
MAINTAINER Dennis Schulte <mail@dennis-schulte.de>

# install updates
RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/*

# default log directory
#VOLUME ["/data/log"]

# copy spring boot jar as 'service.jar'
COPY target/movie-database-*.jar /service.jar

# service port
EXPOSE 8081

# define default jar name
ENTRYPOINT java $JVM_OPTS -jar /service.jar $ARGS
Expand Up @@ -6,7 +6,7 @@ moviedatabase.movies.url.base=http://moviedatabase.com/movie-app
moviedatabase.actors.url.base=http://moviedatabase.com/actor-app
moviedatabase.shop.url.base=http://moviedatabase.com/shop-app/
spring.thymeleaf.cache=false
spring.boot.admin.url=http://localhost:8083
spring.boot.admin.url=http://monitoring:8083
spring.boot.admin.client.url=http://moviedatabase.com/navigation-app
http.mappers.jsonPrettyPrint=true
logging.file=/opt/moviedatabase/logs/@pom.artifactId@/@pom.artifactId@.log
16 changes: 16 additions & 0 deletions movie-database-shop-app/Dockerfile
@@ -0,0 +1,16 @@
FROM nginx:1.7.9
MAINTAINER Dennis Schulte <mail@dennis-schulte.de>

RUN rm /etc/nginx/conf.d/*

COPY moviedatabase.conf /etc/nginx/conf.d/moviedatabase.conf
COPY dist/. /usr/share/nginx/html/shop-app/

COPY run.sh /usr/local/bin/

RUN chmod 755 /usr/local/bin/run.sh

# service port
EXPOSE 80

ENTRYPOINT ["/usr/local/bin/run.sh"]
35 changes: 35 additions & 0 deletions movie-database-shop-app/moviedatabase.conf
@@ -0,0 +1,35 @@
server {
listen 80;
server_name moviedatabase.com;

location / {
proxy_set_header Host $http_host;
proxy_pass http://movies:8080/movie-app/;
}

location /movie-app/ {
proxy_set_header Host $http_host;
proxy_pass http://movies:8080/movie-app/;
}

location /actor-app/ {
proxy_set_header Host $http_host;
proxy_pass http://actors:8082/actor-app/;
}

location /shop-rest/ {
proxy_set_header Host $http_host;
proxy_pass http://shop:8084/shop-rest/;
}

location /navigation-app/ {
proxy_set_header Host $http_host;
proxy_pass http://navigation:8081/;
}

location /shop-app/ {
root /usr/share/nginx/html;
ssi on;
}

}
4 changes: 4 additions & 0 deletions movie-database-shop-app/run.sh
@@ -0,0 +1,4 @@
#!/bin/bash

# start nginx
nginx -g "daemon off;"
19 changes: 19 additions & 0 deletions movie-database-shop-rest/Dockerfile
@@ -0,0 +1,19 @@
FROM java:7
MAINTAINER Dennis Schulte <mail@dennis-schulte.de>

# install updates
RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/*

# default log directory
#VOLUME ["/data/log"]

# copy spring boot jar as 'service.jar'
COPY target/movie-database-*.jar /service.jar

# service port
EXPOSE 8084

# define default jar name
ENTRYPOINT java $JVM_OPTS -jar /service.jar $ARGS
Expand Up @@ -2,9 +2,9 @@ spring.application.name=@pom.artifactId@
info.version=@pom.version@
info.stage=test
server.port=8084
spring.redis.host=192.168.59.103
spring.redis.host=redis
server.context-path=/shop-rest
spring.boot.admin.url=http://localhost:8083
spring.boot.admin.url=http://monitoring:8083
spring.boot.admin.client.url=http://moviedatabase.com/shop-rest
http.mappers.jsonPrettyPrint=true
logging.file=/opt/moviedatabase/logs/@pom.artifactId@/@pom.artifactId@.log
Expand Down
2 changes: 1 addition & 1 deletion shutdown.sh
@@ -1,3 +1,3 @@
boot2docker stop
pkill -f redis-server
sudo nginx -s stop
pkill -f movie-database

0 comments on commit 4ae3722

Please sign in to comment.