Skip to content

Commit

Permalink
Upgraded Docker Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
cer committed Apr 7, 2019
1 parent 47c6597 commit b7fe5a4
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 123 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This project uses with [Docker Compose](https://docs.docker.com/compose/) to run

The `spring-boot-webapp` project uses Selenium to test the web UI using the Chrome browser.
You will need to install [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/getting-started).
On Mac OSX you can run `brew install chromedriver`.
On Mac OSX you can run ` brew cask install chromedriver`.


## The quick way
Expand Down
44 changes: 39 additions & 5 deletions build-and-test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,30 @@

set -e

KEEP_RUNNING=
USE_EXISTING=

while [ ! -z "$*" ] ; do
case $1 in
"--keep-running" )
KEEP_RUNNING=yes
;;
"--use-existing" )
USE_EXISTING=yes
;;
"--help" )
echo ./build-and-test-all.sh --keep-running --use-existing
exit 0
;;
esac
shift
done

. ./set-env.sh
docker-compose stop
docker-compose rm -v --force

if [ -z "$USE_EXISTING" ] ; then
docker-compose down --remove-orphans
fi

docker-compose up -d rabbitmq mongodb

Expand All @@ -22,7 +43,7 @@ cd spring-boot-restful-service

cd ..

docker-compose up -d restfulservice
docker-compose up -d --build restfulservice

echo -n waiting for restfulservice to start..

Expand All @@ -39,5 +60,18 @@ export USER_REGISTRATION_URL=http://${DOCKER_HOST_IP?}:8081/user

./gradlew build

docker-compose stop
docker-compose rm -v --force
cd ..

docker-compose up -d --build web

./wait-for-running-system.sh

./register-user.sh

echo User registered

if [ -z "$KEEP_RUNNING" ] ; then
docker-compose down --remove-orphans
fi

echo Success
103 changes: 54 additions & 49 deletions docker-compose-images.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,59 @@
rabbitmq:
image: rabbitmq:3.5.3-management
ports:
- "5672:5672"
- "15672:15672"
version: '3'
services:

eureka:
build: ./eureka-server
ports:
- "8761:8761"
rabbitmq:
image: rabbitmq:3.5.3-management
ports:
- "5672:5672"
- "15672:15672"

zipkin:
build: ./zipkin-server
links:
- rabbitmq
ports:
- "9411:9411"
environment:
RABBIT_HOST: rabbitmq
eureka:
build: ./eureka-server
ports:
- "8761:8761"

mongodb:
image: mongo:3.0.4
ports:
- "27017:27017"
command: mongod --smallfiles
zipkin:
build: ./zipkin-server
ports:
- "9411:9411"
depends_on:
- rabbitmq
environment:
RABBIT_HOST: rabbitmq

restfulservice:
image: sb_rest_svc
ports:
- "8081:8080"
links:
- rabbitmq
- mongodb
- eureka
environment:
SPRING_DATA_MONGODB_URI: mongodb://mongodb/userregistration
SPRING_RABBITMQ_HOST: rabbitmq
SPRING_APPLICATION_NAME: registration-service
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
SPRING_PROFILES_ACTIVE: enableEureka
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
mongodb:
image: mongo:3.0.4
ports:
- "27017:27017"
command: mongod --smallfiles

web:
image: sb_web
ports:
- "8080:8080"
links:
- eureka
environment:
USER_REGISTRATION_URL: http://REGISTRATION-SERVICE/user
SPRING_APPLICATION_NAME: registration-web
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
SPRING_PROFILES_ACTIVE: enableEureka
restfulservice:
image: spring-boot-restful-service
ports:
- "8081:8080"
depends_on:
- rabbitmq
- mongodb
- eureka
environment:
SPRING_DATA_MONGODB_URI: mongodb://mongodb/userregistration
SPRING_RABBITMQ_HOST: rabbitmq
SPRING_APPLICATION_NAME: registration-service
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
SPRING_PROFILES_ACTIVE: enableEureka
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/

web:
image: spring-boot-webapp
ports:
- "8080:8080"
depends_on:
- rabbitmq
- mongodb
- eureka
environment:
USER_REGISTRATION_URL: http://REGISTRATION-SERVICE/user
SPRING_APPLICATION_NAME: registration-web
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
SPRING_PROFILES_ACTIVE: enableEureka
118 changes: 62 additions & 56 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,67 @@
rabbitmq:
image: rabbitmq:3.5.3-management
ports:
- "5672:5672"
- "15672:15672"
version: '3'
services:

eureka:
build: ./eureka-server
ports:
- "8761:8761"
rabbitmq:
image: rabbitmq:3.5.3-management
ports:
- "5672:5672"
- "15672:15672"

zipkin:
build: ./zipkin-server
links:
- rabbitmq
ports:
- "9411:9411"
environment:
RABBIT_HOST: rabbitmq
mongodb:
image: mongo:3.0.4
ports:
- "27017:27017"
command: mongod --smallfiles

mongodb:
image: mongo:3.0.4
ports:
- "27017:27017"
command: mongod --smallfiles
eureka:
build: ./eureka-server
ports:
- "8761:8761"

restfulservice:
build: ./spring-boot-restful-service
ports:
- "8081:8080"
links:
- rabbitmq
- mongodb
- eureka
environment:
SPRING_DATA_MONGODB_URI: mongodb://mongodb/userregistration
SPRING_RABBITMQ_HOST: rabbitmq
SPRING_APPLICATION_NAME: registration-service
SPRING_PROFILES_ACTIVE: enableEureka
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
SPRING_SLEUTH_ENABLED: "true"
SPRING_SLEUTH_SAMPLER_PERCENTAGE: 1
zipkin:
build: ./zipkin-server
ports:
- "9411:9411"
depends_on:
- rabbitmq
environment:
RABBIT_HOST: rabbitmq

