diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..9e3972c9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +version: '2.1' + +services: + product: + build: product-service + mem_limit: 350m + environment: + - SPRING_PROFILES_ACTIVE=docker + + recommendation: + build: recommendation-service + mem_limit: 350m + environment: + - SPRING_PROFILES_ACTIVE=docker + + review: + build: review-service + mem_limit: 350m + environment: + - SPRING_PROFILES_ACTIVE=docker + + product-composite: + build: product-composite-service + mem_limit: 350m + ports: + - "8080:8080" + environment: + - SPRING_PROFILES_ACTIVE=docker diff --git a/product-composite-service/Dockerfile b/product-composite-service/Dockerfile new file mode 100644 index 00000000..eb7ba1d7 --- /dev/null +++ b/product-composite-service/Dockerfile @@ -0,0 +1,53 @@ +#### Start of builder image +# ------------------------ +# Builder stage to prepare application for final image +FROM openjdk:14-slim-buster as builder +WORKDIR temp + +# Could be set to different jar file location +ARG JAR_FILE=target/*.jar + +# Copy fat jar file to current image builder +COPY ${JAR_FILE} application.jar + +# Extract the jar file layers +RUN java -Djarmode=layertools -jar --enable-preview application.jar extract +#### End of builder stage + +#### Start of actual image +# ------------------------ +# Build image based on JDK 14 base image, based on latest debian buster OS +FROM openjdk:14-slim-buster + +# Set image information, but could be set to different location from command line +ARG IMAGE_VERSION="0.0.1-SNAPSHOT" +ARG IMAGE_NAME="Product Composite Service" +ARG MAINTAINER="Mohamed Taman " + +LABEL version=${IMAGE_VERSION} name=${IMAGE_NAME} maintainer=${MAINTAINER} + +# Limiting security access to not user root user +RUN addgroup siriusxi && useradd -g siriusxi -ms /bin/bash taman + +# Setting user to current created user +USER taman + +# Set working directory to application folder +WORKDIR /home/taman/application + +# Copy all layers from builder stage to current image +COPY --from=builder temp/dependencies/ ./ +COPY --from=builder temp/snapshot-dependencies/ ./ +COPY --from=builder temp/resources/ ./ +COPY --from=builder temp/application/ ./ + +# Expose current application to port 8080 +EXPOSE 8080 + +ARG JAVA_OPTS="" + +# Run the application with JVM configs if any +ENTRYPOINT ["bash", "-c", \ +"java -server --enable-preview -XX:+UseContainerSupport \ +-XX:+AlwaysActAsServerClassMachine -XX:+UseG1GC -XX:+UseStringDeduplication ${JAVA_OPTS} \ +org.springframework.boot.loader.JarLauncher ${0} ${@}"] \ No newline at end of file diff --git a/product-composite-service/pom.xml b/product-composite-service/pom.xml index 658dd259..adc103f4 100644 --- a/product-composite-service/pom.xml +++ b/product-composite-service/pom.xml @@ -14,4 +14,9 @@ Product Composite Service Product Composite Service Spring Boot based project + + false + false + + diff --git a/product-composite-service/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/product-composite-service/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 00000000..c8fce465 --- /dev/null +++ b/product-composite-service/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,33 @@ +{ + "properties": [ + { + "name": "app.product-service.host", + "type": "java.lang.String", + "description": "Description for app.product-service.host." + }, + { + "name": "app.product-service.port", + "type": "java.lang.Integer", + "description": "Description for app.product-service.port." + }, + { + "name": "app.recommendation-service.host", + "type": "java.lang.String", + "description": "Description for app.recommendation-service.host." + }, + { + "name": "app.recommendation-service.port", + "type": "java.lang.Integer", + "description": "Description for app.recommendation-service.port." + }, + { + "name": "app.review-service.host", + "type": "java.lang.String", + "description": "Description for app.review-service.host." + }, + { + "name": "app.review-service.port", + "type": "java.lang.Integer", + "description": "Description for app.review-service.port." + } + ] } \ No newline at end of file diff --git a/product-composite-service/src/main/resources/application.yaml b/product-composite-service/src/main/resources/application.yaml index 3c8fe449..9017d16e 100644 --- a/product-composite-service/src/main/resources/application.yaml +++ b/product-composite-service/src/main/resources/application.yaml @@ -30,4 +30,27 @@ app: port: 9082 review-service: host: localhost - port: 9083 \ No newline at end of file + port: 9083 + +# This is a docker specific profile properties +# Also profiles could be separated in its owen file +# with file name format of "application-docker.yaml" +--- +spring: + profiles: docker + jmx: + enabled: false + +server: + port: 8080 + +app: + product-service: + host: product + port: 8080 + recommendation-service: + host: recommendation + port: 8080 + review-service: + host: review + port: 8080 \ No newline at end of file diff --git a/product-service/Dockerfile b/product-service/Dockerfile new file mode 100644 index 00000000..492c8e38 --- /dev/null +++ b/product-service/Dockerfile @@ -0,0 +1,54 @@ +#### Start of builder image +# ------------------------ +# Builder stage to prepare application for final image +FROM openjdk:14-slim-buster as builder +WORKDIR temp + +# Fatjar location, but could be set to different location from command line +ARG JAR_FILE=target/*.jar + +# Copy fat jar file to current image builder +COPY ${JAR_FILE} application.jar + +# Extract the jar file layers +RUN java -Djarmode=layertools -jar --enable-preview application.jar extract +#### End of builder stage + +#### Start of actual image +# ------------------------ +# Build image based on JDK 14 base image, based on latest debian buster OS +FROM openjdk:14-slim-buster +MAINTAINER Mohamed Taman + +# Set image information, but could be set to different location from command line +ARG IMAGE_VERSION="0.0.1-SNAPSHOT" +ARG IMAGE_NAME="Product Service" +ARG MAINTAINER="Mohamed Taman " + +LABEL version=${IMAGE_VERSION} name=${IMAGE_NAME} maintainer=${MAINTAINER} + +# Limiting security access to not user root user +RUN addgroup siriusxi && useradd -g siriusxi -ms /bin/bash taman + +# Setting user to current created user +USER taman + +# Set working directory to application folder +WORKDIR /home/taman/application + +# Copy all layers from builder stage to current image +COPY --from=builder temp/dependencies/ ./ +COPY --from=builder temp/snapshot-dependencies/ ./ +COPY --from=builder temp/resources/ ./ +COPY --from=builder temp/application/ ./ + +# Expose current application to port 8080 +EXPOSE 8080 + +ARG JAVA_OPTS="" + +# Run the application with JVM configs if any +ENTRYPOINT ["bash", "-c", \ +"java -server --enable-preview -XX:+UseContainerSupport \ +-XX:+AlwaysActAsServerClassMachine -XX:+UseG1GC -XX:+UseStringDeduplication ${JAVA_OPTS} \ +org.springframework.boot.loader.JarLauncher ${0} ${@}"] \ No newline at end of file diff --git a/product-service/pom.xml b/product-service/pom.xml index cbedb927..654737e2 100644 --- a/product-service/pom.xml +++ b/product-service/pom.xml @@ -14,4 +14,9 @@ Product Service Product Service Spring Boot based project + + false + false + + diff --git a/product-service/src/main/resources/application.yaml b/product-service/src/main/resources/application.yaml index 2e84cb35..e14a686a 100644 --- a/product-service/src/main/resources/application.yaml +++ b/product-service/src/main/resources/application.yaml @@ -18,4 +18,16 @@ management: include: "*" endpoint: shutdown: - enabled: true \ No newline at end of file + enabled: true + +# This is a docker specific profile properties +# Also profiles could be separated in its owen file +# with file name format of "application-docker.yaml" +--- +spring: + profiles: docker + jmx: + enabled: false + +server: + port: 8080 \ No newline at end of file diff --git a/recommendation-service/Dockerfile b/recommendation-service/Dockerfile new file mode 100644 index 00000000..75ab08b9 --- /dev/null +++ b/recommendation-service/Dockerfile @@ -0,0 +1,54 @@ +#### Start of builder image +# ------------------------ +# Builder stage to prepare application for final image +FROM openjdk:14-slim-buster as builder +WORKDIR temp + +# Could be set to different jar file location +ARG JAR_FILE=target/*.jar + +# Copy fat jar file to current image builder +COPY ${JAR_FILE} application.jar + +# Extract the jar file layers +RUN java -Djarmode=layertools -jar --enable-preview application.jar extract +#### End of builder stage + +#### Start of actual image +# ------------------------ +# Build image based on JDK 14 base image, based on latest debian buster OS +FROM openjdk:14-slim-buster +MAINTAINER Mohamed Taman + +# Set image information, but could be set to different location from command line +ARG IMAGE_VERSION="0.0.1-SNAPSHOT" +ARG IMAGE_NAME="Recommendation Service" +ARG MAINTAINER="Mohamed Taman " + +LABEL version=${IMAGE_VERSION} name=${IMAGE_NAME} maintainer=${MAINTAINER} + +# Limiting security access to not user root user +RUN addgroup siriusxi && useradd -g siriusxi -ms /bin/bash taman + +# Setting user to current created user +USER taman + +# Set working directory to application folder +WORKDIR /home/taman/application + +# Copy all layers from builder stage to current image +COPY --from=builder temp/dependencies/ ./ +COPY --from=builder temp/snapshot-dependencies/ ./ +COPY --from=builder temp/resources/ ./ +COPY --from=builder temp/application/ ./ + +# Expose current application to port 8080 +EXPOSE 8080 + +ARG JAVA_OPTS="" + +# Run the application with JVM configs if any +ENTRYPOINT ["bash", "-c", \ +"java -server --enable-preview -XX:+UseContainerSupport \ +-XX:+AlwaysActAsServerClassMachine -XX:+UseG1GC -XX:+UseStringDeduplication ${JAVA_OPTS} \ +org.springframework.boot.loader.JarLauncher ${0} ${@}"] \ No newline at end of file diff --git a/recommendation-service/pom.xml b/recommendation-service/pom.xml index dbded8af..c9106565 100644 --- a/recommendation-service/pom.xml +++ b/recommendation-service/pom.xml @@ -14,4 +14,9 @@ Recommendation Service Recommendation Service Spring Boot based project + + false + false + + diff --git a/recommendation-service/src/main/resources/application.yaml b/recommendation-service/src/main/resources/application.yaml index fe117b8f..d0af2644 100644 --- a/recommendation-service/src/main/resources/application.yaml +++ b/recommendation-service/src/main/resources/application.yaml @@ -19,3 +19,15 @@ management: endpoint: shutdown: enabled: true + +# This is a docker specific profile properties +# Also profiles could be separated in its owen file +# with file name format of "application-docker.yaml" +--- +spring: + profiles: docker + jmx: + enabled: false + +server: + port: 8080 diff --git a/review-service/Dockerfile b/review-service/Dockerfile new file mode 100644 index 00000000..37564580 --- /dev/null +++ b/review-service/Dockerfile @@ -0,0 +1,54 @@ +#### Start of builder image +# ------------------------ +# Builder stage to prepare application for final image +FROM openjdk:14-slim-buster as builder +WORKDIR temp + +# Could be set to different jar file location +ARG JAR_FILE=target/*.jar + +# Copy fat jar file to current image builder +COPY ${JAR_FILE} application.jar + +# Extract the jar file layers +RUN java -Djarmode=layertools -jar --enable-preview application.jar extract +#### End of builder stage + +#### Start of actual image +# ------------------------ +# Build image based on JDK 14 base image, based on latest debian buster OS +FROM openjdk:14-slim-buster +MAINTAINER Mohamed Taman + +# Set image information, but could be set to different location from command line +ARG IMAGE_VERSION="0.0.1-SNAPSHOT" +ARG IMAGE_NAME="Review Service" +ARG MAINTAINER="Mohamed Taman " + +LABEL version=${IMAGE_VERSION} name=${IMAGE_NAME} maintainer=${MAINTAINER} + +# Limiting security access to not user root user +RUN addgroup siriusxi && useradd -g siriusxi -ms /bin/bash taman + +# Setting user to current created user +USER taman + +# Set working directory to application folder +WORKDIR /home/taman/application + +# Copy all layers from builder stage to current image +COPY --from=builder temp/dependencies/ ./ +COPY --from=builder temp/snapshot-dependencies/ ./ +COPY --from=builder temp/resources/ ./ +COPY --from=builder temp/application/ ./ + +# Expose current application to port 8080 +EXPOSE 8080 + +ARG JAVA_OPTS="" + +# Run the application with JVM configs if any +ENTRYPOINT ["bash", "-c", \ +"java -server --enable-preview -XX:+UseContainerSupport \ +-XX:+AlwaysActAsServerClassMachine -XX:+UseG1GC -XX:+UseStringDeduplication ${JAVA_OPTS} \ +org.springframework.boot.loader.JarLauncher ${0} ${@}"] \ No newline at end of file diff --git a/review-service/pom.xml b/review-service/pom.xml index ab68e6bb..653471f6 100644 --- a/review-service/pom.xml +++ b/review-service/pom.xml @@ -14,4 +14,9 @@ Review Service Review Service Spring Boot based project + + false + false + + diff --git a/review-service/src/main/resources/application.yaml b/review-service/src/main/resources/application.yaml index e00c7614..21f2c40b 100644 --- a/review-service/src/main/resources/application.yaml +++ b/review-service/src/main/resources/application.yaml @@ -18,4 +18,16 @@ management: include: "*" endpoint: shutdown: - enabled: true \ No newline at end of file + enabled: true + +# This is a docker specific profile properties +# Also profiles could be separated in its owen file +# with file name format of "application-docker.yaml" +--- +spring: + profiles: docker + jmx: + enabled: false + +server: + port: 8080 \ No newline at end of file diff --git a/store-api/pom.xml b/store-api/pom.xml index 40e06f27..43c417bb 100644 --- a/store-api/pom.xml +++ b/store-api/pom.xml @@ -17,7 +17,7 @@ UTF-8 UTF-8 - 2.2.3.BUILD-SNAPSHOT + 2.3.0.M3 3.8.1 3.0.0-M4 3.0.0-M4 diff --git a/store-chassis/pom.xml b/store-chassis/pom.xml index ad2e14a3..e181abfc 100644 --- a/store-chassis/pom.xml +++ b/store-chassis/pom.xml @@ -1,13 +1,12 @@ - 4.0.0 org.springframework.boot spring-boot-starter-parent - - 2.3.0.M2 + 2.3.0.M4 @@ -16,7 +15,7 @@ 0.0.1-SNAPSHOT pom Springy Store Chassis - Parent pom project for Spring Boot μServices + Parent pom project for Springy μServices ../product-composite-service @@ -31,6 +30,19 @@ 14 UTF-8 UTF-8 + + + 1.4.13 + + + Mohamed Taman + mohamed.taman@gmail.com + siriusxi + latest + true + true + true + true @@ -80,7 +92,7 @@ reactor-test test - + com.siriusxi.ms.store store-api @@ -99,6 +111,12 @@ org.springframework.boot spring-boot-maven-plugin + + + + true + + @@ -123,6 +141,62 @@ + + + com.spotify + dockerfile-maven-plugin + ${dockerfile-maven-version} + + + build-image + package + + build + + + ${skip.image.build} + ${docker.repo.image.prefix}/${project.artifactId} + ${docker.image.default.tag} + + + + tag-image + package + + tag + + + ${skip.image.tag} + ${project.version} + + + + push-image + verify + + push + + + ${skip.image.push} + ${project.version} + + + + + ${skip.dockerization} + Dockerfile + ${docker.repo.image.prefix}/${project.artifactId} + true + + target/${project.build.finalName}.jar + ${project.version} + ${project.name} + "${maintainer.name} (${maintainer.email})" + + + + + diff --git a/store-utils/pom.xml b/store-utils/pom.xml index aacd0357..d0ce4fa9 100644 --- a/store-utils/pom.xml +++ b/store-utils/pom.xml @@ -17,7 +17,7 @@ UTF-8 UTF-8 - 2.2.3.BUILD-SNAPSHOT + 2.3.0.M3 3.8.1 3.0.0-M4 3.0.0-M4 diff --git a/test-em-all.sh b/test-em-all.sh index fd047b53..9413eb9f 100644 --- a/test-em-all.sh +++ b/test-em-all.sh @@ -2,13 +2,15 @@ ## Author: Mohamed Taman ## version: v1.0 ### Sample usage: -# -# HOST=localhost PORT=9080 ./test-em-all.bash +# for local run +# HOST=localhost PORT=9080 ./test-em-all.bash +# with docker compose +# HOST=localhost PORT=8080 ./test-em-all.bash start stop # echo -e "Starting [Springy Store] full functionality testing....\n" : ${HOST=localhost} -: ${PORT=9080} +: ${PORT=8080} function assertCurl() { @@ -48,11 +50,54 @@ function assertEqual() { fi } +function testUrl() { + url=$@ + if curl ${url} -ks -f -o /dev/null + then + echo "Ok" + return 0 + else + echo -n "not yet" + return 1 + fi; +} + +function waitForService() { + url=$@ + echo -n "Wait for: $url... " + n=0 + until testUrl ${url} + do + n=$((n + 1)) + if [[ ${n} == 100 ]] + then + echo " Give up" + exit 1 + else + sleep 6 + echo -n ", retry #$n " + fi + done +} + set -e +echo "Start:" `date` + echo "HOST=${HOST}" echo "PORT=${PORT}" +if [[ $@ == *"start"* ]] +then + echo "Restarting the test environment..." + echo "$ docker-compose down" + docker-compose down + echo "$ docker-compose -p ssm up -d" + docker-compose up -d +fi + +waitForService http://${HOST}:${PORT}/product-composite/1 + # Verify that a normal request works, expect three recommendations and three reviews assertCurl 200 "curl http://$HOST:$PORT/product-composite/1 -s" assertEqual 1 $(echo ${RESPONSE} | jq .productId) @@ -82,3 +127,11 @@ assertEqual "\"Invalid productId: -1\"" "$(echo ${RESPONSE} | jq .message)" assertCurl 400 "curl http://$HOST:$PORT/product-composite/invalidProductId -s" assertEqual "\"Type mismatch.\"" "$(echo ${RESPONSE} | jq .message)" +if [[ $@ == *"stop"* ]] +then + echo "We are done, stopping the test environment..." + echo "$ docker-compose down" + docker-compose down +fi + +echo "End:" `date` \ No newline at end of file