Skip to content

Commit

Permalink
Adding Invoice and Docker files
Browse files Browse the repository at this point in the history
  • Loading branch information
vr79x committed Dec 4, 2017
1 parent 2de85e7 commit bc2220e
Show file tree
Hide file tree
Showing 20 changed files with 722 additions and 26 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM java:8-jre

MAINTAINER Hitesh Joshi [email protected]

VOLUME [ "/data" ]

WORKDIR /data

EXPOSE 8080
ENTRYPOINT [ "java" ]
CMD ["-?"]
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,41 @@ I am going to use Spring Netflix OSS to build microservices API for a very basic



Commands ->

To build and package a jar to target folder :<BR>
<b><code>mvn clean package</code></b>


To start the Mysql container: <BR>
<b><code>docker run --name docker-mysql -e MYSQL_ROOT_PASSWORD=test -d mysql</code></b>


To Build the image from Docker File - Custom image as specified in the Dockerfile ---> (Note the .) <br>

1. Build(Or Rebuilding) Service Discovery Customer, Inventory , Invoice from the docker file .

<b><code>docker build -t microservice/customer . </code></b>
<b><code>docker build -t microservice/inventory . </code></b>
<b><code>docker build -t microservice/invoice . </code></b>

Building a container happens once, once it is built you can run it from the same folder and give it a name.

To Run the Custom Image, notice the linkage to the mysql container for microservices--><br>
<b><code>docker run --name docker-discovery -P -d microservice/serviceDiscovery</code></b>
<b><code>docker run --name docker-customer --link docker-mysql:mysql -P -d microservice/customer</code></b>
<b><code>docker run --name docker-inventory --link docker-mysql:mysql -P -d microservice/inventory</code></b>
<b><code>docker run --name docker-invoice --link docker-mysql:mysql -P -d microservice/invoice</code></b>



In this example, all my microservices connect to the same DB, but this can be easily changed above.


Creating a network
docker network create microservicesnet

Creating a base image
docker build -t microservice/baseserviceimg .


22 changes: 16 additions & 6 deletions customer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,21 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!--<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId>
</dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId>
</dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-turbine</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
Expand All @@ -55,6 +64,7 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;


@SpringBootApplication(scanBasePackages={"com.hitesh.microservices.customer"})
//@EnableDiscoveryClient
@EnableDiscoveryClient
public class CustomerApplication {

public static void main(String[] args) {
Expand Down
8 changes: 0 additions & 8 deletions customer/src/main/resources/application.properties

This file was deleted.

41 changes: 41 additions & 0 deletions customer/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Spring properties
spring:
application:
name: customer-service
freemarker:
enabled: false # Ignore Eureka dashboard FreeMarker templates
jpa:
hibernate:
ddl-auto: none
datasource:
url: jdbc:mysql://localhost:32769/microservices_cust
username: root
password: test
# thymeleaf:
# cache: false # Allow Thymeleaf templates to be reloaded at runtime
# prefix: classpath:/challenges-server/templates/ # Trailing / mandatory
# Template location for this application only

# Map the error path to error template (for Thymeleaf)
error:
path: /error

# HTTP Server
server:
port: 3333 # HTTP (Tomcat) port
display-name: Customer

# Discovery Server Access
# 1. DEV ONLY: Reduce the lease renewal interval to speed up registration
# 2. Define URL of registration server (defaultZone)
eureka:
client:
serviceUrl:
defaultZone: http://eureka:1111/eureka/ # using eureka instead of localhost
instance:
leaseRenewalIntervalInSeconds: 5 # DO NOT DO THIS IN PRODUCTION





42 changes: 35 additions & 7 deletions inventory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,70 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
<relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@EnableDiscoveryClient
public class InventoryApplication {

public static void main(String[] args) {
Expand Down
3 changes: 0 additions & 3 deletions inventory/src/main/resources/application.properties

This file was deleted.

41 changes: 41 additions & 0 deletions inventory/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Spring properties
spring:
application:
name: inventory-service
freemarker:
enabled: false # Ignore Eureka dashboard FreeMarker templates
jpa:
hibernate:
ddl-auto: none
datasource:
url: jdbc:mysql://localhost:32769/microservices_prod
username: root
password: test
# thymeleaf:
# cache: false # Allow Thymeleaf templates to be reloaded at runtime
# prefix: classpath:/challenges-server/templates/ # Trailing / mandatory
# Template location for this application only

# Map the error path to error template (for Thymeleaf)
error:
path: /error

# HTTP Server
server:
port: 2222 # HTTP (Tomcat) port
display-name: Inventory

# Discovery Server Access
# 1. DEV ONLY: Reduce the lease renewal interval to speed up registration
# 2. Define URL of registration server (defaultZone)
eureka:
client:
serviceUrl:
defaultZone: http://eureka:1111/eureka/ # using eureka instead of localhost
instance:
leaseRenewalIntervalInSeconds: 5 # DO NOT DO THIS IN PRODUCTION





24 changes: 24 additions & 0 deletions invoice/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
target/
!.mvn/wrapper/maven-wrapper.jar
*.mvn/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
6 changes: 6 additions & 0 deletions invoice/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM java:8
VOLUME /tmp
ADD /target/inventory-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Dspring.datasource.url=jdbc:mysql://docker-mysql/microservices_prod","-Dspring.datasource.username=root","-Dspring.datasource.password=test","-jar","/app.jar"]
Loading

0 comments on commit bc2220e

Please sign in to comment.