Skip to content

Commit ffea7b9

Browse files
committed
Working version
1 parent 0869f84 commit ffea7b9

File tree

17 files changed

+816
-4
lines changed

17 files changed

+816
-4
lines changed

Diff for: README.md

+161-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,165 @@
33
### Microservices Reference Application - What's For Dinner User-Interface Service
44

55
*This project is part of the 'IBM Cloud Architecture - Microservices Reference Application for Netflix OSS' suite, available at
6-
https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd*. There are three versions of the application, each available in their own branch, as documented below.
6+
https://github.com/ibm-cloud-architecture/refarch-cloudnative-netflix*
77

8-
- [Microprofile](../../tree/microprofile/) - leverages the Microprofile framework for the Java microservices framework of choice.
9-
- [Spring](../../tree/spring/) - leverages Spring Boot as the Java programming model of choice, with reliance on Kubernetes-based routing for microservices communication.
10-
- [Spring Cloud](../../tree/spring-cloud/) - leverages the Spring Cloud programming model (including Netflix OSS componentes) as the Java microservices framework of choice.
8+
#### Introduction
9+
10+
This project is built to demonstrate how to build a Spring Boot application for use in a microservices-based architecture:
11+
- Leverage Spring Boot framework to build a microservices application.
12+
- Integrate with [Netflix Eureka](https://github.com/Netflix/eureka) and [Ribbon](https://github.com/Netflix/ribbon) framework.
13+
- Display a simpler user interface, based on Spring MVC, with the content of the [What's for Dinner Menu Service](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-menu).
14+
- Deployment options for local, Cloud Foundry, or Docker Container-based runtimes (including [IBM Container Service](https://console.ng.bluemix.net/docs/containers/container_index.html) on [Bluemix](https://new-console.ng.bluemix.net/#overview)).
15+
16+
#### APIs in this application
17+
You can access the user interface directly in a browser via `http://<hostname>:8181/`
18+
19+
#### Pre-requisite:
20+
- You need a Docker machine running on localhost to host container(s). [Click for instructions](https://docs.docker.com/machine/get-started/).
21+
22+
#### Build the application
23+
1. Clone git repository.
24+
```
25+
git clone https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-ui
26+
cd refarch-cloudnative-wfd-ui
27+
```
28+
29+
2. Build the application. A utility script is provided to easily build using either Gradle (default) or Maven. You can optionally specify the `-d` parameter to build the associated Docker image as well. The default Gradle build instructions use a Gradle wrapper requiring no further installation. The Maven build instructions require Maven to be installed locally.
30+
31+
2.1 Build the application using Gradle:
32+
```
33+
./build-microservice.sh [-d]
34+
```
35+
36+
2.2 Build the application using Maven:
37+
```
38+
./build-microservice.sh -m [-d]
39+
```
40+
41+
#### Run UI Service on localhost
42+
In this section you will deploy the Spring Boot application to run on your localhost.
43+
44+
1. [Setup Eureka](https://github.com/ibm-cloud-architecture/refarch-cloudnative-netflix-eureka#run-the-application-component-locally) to run locally.
45+
46+
2. Run the required downstream services:
47+
2.1. [Appetizer](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-appetizer#run-appetizer-service-on-localhost)
48+
2.2. [Entree](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-entree#run-entree-service-on-localhost)
49+
2.3. [Desserts](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-dessert#run-dessert-service-on-localhost)
50+
2.4. [Menu](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-menu#run-menu-service-on-localhost)
51+
52+
3. Run the application on localhost (assuming default Gradle build). If Eureka is not running locally, you will need to pass the location of the Eureka server as a command-line paramter.
53+
```
54+
java [-Deureka.client.serviceUrl.defaultZone=http://eureka-host:port/eureka/] -jar build/libs/wfd-ui-0.0.1-SNAPSHOT.jar
55+
```
56+
57+
4. Validate via `http://localhost:8181` in your browser.
58+
59+
#### Run UI Service application on local Docker container
60+
In this section you will deploy the Spring Boot application to run in a local docker container.
61+
62+
1. Build service and container image:
63+
```
64+
./build-microservice.sh -d
65+
```
66+
67+
2. If not done so already, [Setup Eureka](https://github.com/ibm-cloud-architecture/refarch-cloudnative-netflix-eureka#run-the-application-component-locally) to run locally.
68+
69+
3. Run the required downstream services:
70+
3.1. [Appetizer](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-appetizer#run-appetizer-service-on-local-docker-container)
71+
3.2. [Entree](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-entree#run-entree-service-on-local-docker-container)
72+
3.3. [Desserts](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-dessert#run-dessert-service-on-local-docker-container)
73+
3.4. [Menu](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-menu#run-menu-service-application-on-local-docker-container)
74+
75+
4. Start the application in docker container.
76+
```
77+
docker run -d -p 8181:8181 --name wfd-ui --rm --env "eureka.client.serviceUrl.defaultZone=http://eureka-host:port/eureka/" wfd-ui
78+
```
79+
80+
5. Validate via `http://localhost:8181` in your browser.
81+
82+
#### Deploy UI Service to Cloud Foundry runtime, on IBM Bluemix
83+
84+
1. Log in to your Bluemix account.
85+
```
86+
cf login -a <bluemix-api-endpoint> -u <your-bluemix-user-id>
87+
```
88+
89+
2. Set target to use your Bluemix Org and Space.
90+
```
91+
cf target -o <your-bluemix-org> -s <your-bluemix-space>
92+
```
93+
94+
3. [Setup Eureka on Bluemix](https://github.com/ibm-cloud-architecture/refarch-cloudnative-netflix-eureka#run-the-application-component-on-bluemix).
95+
96+
4. Run the required downstream services:
97+
4.1. [Appetizer](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-appetizer#deploy-appetizer-service-to-cloud-foundry-runtime-on-ibm-bluemix)
98+
4.2. [Entree](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-entree#deploy-entree-service-to-cloud-foundry-runtime-on-ibm-bluemix)
99+
4.3. [Desserts](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-dessert#deploy-dessert-service-to-cloud-foundry-runtime-on-ibm-bluemix)
100+
4.4. [Menu](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-menu#deploy-menu-service-to-cloud-foundry-runtime-on-ibm-bluemix)
101+
102+
5. Create a user-provided service for Eureka, so the services running in Cloud Foundry can bind to it:
103+
104+
```
105+
cf create-user-provided-service eureka-service-discovery -p "{\"uri\": \"http://{eureka-host}/eureka/\"}"
106+
```
107+
108+
6. Start the application in a Cloud Foundry runtime on IBM Bluemix.
109+
110+
The following commands push the service code to Bluemix and creates a Cloud Foundry application. It then sets the desired Spring Boot profile for the application to configure itself correctly, as well as binds the user-provided service with the Eureka endpoint information. Finally, it restages the application code to ensure it receives all the configuration changes and then starts the application.
111+
112+
_NOTE_: There is no need for a port in the Eureka parameter, as the Container Group running Eureka is listening on port 80 (the default HTTP port) and will forward to the necessary port of 8761 that Eureka is listening on.
113+
114+
```
115+
cf push -p build/libs/wfd-ui-0.0.1-SNAPSHOT.jar -d mybluemix.net -n wfd-ui-{your-bluemix-user-id} --no-start
116+
117+
cf set-env wfd-ui SPRING_PROFILES_ACTIVE cloud
118+
119+
cf bind-service wfd-ui eureka-service-discovery
120+
121+
cf restage wfd-ui
122+
123+
cf start wfd-ui
124+
```
125+
126+
7. Validate via `http://localhost:8181` in your browser.
127+
128+
129+
#### Deploy UI Service to Docker Container, on IBM Bluemix
130+
131+
1. Log in to your Bluemix account.
132+
```
133+
cf login -a <bluemix-api-endpoint> -u <your-bluemix-user-id>
134+
```
135+
136+
2. Set target to use your Bluemix Org and Space.
137+
```
138+
cf target -o <your-bluemix-org> -s <your-bluemix-space>
139+
```
140+
141+
3. Log in to IBM Containers plugin.
142+
```
143+
cf ic init
144+
```
145+
146+
4. Tag and push the local docker image to bluemix private registry.
147+
```
148+
docker tag wfd-ui registry.ng.bluemix.net/$(cf ic namespace get)/wfd-ui:latest
149+
docker push registry.ng.bluemix.net/$(cf ic namespace get)/wfd-ui:latest
150+
```
151+
152+
5. [Setup Eureka on Bluemix](https://github.com/ibm-cloud-architecture/refarch-cloudnative-netflix-eureka#run-the-application-component-on-bluemix).
153+
154+
6. Run the required downstream services:
155+
6.1. [Appetizer](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-appetizer#deploy-appetizer-service-to-docker-container-on-ibm-bluemix)
156+
6.2. [Entree](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-entree#deploy-entree-service-to-docker-container-on-ibm-bluemix)
157+
6.3. [Desserts](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-dessert#deploy-desserts-service-to-docker-container-on-ibm-bluemix)
158+
6.4. [Menu](https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-menu#deploy-menu-service-to-docker-container-on-ibm-bluemix)
159+
160+
7. Start the application in an IBM Bluemix Container. Replace `{eureka-host}` with the public route configured in the deployment of Eureka to Bluemix.
161+
162+
_NOTE_: There is no need for a port in the Eureka parameter, as the Container Group running Eureka is listening on port 80 (the default HTTP port) and will forward to the necessary port of 8761 that Eureka is listening on.
163+
```
164+
cf ic group create -p 8180 -m 256 --min 1 --auto --name wfd-menu-group -e "--env "eureka.client.serviceUrl.defaultZone=http://eureka-host/eureka/" -n wfd-menu-$(cf ic namespace get) -d mybluemix.net registry.ng.bluemix.net/$(cf ic namespace get)/wfd-menu:latest
165+
```
166+
167+
8. Validate via `http://localhost:8181` in your browser.

Diff for: build-microservice.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
IMAGE_NAME=wfd-ui
4+
MAVEN_BUILD_TARGET=target/wfd-ui-0.0.1-SNAPSHOT.jar
5+
GRADLE_BUILD_TARGET=build/libs/wfd-ui-0.0.1-SNAPSHOT.jar
6+
7+
while getopts "md" ARG; do
8+
case ${ARG} in
9+
m)
10+
USE_MAVEN='yes'
11+
;;
12+
d)
13+
DO_DOCKER='yes'
14+
;;
15+
esac
16+
done
17+
18+
if [[ ${USE_MAVEN} == 'yes' ]]; then
19+
mvn clean package
20+
if [[ ${DO_DOCKER} == 'yes' ]]; then
21+
cp ${MAVEN_BUILD_TARGET} docker/app.jar
22+
fi
23+
else
24+
./gradlew clean build
25+
if [[ ${DO_DOCKER} == 'yes' ]]; then
26+
cp ${GRADLE_BUILD_TARGET} docker/app.jar
27+
fi
28+
fi
29+
30+
if [[ ${DO_DOCKER} == 'yes' ]]; then
31+
cd docker/
32+
docker build -t ${IMAGE_NAME} .
33+
fi

Diff for: build.gradle

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
buildscript {
2+
ext {
3+
springBootVersion = '1.4.0.RELEASE'
4+
}
5+
repositories {
6+
mavenCentral()
7+
}
8+
dependencies {
9+
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
10+
}
11+
}
12+
13+
apply plugin: 'java'
14+
apply plugin: 'eclipse'
15+
apply plugin: 'spring-boot'
16+
17+
jar {
18+
baseName = 'wfd-ui'
19+
version = '0.0.1-SNAPSHOT'
20+
}
21+
sourceCompatibility = 1.8
22+
targetCompatibility = 1.8
23+
24+
repositories {
25+
mavenCentral()
26+
jcenter()
27+
}
28+
29+
dependencies {
30+
compile('org.springframework.cloud:spring-cloud-sleuth-zipkin')
31+
compile('org.springframework.cloud:spring-cloud-starter-sleuth')
32+
compile('org.springframework.boot:spring-boot-starter-actuator')
33+
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
34+
compile('org.springframework.cloud:spring-cloud-starter-eureka')
35+
compile('org.springframework.cloud:spring-cloud-starter-ribbon')
36+
compile('org.springframework.cloud:spring-cloud-starter-hystrix')
37+
compile('org.springframework.cloud:spring-cloud-netflix-hystrix-stream')
38+
compile('org.springframework.cloud:spring-cloud-starter-stream-rabbit')
39+
compile('org.springframework.boot:spring-boot-starter-web')
40+
compile('io.springfox:springfox-swagger2:2.5.0')
41+
compile('io.springfox:springfox-swagger-ui:2.5.0')
42+
compile('io.swagger:swagger-annotations:1.5.10')
43+
testCompile('org.springframework.boot:spring-boot-starter-test')
44+
}
45+
46+
dependencyManagement {
47+
imports {
48+
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.SR5"
49+
}
50+
}
51+
52+
53+
eclipse {
54+
classpath {
55+
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
56+
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
57+
}
58+
}

Diff for: docker/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM java:8
2+
# VOLUME /tmp
3+
ADD app.jar app.jar
4+
RUN bash -c 'touch /app.jar'
5+
6+
EXPOSE 8181
7+
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

Diff for: gradle/wrapper/gradle-wrapper.jar

52.4 KB
Binary file not shown.

Diff for: gradle/wrapper/gradle-wrapper.properties

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Mon Aug 29 13:09:25 CDT 2016
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip

0 commit comments

Comments
 (0)