Skip to content

Commit 6ec4589

Browse files
committed
Merge pull request rohitghatol#3 from anilallewar/master
Changes to get the services running in docker containers
2 parents 8fb3c4e + 39a149f commit 6ec4589

File tree

32 files changed

+307
-57
lines changed

32 files changed

+307
-57
lines changed

README.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This repository is an example of how to get Microservices going using Spring Boo
44
# Table of Content
55
* [Contributors](#contributors)
66
* [Using the application](#using-application)
7+
* [Running on local m/c](#run_local_mc)
8+
* [Running using docker - NOT WORKING](#run_docker)
79
* [Microservices Overview](#microservices-overview)
810
* [Netflix OSS](#netflix-oss)
911
* [Spring Boot Overview](#spring-boot-overview)
@@ -31,11 +33,55 @@ The application consists of 7 different services
3133
* [api-gateway](api-gateway/README.md) - API gateway that proxies all the micro-services
3234
* [web-portal](web-portal/README.md) - Single Page Application that provides the UI
3335

34-
Please refer to the individual readme files on instructions of how to run the services. For demo, you can run the applications in the same order listed above.
35-
36-
Note:
37-
* If the gradle wrapper doesn't work, then install gradle and run `gradle wrapper` before using `gradlew`.
38-
* If you need to setup the classpath correctly, then run `./gradlew clean build eclipse` which would setup the `.classpath` accordingly.
36+
### <a name="run_local_mc"></a>Running on local m/c
37+
38+
* You can build all the projects by running the `./build-all-projects.sh` on Mac/Linux systems and then going to each individual folder and running the jars using the `java -jar build/libs/sam<application_name>.jar` command.
39+
* Please refer to the individual readme files on instructions of how to run the services. For demo, you can run the applications in the same order listed above.
40+
41+
### <a name="run_docker"></a>Running using docker (**NOTE: NOT WORKING with latest docker 1.8x since the gradle docker task is NOT compatible; also bug in Spring Boot 1.2.x**)
42+
43+
* [Docker](https://www.docker.com) is an open platform for building, shipping and running distributed applications. Follow steps on the site to install docker based on your operating system.
44+
* Currently there is a **[bug in Spring Boot 1.2.x](https://github.com/spring-projects/spring-boot/commit/8168e8a3275f17646c5c2bf628d2f3417369c583)** that affects the way how JPA starts in an app launched with executable jar. Hence while the docker containers are good to go, we will need to change the application once Spring boot 1.3 is released so that we can run this on docker.
45+
* Once docker is setup, we would reset the VM so as to start fresh. The examples were developed on Mac so follow these step; they would be fairly similar on Windows.
46+
* Once you open the docker program through terminal, follow these steps
47+
* Reset the VM => `boot2docker delete`
48+
* Start the VM giving it around 8 GB of RAM => `boot2docker init -m 8192`
49+
* Check whether the initialization parameters were successful => `boot2docker info`
50+
* Start the VM => `boot2docker up`
51+
* To connect the Docker client to the Docker daemon => `$(boot2docker shellinit)`
52+
* If you have not added your TLS certs to boot2docker; you would need to change docker to run the API on HTTP; while boot2docker 1.3 comes with TLS enabled. Hence you need to run the following command `$(docker run sequenceiq/socat)` at the docker prompt so that this image maps the api to HTTP port. You can check that it is working correctly(returns OK) using the command `curl http://192.168.59.103:2375/_ping` or connect the `http://192.168.59.103:2375/_ping` URL in the browser.
53+
* Run the mysql container using `docker run -d -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=auth --name auth-db -p 3306:3306 mysql`
54+
* On the mac command prompt, navigate to the root folder of the application (spring-boot-microservices) and run the `./docker-image-all-projects.sh` command. This should build all the images and publish them to docker.
55+
* Run the individual images as below; note that the auth-server and api-gateway images fail because of Spring Boot 1.2.x bug.
56+
* Config Server
57+
* docker run -d --name config-server -p 8888:8888 anilallewar/config-server
58+
* docker logs -f config-server
59+
* Eureka Server
60+
* docker run -d --name registry-server -p 8761:8761 anilallewar/webservice-registry
61+
* docker logs -f registry-server
62+
* OAuth Server
63+
* docker run -d --name auth-server -p 8899:8899 anilallewar/auth-server
64+
* docker logs -f auth-server
65+
* User Webservice
66+
* docker run -d --name user-webservice anilallewar/user-webservice
67+
* docker logs -f user-web service
68+
* Task Webservice
69+
* docker run -d --name task-webservice anilallewar/task-webservice
70+
* docker logs -f task-webservice
71+
* Comments Webservice
72+
* docker run -d --name comments-webservice anilallewar/comments-webservice
73+
* docker logs -f comments-webservice
74+
* Web Portal
75+
* docker run -d --name web-portal anilallewar/web-portal
76+
* docker logs -f web-portal
77+
* Zuul API Gateway
78+
* docker run -d --name api-gateway -p 8080:8080 anilallewar/api-gateway
79+
* docker logs -f api-gateway
80+
* We also have a [docker-compose](https://docs.docker.com/compose/) file that can be used to start all the containers together using `docker-compose up -d`. However this doesn't work in our case since our containers need to be started in order e.g. config-server before everything, webservice-registry before rest of Eureka clients. Docker compose starts all containers together and this fails because containers like auth-server, web-portal start before their dependent containers have started. Please see [here](https://github.com/docker/compose/issues/374) for more details.
81+
82+
* Note:
83+
* If the gradle wrapper doesn't work, then install gradle and run `gradle wrapper` before using `gradlew`.
84+
* If you need to setup the classpath correctly, then run `./gradlew clean build eclipse` which would setup the `.classpath` accordingly.
3985

4086
## <a name="microservices-overview"></a>Microservices Overview
4187

api-gateway/bootstrap.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

api-gateway/build.gradle

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ buildscript {
1515
}
1616
}
1717

18-
apply plugin: 'application'
1918
apply plugin: 'eclipse'
2019
apply plugin: 'spring-boot'
2120
apply plugin: 'java'
2221
apply plugin: 'docker'
2322

24-
2523
jar {
2624
baseName = 'sample-api-gateway'
2725
version = '0.0.1'
@@ -48,14 +46,44 @@ dependencies {
4846
testCompile 'org.springframework:spring-test:4.0.6.RELEASE'
4947
}
5048

51-
group = 'rohitghatol'
49+
/**
50+
* These values(group & mainClassName) are required by the gradle docker plugin.
51+
*
52+
* The "group" value feeds into the docker tag and is required if you want to push the images
53+
* to docker hub.
54+
*
55+
* The "mainClassName" value tells which class has the "main" entry point for running the
56+
* Spring boot application.
57+
*/
58+
group = 'anilallewar'
59+
mainClassName = 'com.rohitghatol.microservice.gateway.Application'
5260

5361
sourceCompatibility = 1.7
5462
targetCompatibility = 1.7
5563

56-
5764
distDocker {
5865
exposePort 8080
66+
setEnvironment 'JAVA_OPTS', '-Dspring.profiles.active=docker'
67+
}
68+
69+
/**
70+
* On Mac, docker can't be connected locally since it is running in a separate VM.
71+
*
72+
* NOTE: If you have not added your TLS certs to boot2docker; you would need to change
73+
* docker to run the API on HTTP; while boot2docker 1.3 comes with TLS enabled. Hence
74+
* you need to run the following command "$(docker run sequenceiq/socat)" at the docker
75+
* prompt so that this image maps the api to HTTP port. You can check that it is working
76+
* correctly using the command "curl http://192.168.59.103:2375/_ping"
77+
*
78+
*
79+
* In order to change docker to run the remote API, we need to set the following flags:
80+
* 1. useApi true => Use the Docker Remote API instead of a locally installed docker binary.
81+
* 2. hostUrl => set the URL used to contact the Docker server. Defaults to http://localhost:2375
82+
*/
83+
docker {
84+
useApi true
85+
hostUrl 'http://192.168.59.103:2375'
86+
baseImage = 'java:7'
5987
}
6088

6189
bootRun {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
spring:
2+
application:
3+
name: api-gateway
4+
cloud:
5+
config:
6+
uri: http://localhost:8888
7+
8+
---
9+
10+
spring:
11+
profiles: docker
12+
cloud:
13+
config:
14+
uri: http://192.168.59.103:8888

auth-server/bootstrap.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

auth-server/build.gradle

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ buildscript {
1515
}
1616
}
1717

18-
apply plugin: 'application'
1918
apply plugin: 'eclipse'
2019
apply plugin: 'spring-boot'
2120
apply plugin: 'java'
@@ -48,14 +47,22 @@ dependencies {
4847
testCompile 'org.springframework:spring-test:4.0.6.RELEASE'
4948
}
5049

51-
group = 'rohitghatol'
50+
group = 'anilallewar'
51+
mainClassName = 'com.rohitghatol.microservice.auth.Application'
5252

5353
sourceCompatibility = 1.7
5454
targetCompatibility = 1.7
5555

5656

5757
distDocker {
58-
exposePort 8080
58+
exposePort 8899
59+
setEnvironment 'JAVA_OPTS', '-Dspring.profiles.active=docker'
60+
}
61+
62+
docker {
63+
useApi true
64+
hostUrl 'http://192.168.59.103:2375'
65+
baseImage = 'java:7'
5966
}
6067

6168
bootRun {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
spring:
2+
application:
3+
name: auth-server
4+
cloud:
5+
config:
6+
uri: http://localhost:8888
7+
8+
---
9+
10+
spring:
11+
profiles: docker
12+
cloud:
13+
config:
14+
uri: http://192.168.59.103:8888

build-all-projects.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
cd api-gateway; ./gradlew clean build; cd ..
4+
cd auth-server; ./gradlew clean build; cd ..
5+
cd config-server; ./gradlew clean build; cd ..
6+
cd task-webservice; ./gradlew clean build; cd ..
7+
cd user-webservice; ./gradlew clean build; cd ..
8+
cd web-portal; ./gradlew clean build; cd ..
9+
cd webservice-registry; ./gradlew clean build; cd ..
10+
cd comments-webservice; ./gradlew clean build; cd ..

0 commit comments

Comments
 (0)