web:
build: ./spring-boot-webapp
ports:
- "8080:8080"
links:
- eureka
- rabbitmq
environment:
USER_REGISTRATION_URL: http://REGISTRATION-SERVICE/user
SPRING_APPLICATION_NAME: registration-web
SPRING_PROFILES_ACTIVE: enableEureka
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
SPRING_RABBITMQ_HOST: rabbitmq
SPRING_SLEUTH_ENABLED: "true"
SPRING_SLEUTH_SAMPLER_PERCENTAGE: 1
SPRING_SLEUTH_WEB_SKIPPATTERN: "/api-docs.*|/autoconfig|/configprops|/dump|/health|/info|/metrics.*|/mappings|/trace|/swagger.*|.*\\.png|.*\\.css|.*\\.js|/favicon.ico|/hystrix.stream"

restfulservice:
build: ./spring-boot-restful-service
ports:
- "8081:8080"
depends_on:
- rabbitmq
- mongodb
- eureka
- zipkin
environment:
SPRING_DATA_MONGODB_URI: mongodb://mongodb/userregistration
SPRING_RABBITMQ_HOST: rabbitmq
SPRING_APPLICATION_NAME: registration-service
SPRING_PROFILES_ACTIVE: enableEureka
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
SPRING_SLEUTH_ENABLED: "true"
SPRING_SLEUTH_SAMPLER_PERCENTAGE: 1

web:
build: ./spring-boot-webapp
ports:
- "8080:8080"
depends_on:
- restfulservice
- zipkin
- eureka
environment:
USER_REGISTRATION_URL: http://REGISTRATION-SERVICE/user
SPRING_APPLICATION_NAME: registration-web
SPRING_PROFILES_ACTIVE: enableEureka
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
SPRING_RABBITMQ_HOST: rabbitmq
SPRING_SLEUTH_ENABLED: "true"
SPRING_SLEUTH_SAMPLER_PERCENTAGE: 1
SPRING_SLEUTH_WEB_SKIPPATTERN: "/api-docs.*|/autoconfig|/configprops|/dump|/health|/info|/metrics.*|/mappings|/trace|/swagger.*|.*\\.png|.*\\.css|.*\\.js|/favicon.ico|/hystrix.stream"
6 changes: 4 additions & 2 deletions eureka-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM java:openjdk-8u91-jdk
FROM openjdk:8u171-jre-alpine
RUN apk --no-cache add curl
HEALTHCHECK --start-period=30s --interval=5s CMD curl -f http://localhost:8761/health || exit 1
CMD java -jar eureka-server.jar --server.port=8761
EXPOSE 8080
EXPOSE 8761
COPY build/libs/eureka-server.jar .
2 changes: 1 addition & 1 deletion mongodb-cli.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#! /bin/bash

docker run --rm --link microservicesexamples_mongodb_1:mongodb -i -t mongo:3.0.4 /usr/bin/mongo --host mongodb
docker run --rm --network microservices-examples_default -i -t mongo:3.0.4 /usr/bin/mongo --host mongodb
2 changes: 1 addition & 1 deletion register-user.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
curl -v -d '{"emailAddress": "foo@bar.com", "password" : "secret1234"}' -H "content-type: application/json" http://${DOCKER_HOST_IP}:8081/user
curl -v -d "$(echo '{"emailAddress": "fooSUFFIX@bar.com", "password" : "secret1234"}' | sed -e "s/SUFFIX/$(date +%s)/")" -H "content-type: application/json" http://${DOCKER_HOST_IP}:8081/user
6 changes: 4 additions & 2 deletions spring-boot-restful-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM java:openjdk-8u91-jdk
FROM openjdk:8u171-jre-alpine
RUN apk --no-cache add curl
MAINTAINER [email protected]
EXPOSE 8080
HEALTHCHECK --start-period=30s --interval=5s CMD curl -f http://localhost:8080/health || exit 1
CMD java -jar spring-boot-restful-service.jar
ADD build/libs/spring-boot-restful-service.jar .
COPY build/libs/spring-boot-restful-service.jar .
2 changes: 1 addition & 1 deletion spring-boot-restful-service/build-docker.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash -e

./gradlew assemble
docker build -t sb_rest_svc .
docker build -t spring-boot-restful-service .
6 changes: 4 additions & 2 deletions spring-boot-webapp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM java:openjdk-8u91-jdk
FROM openjdk:8u171-jre-alpine
RUN apk --no-cache add curl
MAINTAINER [email protected]
EXPOSE 8080
HEALTHCHECK --start-period=30s --interval=5s CMD curl -f http://localhost:8080/health || exit 1
CMD java -jar spring-boot-webapp.jar
ADD build/libs/spring-boot-webapp.jar .
COPY build/libs/spring-boot-webapp.jar .
2 changes: 1 addition & 1 deletion spring-boot-webapp/build-docker.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash -e

./gradlew assemble
docker build -t sb_web .
docker build -t spring-boot-webapp .
6 changes: 4 additions & 2 deletions zipkin-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM java:openjdk-8u91-jdk
FROM openjdk:8u171-jre-alpine
RUN apk --no-cache add curl
HEALTHCHECK --start-period=30s --interval=5s CMD curl -f http://localhost:9411 || exit 1
CMD java -jar zipkin-server.jar --server.port=9411
EXPOSE 8080
EXPOSE 9411
COPY build/libs/zipkin-server.jar .

0 comments on commit b7fe5a4

Please sign in to comment.