Skip to content

Commit cd30e57

Browse files
committed
Update application.properties with open api docs path, added shell scripts to Docker
1 parent b87d46d commit cd30e57

19 files changed

+92
-39
lines changed

compile

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# 5. Start the Service using ./run script and then test it with ./test script
1212
# After the Successful build and Startup of the Service, It should show the Build No. & Date
1313
# -------------------------------------------------------------------------------------------
14-
SERVICE=XYZ-SERVICE
14+
SERVICE=Mock
1515

1616
echo "---------------------------------------------------------------------------------------"
1717
echo "Compiling $SERVICE Microservice"
@@ -22,7 +22,7 @@ mvn clean
2222
# -------------------------------------------------------------------------------------------
2323
echo "Git Commit Count = "`git rev-list HEAD --count`
2424
echo "---------------------------------------------------------------------------------------"
25-
#generateBuildNumber $SERVICE
25+
generateBuildNumber $SERVICE
2626
# -------------------------------------------------------------------------------------------
2727
echo "Build the $SERVICE Microservice : mvn -e package"
2828
echo "---------------------------------------------------------------------------------------"

pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.fusion.air</groupId>
6-
<artifactId>payments-service</artifactId>
6+
<artifactId>mock-service</artifactId>
77
<version>0.1.0</version>
88
<packaging>jar</packaging>
9-
<name>paymentsService</name>
10-
<description>Payment Microservice</description>
9+
<name>microService</name>
10+
<description>Microservice Template</description>
1111

1212
<!--
1313
<parent>

src/docker/Dockerfile

+14-10
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,28 @@ FROM metamagic/java:8
1313

1414
LABEL author="Araf Karsh Hamid <araf.karsh@metamagic.in>"
1515

16-
RUN mkdir /Softwares/apps/
17-
RUN mkdir /Softwares/apps/payments/
18-
RUN mkdir /Softwares/apps/payments/libs
16+
RUN mkdir /Softwares/service
17+
RUN mkdir /Softwares/service/libs
18+
19+
ARG SPRINGBOOT_JAR=*-spring-boot.jar
20+
ARG MAVEN_JAR=*-?.?.?.jar
1921

2022
# Copy Service (Install)
21-
COPY --chown=arivu:arivu startService /Softwares/apps/payments/
23+
# COPY --chown=arivu:arivu startService /Softwares/service/
24+
2225
# SpringBoot Fat Jar
23-
COPY --chown=arivu:arivu payments-service-0.1.0-spring-boot.jar /Softwares/apps/payments/
26+
COPY --chown=arivu:arivu ${SPRINGBOOT_JAR} /Softwares/service/
27+
2428
# Maven Thin Jar
25-
#COPY --chown=arivu:arivu payments-service-0.1.0.jar /Softwares/apps/payments/
26-
#COPY --chown=arivu:arivu /libs /Softwares/apps/payments/libs/
29+
#COPY --chown=arivu:arivu ${MAVEN_JAR} /Softwares/service/
30+
#COPY --chown=arivu:arivu /libs /Softwares/service/libs/
2731

2832
# Change the Mode
29-
RUN chmod -R 750 /Softwares/apps/payments/*
33+
RUN chmod -R 750 /Softwares/service/*
3034

3135
# Expose Micro Service Port
3236
EXPOSE 9090
3337

3438
# Start Micro Service
35-
#ENTRYPOINT ["java","-jar","/Softwares/apps/payments/payments-service-0.1.0.jar"]
36-
ENTRYPOINT ["java","-jar","/Softwares/apps/payments/payments-service-0.1.0-spring-boot.jar"]
39+
#ENTRYPOINT ["java","-jar","/Softwares/service/mock-service-0.1.0.jar"]
40+
ENTRYPOINT ["java","-jar","/Softwares/service/mock-service-0.1.0-spring-boot.jar"]

src/docker/ORG_NAME

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
metamagic

src/docker/README.MD

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Create Docker Container
2+
3+
## Step 1 - Setting Microservice Name
4+
5+
1. Change the micro service name in the file SERVICE_NAME
6+
2. Change the Org namme in the file ORG_NAME
7+
3. Change the EntryPoint in the Dockerfile (Last line - jar file name)
8+
9+
## Step 2 - Build the image
10+
11+
1. build.sh
12+
2. securityScan
13+
14+
## Step 3 - Test the image
15+
16+
1. start.sh
17+
2. docker container ls (it shld display the sevice - mentioned in the SERVICE_NAME) as the output - running since....
18+
3. Check the URL in a Browser
19+
4. docker logs <container-id> (To Troubleshoot)
20+
21+
## Step 4 - Push the image to Cloud Repo
22+
23+
1. docker push org/image

src/docker/SERVICE_NAME

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mock-service

src/docker/build.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2-
SERVICE=mock-payment
3-
echo "docker build --force-rm -f Dockerfile -t metamagic/$SERVICE . "
4-
docker build --force-rm -f Dockerfile -t metamagic/$SERVICE .
2+
ORG=`cat ORG_NAME`
3+
SERVICE=`cat SERVICE_NAME`
4+
echo "docker build --force-rm -f Dockerfile -t $ORG/$SERVICE . "
5+
docker build --force-rm -f Dockerfile -t $ORG/$SERVICE .

src/docker/securityScan

100644100755
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/bin/bash
2-
SERVICE=mock-payment
2+
SERVICE=`cat SERVICE_NAME`
3+
echo "Scanning $SERVICE for vulnerabilities"
34
docker scan metamagic/$SERVICE

src/docker/shell

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
#!/bin/bash
2-
docker container run -it metamagic/bdd-order-service
2+
SERVICE=`cat SERVICE_NAME`
3+
echo "docker container exec -it $SERVICE bash"
4+
docker container exec -it $SERVICE bash

src/docker/start

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
ORG=`cat ORG_NAME`
3+
SERVICE=`cat SERVICE_NAME`
4+
echo "docker container run --name $SERVICE -d --rm -p 9010:9090 $ORG/$SERVICE"
5+
docker container run --name $SERVICE -d --rm -p 9010:9090 $ORG/$SERVICE

src/docker/start.sh

-4
This file was deleted.

src/docker/startService

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22
echo "Starting the MicroService"
3-
java -jar payments-service-0.1.0.jar
3+
java -jar mock-service-0.1.0.jar

src/docker/stop.sh src/docker/stop

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2-
SERVICE=mock-payment
2+
ORG=`cat ORG_NAME`
3+
SERVICE=`cat SERVICE_NAME`
34
echo "docker container stop $SERVICE"
45
docker container stop $SERVICE

src/main/java/io/fusion/air/microservice/ServiceBootStrap.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import javax.servlet.MultipartConfigElement;
2020

2121
import io.fusion.air.microservice.server.ServiceConfiguration;
22+
import io.fusion.air.microservice.server.ServiceHealthController;
2223
import org.slf4j.Logger;
2324
import org.springdoc.core.GroupedOpenApi;
2425
import org.springframework.beans.factory.annotation.Autowired;
@@ -94,7 +95,7 @@ public static void main(String[] args) {
9495
// Start the Server
9596
start(args);
9697

97-
// API URL : http://localhost:9090/swagger-ui.html
98+
// API URL : http://localhost:9090/servicecname/swagger-ui.html
9899
}
99100

100101
/**
@@ -187,13 +188,15 @@ public GroupedOpenApi appPublicApi() {
187188

188189
/**
189190
* Open API v3 Docs - Core Service
190-
* @return
191+
* Change the Resource Mapping in ServiceHealthController
192+
*
193+
* @see ServiceHealthController
191194
*/
192195
@Bean
193196
public GroupedOpenApi corePublicApi() {
194197
return GroupedOpenApi.builder()
195198
.group(serviceName+"-service-core")
196-
.pathsToMatch("/api/v1/service/**")
199+
.pathsToMatch("/api/v1/"+serviceName.toLowerCase()+"/service/**")
197200
.build();
198201
}
199202

src/main/java/io/fusion/air/microservice/server/ServiceConfiguration.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
name = "serviceConfig",
3636
value = "classpath:application.properties")
3737
public class ServiceConfiguration {
38+
39+
@Value("${springdoc.swagger-ui.path}")
40+
private String apiDocPath;
3841

3942
@Value("${service.name:NameNotDefined}")
4043
private String serviceName;
@@ -110,7 +113,7 @@ public ServiceConfiguration(String rHost, int rPort) {
110113
* @return
111114
*/
112115
public String getAPIURL() {
113-
return "http://localhost:"+serverPort+"/swagger-ui.html";
116+
return "http://localhost:"+serverPort+"/"+apiDocPath;
114117
}
115118

116119
/**

src/main/java/io/fusion/air/microservice/server/ServiceHealthController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
*/
5757
@Configuration
5858
@RestController
59-
@RequestMapping("/api/v1/service")
59+
@RequestMapping("/api/v1/payment/service")
6060
@RequestScope
6161
@Tag(name = "Core", description = "Core Service (Health, Readiness, ReStart.. etc)")
6262
public class ServiceHealthController {

src/main/resources/app.props.build

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# =======================================================================
2-
# Service Properties
2+
# Mock Service Properties
33
# =======================================================================
4-
build.number=1
5-
build.date=Tue Aug 10 19:29:28 IST 2021
4+
build.number=6
5+
build.date=Thu Aug 12 14:15:08 IST 2021

src/main/resources/app.props.tmpl

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# =======================================================================
2-
# Micro Service Properties
2+
# Service Name & API Docs
33
# =======================================================================
44
service.name=Payment
5+
springdoc.api-docs.path=/api/v1/payments/docs
6+
springdoc.swagger-ui.path=/api/v1/payments/swagger-ui.html
7+
# =======================================================================
8+
# Micro Service Properties
9+
# =======================================================================
510
server.port=9090
611
server.version=0.1.0
712
server.restart=true
@@ -26,6 +31,7 @@ remote.protocol=http
2631
springdoc.api-docs.enabled=true
2732
# Disabling the swagger-ui
2833
#springdoc.swagger-ui.enabled=true
34+
springdoc.swagger-ui.operationsSorter=method
2935
# Packages to include
3036
# springdoc.packagesToScan=io.fusion.water, io.fusion.fire
3137
# Paths to include

src/main/resources/application.properties

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# =======================================================================
2-
# Service Properties
2+
# Mock Service Properties
33
# =======================================================================
4-
build.number=1
5-
build.date=Tue Aug 10 19:29:28 IST 2021
4+
build.number=6
5+
build.date=Thu Aug 12 14:15:08 IST 2021
66
# =======================================================================
7-
# Micro Service Properties
7+
# Service Name & API Docs
88
# =======================================================================
99
service.name=Payment
10+
springdoc.api-docs.path=/api/v1/payments/docs
11+
springdoc.swagger-ui.path=/api/v1/payments/swagger-ui.html
12+
# =======================================================================
13+
# Micro Service Properties
14+
# =======================================================================
1015
server.port=9090
1116
server.version=0.1.0
1217
server.restart=true
@@ -31,6 +36,7 @@ remote.protocol=http
3136
springdoc.api-docs.enabled=true
3237
# Disabling the swagger-ui
3338
#springdoc.swagger-ui.enabled=true
39+
springdoc.swagger-ui.operationsSorter=method
3440
# Packages to include
3541
# springdoc.packagesToScan=io.fusion.water, io.fusion.fire
3642
# Paths to include

0 commit comments

Comments
 (0)