diff --git a/address-validation-service/Dockerfile b/address-validation-service/Dockerfile index 14be675..6ab2326 100644 --- a/address-validation-service/Dockerfile +++ b/address-validation-service/Dockerfile @@ -1,15 +1,7 @@ -FROM maven:3.6.3-jdk-11-openj9 AS mvn +FROM openjdk:11-jre -WORKDIR /usr/src/online-shop -COPY pom.xml ./ -RUN mvn package dependency:go-offline # cache dependencies -COPY src ./src -RUN mvn clean package -Dservice.name=address-validation-service -DskipTests +RUN wget https://repo.maven.apache.org/maven2/org/apache/meecrowave/meecrowave-core/1.2.13/meecrowave-core-1.2.13-runner.jar -O /opt/meecrowave-core-runner.jar +ADD target/address-validation-service.war /opt/address-validation-service.war -FROM openjdk:11 - -EXPOSE 8080 -COPY --from=mvn /usr/src/online-shop/target/runner/meecrowave-core-runner.jar /opt/meecrowave-runner.jar -COPY --from=mvn /usr/src/online-shop/target/address-validation-service.war /opt/address-validation-service.war - -ENTRYPOINT ["java", "--illegal-access=permit", "-Djava.net.preferIPv4Stack=true", "-jar", "/opt/meecrowave-runner.jar", "--webapp", "/opt/address-validation-service.war"] +EXPOSE 4003 +ENTRYPOINT ["java", "-Djava.net.preferIPv4Stack=true", "-jar", "/opt/meecrowave-core-runner.jar", "--host", "0.0.0.0", "--http", "4003", "--webapp", "/opt/address-validation-service.war"] diff --git a/address-validation-service/Jenkinsfile b/address-validation-service/Jenkinsfile index 65ed856..b82ef0a 100644 --- a/address-validation-service/Jenkinsfile +++ b/address-validation-service/Jenkinsfile @@ -2,6 +2,10 @@ pipeline { agent any + parameters { + booleanParam(name: 'verifyPacts', defaultValue: false, description: 'should this job just run to verify pacts from a consumer') + } + options { disableConcurrentBuilds() } @@ -12,6 +16,7 @@ pipeline { PERFORM_RELEASE = "${env.SNAPSHOT_VERSION.contains('-SNAPSHOT') && env.BRANCH_NAME == 'main' && !env.LAST_COMMIT_MESSAGE.startsWith('update version to ')}" RELEASE_VERSION = "${env.SNAPSHOT_VERSION.contains('-SNAPSHOT') ? env.SNAPSHOT_VERSION.substring(0, env.SNAPSHOT_VERSION.lastIndexOf('-SNAPSHOT')) : SNAPSHOT_VERSION}" VERSION = "${env.BRANCH_NAME == 'main' && !env.LAST_COMMIT_MESSAGE.startsWith('update version to ') ? env.RELEASE_VERSION : env.SNAPSHOT_VERSION}" + ROOT_DIRECTORY = "${params.verifyPacts == true && env.BRANCH_NAME == 'main' && env.SNAPSHOT_VERSION.endsWith("-SNAPSHOT") ? 'target/checkout' : '.'}" } triggers { @@ -26,19 +31,29 @@ pipeline { branch 'main' } environment name: 'PERFORM_RELEASE', value: 'true' + expression { + params.verifyPacts == true + } } } steps { echo "Building version ${env.VERSION}" script { - if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { + if (params.verifyPacts == true && env.BRANCH_NAME == 'main' && env.SNAPSHOT_VERSION.endsWith("-SNAPSHOT")) { + int previousRevision = Integer.parseInt(env.RELEASE_VERSION.substring(env.RELEASE_VERSION.lastIndexOf(".") + 1)) - 1 + if (previousRevision >= 0) { + previousVersion = RELEASE_VERSION.substring(0, env.RELEASE_VERSION.lastIndexOf(".")) + "." + previousRevision + sh "mvn scm:checkout -DscmVersionType=tag -DscmVersion=${previousVersion}" + echo "Testing against version ${previousVersion}" + } + } else if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { sh "mvn versions:set -DnewVersion=${env.RELEASE_VERSION} -B" - sh "sed -i 's/${env.SNAPSHOT_VERSION}/${env.RELEASE_VERSION}/g' deployment/overlays/prod/kustomization.yaml" - } else { - sh "sed -i 's/${env.SNAPSHOT_VERSION}/${env.GIT_COMMIT}/g' deployment/overlays/test/kustomization.yaml" } } - sh 'mvn clean test-compile -B' + sh """ + cd ${ROOT_DIRECTORY} + mvn clean test-compile -B + """ } } stage ('Test') { @@ -48,10 +63,16 @@ pipeline { branch 'main' } environment name: 'PERFORM_RELEASE', value: 'true' + expression { + params.verifyPacts == true + } } } steps { - sh "mvn test -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -B" + sh """ + cd ${ROOT_DIRECTORY} + mvn test -DpactBroker.url=http://pact:9292 -Dpact.verifier.publishResults=true -B + """ } } stage ('Package') { @@ -62,10 +83,12 @@ pipeline { } environment name: 'PERFORM_RELEASE', value: 'true' } + expression { + params.verifyPacts == false + } } steps { - sh 'mvn package -DskipTests -B' - sh 'docker build -t address-validation .' + sh 'mvn package meecrowave:bundle -DskipTests -B' } } stage ('Push') { @@ -76,16 +99,13 @@ pipeline { } environment name: 'PERFORM_RELEASE', value: 'true' } + expression { + params.verifyPacts == false + } } steps { - sh """ - docker tag address-validation localhost:30010/address-validation:${env.VERSION} - docker tag address-validation localhost:30010/address-validation:${env.BRANCH_NAME == 'main' ? 'stable' : 'latest'} - docker tag address-validation localhost:30010/address-validation:${env.GIT_COMMIT} - docker push localhost:30010/address-validation:${env.VERSION} - docker push localhost:30010/address-validation:${env.BRANCH_NAME == 'main' ? 'stable' : 'latest'} - docker push localhost:30010/address-validation:${env.GIT_COMMIT} - """ + sh 'sshpass -p jenkins scp -o StrictHostKeyChecking=no -P 2222 target/address-validation-service-meecrowave-distribution.zip jenkins@test:~/' + sh 'sshpass -p jenkins scp -o StrictHostKeyChecking=no -P 2222 target/address-validation-service-meecrowave-distribution.zip jenkins@prod:~/' script { if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { sh 'git config --global user.name "Jenkins"' @@ -94,7 +114,6 @@ pipeline { sh "mvn scm:tag -Dtag=${env.RELEASE_VERSION} -B" int nextRevision = Integer.parseInt(env.RELEASE_VERSION.substring(env.RELEASE_VERSION.lastIndexOf(".") + 1)) + 1 nextVersion = RELEASE_VERSION.substring(0, env.RELEASE_VERSION.lastIndexOf(".")) + "." + nextRevision + "-SNAPSHOT" - sh "sed -i 's/${env.RELEASE_VERSION}/${nextVersion}/g' deployment/overlays/prod/kustomization.yaml" sh "mvn versions:set scm:checkin -DnewVersion=${nextVersion} -Dmessage='update version to ${nextVersion}' -B" } } @@ -102,6 +121,9 @@ pipeline { } stage ('Deploy') { when { + expression { + params.verifyPacts == false + } anyOf { not { branch 'main' @@ -113,10 +135,19 @@ pipeline { script { if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { sh "mvn scm:checkout -DscmVersion=${env.RELEASE_VERSION} -DscmVersionType=tag -B" - sh 'kubectl apply -k deployment/overlays/prod' + sh """ + sshpass -p jenkins ssh -o StrictHostKeyChecking=no -p 2222 jenkins@prod "~/address-validation-service-distribution/bin/meecrowave.sh stop\ + && rm -rf ~/address-validation-service-distribution\ + && unzip ~/address-validation-service-meecrowave-distribution.zip\ + && ~/address-validation-service-distribution/bin/meecrowave.sh start" + """ } else { - sh 'kubectl apply -k deployment/overlays/test' - sh "sed -i 's/${env.GIT_COMMIT}/${env.SNAPSHOT_VERSION}/g' deployment/overlays/test/kustomization.yaml" + sh """ + sshpass -p jenkins ssh -o StrictHostKeyChecking=no -p 2222 jenkins@test "~/address-validation-service-distribution/bin/meecrowave.sh stop\ + && rm -rf ~/address-validation-service-distribution\ + && unzip ~/address-validation-service-meecrowave-distribution.zip\ + && ~/address-validation-service-distribution/bin/meecrowave.sh start" + """ } } } diff --git a/address-validation-service/pom.xml b/address-validation-service/pom.xml index f54426f..e2b917c 100644 --- a/address-validation-service/pom.xml +++ b/address-validation-service/pom.xml @@ -12,23 +12,21 @@ 4.0.0 de.openkonwledge.sample.shop - ${service.name} - 1.0.0-SNAPSHOT - war + address-validation-service + 1.1.0-SNAPSHOT - scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/address-validation-service.git - scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/address-validation-service.git + scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/address-validation-service.git + scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/address-validation-service.git - online-shop 11 11 false UTF-8 + http://localhost 1.2.13 - 1.9.6 5.8.2 @@ -40,55 +38,11 @@ ${meecrowave.version} provided - - org.apache.meecrowave - meecrowave-core - ${meecrowave.version} - provided - - - org.apache.geronimo.specs - geronimo-validation_1.0_spec - 1.1 - - - org.eclipse.microprofile.config - microprofile-config-api - 1.4 - - - org.apache.geronimo.config - geronimo-config-impl - 1.2.2 - - - org.eclipse.microprofile.jwt - microprofile-jwt-auth-api - 1.2.1 - - - org.apache.geronimo - geronimo-jwt-auth - 1.0.4 - - - org.apache.deltaspike.modules - deltaspike-security-module-api - ${deltaspike.version} - compile - - - org.apache.deltaspike.modules - deltaspike-security-module-impl - ${deltaspike.version} - runtime - org.apache.commons commons-lang3 3.9 - org.junit.jupiter junit-jupiter-api @@ -107,11 +61,6 @@ 3.22.0 test - - org.mockito - mockito-core - 2.28.2 - au.com.dius.pact.provider junit5 @@ -124,22 +73,9 @@ ${meecrowave.version} test - - rocks.limburg.cdimock - cdimock - 1.0.4 - test - - - com.tngtech.archunit - archunit - 1.0.1 - test - - ${project.artifactId} org.apache.maven.plugins @@ -148,56 +84,17 @@ ${project.version} + ${pactBroker.url} - org.apache.maven.plugins - maven-dependency-plugin - - - copy-runner - package - - copy - - - - - org.apache.meecrowave - meecrowave-core - ${meecrowave-version} - runner - - - ${project.build.directory}/runner - true - - - - - - maven-checkstyle-plugin - 3.2.0 + org.apache.meecrowave + meecrowave-maven-plugin + ${meecrowave.version} - true - ${project.basedir}/src/main/checkstyle/java.header - true - true + ${project.basedir}/src/main/meecrowave/conf - - - compile - compile - - checkstyle - - - ${project.basedir}/src/main/checkstyle/configuration.xml - true - - - diff --git a/address-validation-service/src/main/java/de/openknowledge/sample/address/domain/CityName.java b/address-validation-service/src/main/java/de/openknowledge/sample/address/domain/CityName.java index 1fea087..64603ae 100644 --- a/address-validation-service/src/main/java/de/openknowledge/sample/address/domain/CityName.java +++ b/address-validation-service/src/main/java/de/openknowledge/sample/address/domain/CityName.java @@ -5,7 +5,11 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * +<<<<<<< HEAD * http://www.apache.org/licenses/LICENSE-2.0 +======= + * http://www.apache.org/licenses/LICENSE-2.0 +>>>>>>> a8745a7... update apps to pipeline * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/address-validation-service/src/main/meecrowave/conf/meecrowave.properties b/address-validation-service/src/main/meecrowave/conf/meecrowave.properties new file mode 100644 index 0000000..fc05e42 --- /dev/null +++ b/address-validation-service/src/main/meecrowave/conf/meecrowave.properties @@ -0,0 +1,5 @@ +# This file contains the meecrowave default configuration +# More on http://openwebbeans.apache.org/meecrowave/meecrowave-core/cli.html + +tomcat-access-log-pattern = %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i" +http=8084 diff --git a/billing-service/Dockerfile b/billing-service/Dockerfile index 850e4e9..9a8b4a3 100644 --- a/billing-service/Dockerfile +++ b/billing-service/Dockerfile @@ -1,15 +1,7 @@ -FROM maven:3.6.3-jdk-11-openj9 AS mvn +FROM openjdk:11-jre -WORKDIR /usr/src/online-shop -COPY pom.xml ./ -RUN mvn package dependency:go-offline # cache dependencies -COPY src ./src -RUN mvn clean package -Dservice.name=billing-service -DskipTests +RUN wget https://repo.maven.apache.org/maven2/org/apache/meecrowave/meecrowave-core/1.2.13/meecrowave-core-1.2.13-runner.jar -O /opt/meecrowave-core-runner.jar +ADD target/billing-service.war /opt/billing-service.war -FROM openjdk:11 - -EXPOSE 8080 -COPY --from=mvn /usr/src/online-shop/target/runner/meecrowave-core-runner.jar /opt/meecrowave-runner.jar -COPY --from=mvn /usr/src/online-shop/target/billing-service.war /opt/billing-service.war - -ENTRYPOINT ["java", "--illegal-access=permit", "-Djava.net.preferIPv4Stack=true", "-jar", "/opt/meecrowave-runner.jar", "--webapp", "/opt/billing-service.war"] +EXPOSE 4001 +ENTRYPOINT ["java", "-Djava.net.preferIPv4Stack=true", "-jar", "/opt/meecrowave-core-runner.jar", "--host", "0.0.0.0", "--http", "4001", "--webapp", "/opt/billing-service.war"] diff --git a/billing-service/Jenkinsfile b/billing-service/Jenkinsfile index f1ec156..94f8257 100644 --- a/billing-service/Jenkinsfile +++ b/billing-service/Jenkinsfile @@ -2,6 +2,10 @@ pipeline { agent any + parameters { + booleanParam(name: 'verifyPacts', defaultValue: false, description: 'should this job just run to verify pacts from a consumer') + } + options { disableConcurrentBuilds() } @@ -12,6 +16,7 @@ pipeline { PERFORM_RELEASE = "${env.SNAPSHOT_VERSION.contains('-SNAPSHOT') && env.BRANCH_NAME == 'main' && !env.LAST_COMMIT_MESSAGE.startsWith('update version to ')}" RELEASE_VERSION = "${env.SNAPSHOT_VERSION.contains('-SNAPSHOT') ? env.SNAPSHOT_VERSION.substring(0, env.SNAPSHOT_VERSION.lastIndexOf('-SNAPSHOT')) : SNAPSHOT_VERSION}" VERSION = "${env.BRANCH_NAME == 'main' && !env.LAST_COMMIT_MESSAGE.startsWith('update version to ') ? env.RELEASE_VERSION : env.SNAPSHOT_VERSION}" + ROOT_DIRECTORY = "${params.verifyPacts == true && env.BRANCH_NAME == 'main' && env.SNAPSHOT_VERSION.endsWith("-SNAPSHOT") ? 'target/checkout' : '.'}" } triggers { @@ -26,19 +31,29 @@ pipeline { branch 'main' } environment name: 'PERFORM_RELEASE', value: 'true' + expression { + params.verifyPacts == true + } } } steps { echo "Building version ${env.VERSION}" script { - if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { + if (params.verifyPacts == true && env.BRANCH_NAME == 'main' && env.SNAPSHOT_VERSION.endsWith("-SNAPSHOT")) { + int previousRevision = Integer.parseInt(env.RELEASE_VERSION.substring(env.RELEASE_VERSION.lastIndexOf(".") + 1)) - 1 + if (previousRevision >= 0) { + previousVersion = RELEASE_VERSION.substring(0, env.RELEASE_VERSION.lastIndexOf(".")) + "." + previousRevision + sh "mvn scm:checkout -DscmVersionType=tag -DscmVersion=${previousVersion}" + echo "Testing against version ${previousVersion}" + } + } else if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { sh "mvn versions:set -DnewVersion=${env.RELEASE_VERSION} -B" - sh "sed -i 's/${env.SNAPSHOT_VERSION}/${env.RELEASE_VERSION}/g' deployment/overlays/prod/kustomization.yaml" - } else { - sh "sed -i 's/${env.SNAPSHOT_VERSION}/${env.GIT_COMMIT}/g' deployment/overlays/test/kustomization.yaml" } } - sh 'mvn clean test-compile -B' + sh """ + cd ${ROOT_DIRECTORY} + mvn clean test-compile -B + """ } } stage ('Test') { @@ -48,10 +63,16 @@ pipeline { branch 'main' } environment name: 'PERFORM_RELEASE', value: 'true' + expression { + params.verifyPacts == true + } } } steps { - sh "mvn test -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -B" + sh """ + cd ${ROOT_DIRECTORY} + mvn test -DpactBroker.url=http://pact:9292 -Dpact.verifier.publishResults=true -B + """ } } stage ('Package') { @@ -62,10 +83,12 @@ pipeline { } environment name: 'PERFORM_RELEASE', value: 'true' } + expression { + params.verifyPacts == false + } } steps { - sh 'mvn package -Dmaven.test.skip=true -B' - sh 'docker build -t billing .' + sh 'mvn package meecrowave:bundle -DskipTests -B' } } stage ('Push') { @@ -76,16 +99,13 @@ pipeline { } environment name: 'PERFORM_RELEASE', value: 'true' } + expression { + params.verifyPacts == false + } } steps { - sh """ - docker tag billing localhost:30010/billing:${env.VERSION} - docker tag billing localhost:30010/billing:${env.BRANCH_NAME == 'main' ? 'stable' : 'latest'} - docker tag billing localhost:30010/billing:${env.GIT_COMMIT} - docker push localhost:30010/billing:${env.VERSION} - docker push localhost:30010/billing:${env.BRANCH_NAME == 'main' ? 'stable' : 'latest'} - docker push localhost:30010/billing:${env.GIT_COMMIT} - """ + sh 'sshpass -p jenkins scp -o StrictHostKeyChecking=no -P 2222 target/billing-service-meecrowave-distribution.zip jenkins@test:~/' + sh 'sshpass -p jenkins scp -o StrictHostKeyChecking=no -P 2222 target/billing-service-meecrowave-distribution.zip jenkins@prod:~/' script { if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { sh 'git config --global user.name "Jenkins"' @@ -94,7 +114,6 @@ pipeline { sh "mvn scm:tag -Dtag=${env.RELEASE_VERSION} -B" int nextRevision = Integer.parseInt(env.RELEASE_VERSION.substring(env.RELEASE_VERSION.lastIndexOf(".") + 1)) + 1 nextVersion = RELEASE_VERSION.substring(0, env.RELEASE_VERSION.lastIndexOf(".")) + "." + nextRevision + "-SNAPSHOT" - sh "sed -i 's/${env.RELEASE_VERSION}/${nextVersion}/g' deployment/overlays/prod/kustomization.yaml" sh "mvn versions:set scm:checkin -DnewVersion=${nextVersion} -Dmessage='update version to ${nextVersion}' -B" } } @@ -102,6 +121,9 @@ pipeline { } stage ('Deploy') { when { + expression { + params.verifyPacts == false + } anyOf { not { branch 'main' @@ -113,10 +135,19 @@ pipeline { script { if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { sh "mvn scm:checkout -DscmVersion=${env.RELEASE_VERSION} -DscmVersionType=tag -B" - sh 'kubectl apply -k deployment/overlays/prod' + sh """ + sshpass -p jenkins ssh -o StrictHostKeyChecking=no -p 2222 jenkins@prod "~/billing-service-distribution/bin/meecrowave.sh stop\ + && rm -rf ~/billing-service-distribution\ + && unzip ~/billing-service-meecrowave-distribution.zip\ + && ~/billing-service-distribution/bin/meecrowave.sh start" + """ } else { - sh 'kubectl apply -k deployment/overlays/test' - sh "sed -i 's/${env.GIT_COMMIT}/${env.SNAPSHOT_VERSION}/g' deployment/overlays/test/kustomization.yaml" + sh """ + sshpass -p jenkins ssh -o StrictHostKeyChecking=no -p 2222 jenkins@test "~/billing-service-distribution/bin/meecrowave.sh stop\ + && rm -rf ~/billing-service-distribution\ + && unzip ~/billing-service-meecrowave-distribution.zip\ + && ~/billing-service-distribution/bin/meecrowave.sh start" + """ } } } diff --git a/billing-service/pom.xml b/billing-service/pom.xml index 9e7c55d..0604d52 100644 --- a/billing-service/pom.xml +++ b/billing-service/pom.xml @@ -12,23 +12,22 @@ 4.0.0 de.openkonwledge.sample.shop - ${service.name} + billing-service 1.0.0-SNAPSHOT war - scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/billing-service.git - scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/billing-service.git + scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/billing-service.git + scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/billing-service.git - online-shop 11 11 false UTF-8 + http://localhost:5000 1.2.13 - 1.9.6 5.8.2 @@ -40,55 +39,16 @@ ${meecrowave.version} provided - - org.apache.meecrowave - meecrowave-core - ${meecrowave.version} - provided - org.apache.geronimo.specs geronimo-validation_1.0_spec 1.1 - - org.eclipse.microprofile.config - microprofile-config-api - 1.4 - - - org.apache.geronimo.config - geronimo-config-impl - 1.2.2 - - - org.eclipse.microprofile.jwt - microprofile-jwt-auth-api - 1.2.1 - - - org.apache.geronimo - geronimo-jwt-auth - 1.0.4 - - - org.apache.deltaspike.modules - deltaspike-security-module-api - ${deltaspike.version} - compile - - - org.apache.deltaspike.modules - deltaspike-security-module-impl - ${deltaspike.version} - runtime - org.apache.commons commons-lang3 3.9 - org.junit.jupiter junit-jupiter-api @@ -107,12 +67,6 @@ 3.22.0 test - - org.mockito - mockito-core - 2.28.2 - test - au.com.dius.pact.provider junit5 @@ -125,22 +79,9 @@ ${meecrowave.version} test - - rocks.limburg.cdimock - cdimock - 1.0.4 - test - - - com.tngtech.archunit - archunit - 1.0.1 - test - - ${project.artifactId} org.apache.maven.plugins @@ -149,56 +90,17 @@ ${project.version} + ${pactBroker.url} - org.apache.maven.plugins - maven-dependency-plugin - - - copy-runner - package - - copy - - - - - org.apache.meecrowave - meecrowave-core - ${meecrowave-version} - runner - - - ${project.build.directory}/runner - true - - - - - - maven-checkstyle-plugin - 3.2.0 + org.apache.meecrowave + meecrowave-maven-plugin + ${meecrowave.version} - true - ${project.basedir}/src/main/checkstyle/java.header - true - true + ${project.basedir}/src/main/meecrowave/conf - - - compile - compile - - checkstyle - - - ${project.basedir}/src/main/checkstyle/configuration.xml - true - - - diff --git a/billing-service/src/main/java/de/openknowledge/sample/address/domain/AddressLine.java b/billing-service/src/main/java/de/openknowledge/sample/address/domain/AddressLine.java index 864e588..94c5ee6 100644 --- a/billing-service/src/main/java/de/openknowledge/sample/address/domain/AddressLine.java +++ b/billing-service/src/main/java/de/openknowledge/sample/address/domain/AddressLine.java @@ -22,6 +22,8 @@ import de.openknowledge.sample.address.domain.AddressLine.Adapter; +import static org.apache.commons.lang3.Validate.notNull; + @JsonbTypeAdapter(Adapter.class) public class AddressLine { @@ -66,7 +68,6 @@ public String toString() { return line; } - @Override public int hashCode() { return line.hashCode(); diff --git a/billing-service/src/main/meecrowave/conf/meecrowave.properties b/billing-service/src/main/meecrowave/conf/meecrowave.properties new file mode 100644 index 0000000..fc05e42 --- /dev/null +++ b/billing-service/src/main/meecrowave/conf/meecrowave.properties @@ -0,0 +1,5 @@ +# This file contains the meecrowave default configuration +# More on http://openwebbeans.apache.org/meecrowave/meecrowave-core/cli.html + +tomcat-access-log-pattern = %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i" +http=8084 diff --git a/billing-service/src/test/java/de/openknowledge/sample/address/BillingAddressServiceTest.java b/billing-service/src/test/java/de/openknowledge/sample/address/BillingAddressServiceTest.java index 72d4bd5..d89a2da 100644 --- a/billing-service/src/test/java/de/openknowledge/sample/address/BillingAddressServiceTest.java +++ b/billing-service/src/test/java/de/openknowledge/sample/address/BillingAddressServiceTest.java @@ -15,6 +15,8 @@ */ package de.openknowledge.sample.address; +import static java.util.Optional.ofNullable; + import org.apache.meecrowave.Meecrowave; import org.apache.meecrowave.junit5.MonoMeecrowaveConfig; import org.apache.meecrowave.testing.ConfigurationInject; @@ -41,13 +43,13 @@ public class BillingAddressServiceTest { @BeforeEach public void setUp(PactVerificationContext context) { - context.setTarget(new HttpTestTarget("localhost", config.getHttpPort(), "/")); + ofNullable(context).ifPresent(c -> c.setTarget(new HttpTestTarget("localhost", config.getHttpPort(), "/"))); } @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { - context.verifyInteraction(); + ofNullable(context).ifPresent(PactVerificationContext::verifyInteraction); } @State("Three customers") diff --git a/customer-service/Dockerfile b/customer-service/Dockerfile index e80a02f..e1012b4 100644 --- a/customer-service/Dockerfile +++ b/customer-service/Dockerfile @@ -1,15 +1,7 @@ -FROM maven:3.6.3-jdk-11-openj9 AS mvn +FROM openjdk:11-jre -WORKDIR /usr/src/online-shop -COPY pom.xml ./ -RUN mvn package dependency:go-offline # cache dependencies -COPY src ./src -RUN mvn clean package -Dservice.name=customer-service -DskipTests +RUN wget https://repo.maven.apache.org/maven2/org/apache/meecrowave/meecrowave-core/1.2.13/meecrowave-core-1.2.13-runner.jar -O /opt/meecrowave-core-runner.jar +ADD target/customer-service.war /opt/customer-service.war -FROM openjdk:11 - -EXPOSE 8080 -COPY --from=mvn /usr/src/online-shop/target/runner/meecrowave-core-runner.jar /opt/meecrowave-runner.jar -COPY --from=mvn /usr/src/online-shop/target/customer-service.war /opt/customer-service.war - -ENTRYPOINT ["java", "--illegal-access=permit", "-Djava.net.preferIPv4Stack=true", "-jar", "/opt/meecrowave-runner.jar", "--webapp", "/opt/customer-service.war"] +EXPOSE 4000 +ENTRYPOINT ["java", "-Djava.net.preferIPv4Stack=true", "-jar", "/opt/meecrowave-core-runner.jar", "--http", "4000", "--webapp", "/opt/customer-service.war"] diff --git a/customer-service/Jenkinsfile b/customer-service/Jenkinsfile index 738887d..4164c36 100644 --- a/customer-service/Jenkinsfile +++ b/customer-service/Jenkinsfile @@ -33,9 +33,6 @@ pipeline { script { if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { sh "mvn versions:set -DnewVersion=${env.RELEASE_VERSION} -B" - sh "sed -i 's/${env.SNAPSHOT_VERSION}/${env.RELEASE_VERSION}/g' deployment/overlays/prod/kustomization.yaml" - } else { - sh "sed -i 's/${env.SNAPSHOT_VERSION}/${env.GIT_COMMIT}/g' deployment/overlays/test/kustomization.yaml" } } sh 'mvn clean test-compile -B' @@ -51,7 +48,27 @@ pipeline { } } steps { - sh 'mvn test pact:publish -DpactBroker.url=http://pact-service:8080 -B' + sh 'mvn test pact:publish -DpactBroker.url=http://pact:9292 -Dpact.verifier.publishResults=true -B' + } + } + stage ('Test providers') { + when { + anyOf { + not { + branch 'main' + } + environment name: 'PERFORM_RELEASE', value: 'true' + } + } + steps { + parallel( + 'delivery-service': { + build job: "delivery-service/${env.BRANCH_NAME}", parameters: [booleanParam(name: 'verifyPacts', value: true)] + }, + 'billing-service': { + build job: "billing-service/${env.BRANCH_NAME}", parameters: [booleanParam(name: 'verifyPacts', value: true)] + } + ) } } stage ('Package') { @@ -64,8 +81,7 @@ pipeline { } } steps { - sh 'mvn package -DskipTests -B' - sh 'docker build -t customer .' + sh 'mvn package meecrowave:bundle -DskipTests -B' } } stage ('Push') { @@ -78,14 +94,8 @@ pipeline { } } steps { - sh """ - docker tag customer localhost:30010/customer:${env.VERSION} - docker tag customer localhost:30010/customer:${env.BRANCH_NAME == 'main' ? 'stable' : 'latest'} - docker tag customer localhost:30010/customer:${env.GIT_COMMIT} - docker push localhost:30010/customer:${env.VERSION} - docker push localhost:30010/customer:${env.BRANCH_NAME == 'main' ? 'stable' : 'latest'} - docker push localhost:30010/customer:${env.GIT_COMMIT} - """ + sh 'sshpass -p jenkins scp -o StrictHostKeyChecking=no -P 2222 target/customer-service-meecrowave-distribution.zip jenkins@test:~/' + sh 'sshpass -p jenkins scp -o StrictHostKeyChecking=no -P 2222 target/customer-service-meecrowave-distribution.zip jenkins@prod:~/' script { if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { sh 'git config --global user.name "Jenkins"' @@ -94,7 +104,6 @@ pipeline { sh "mvn scm:tag -Dtag=${env.RELEASE_VERSION} -B" int nextRevision = Integer.parseInt(env.RELEASE_VERSION.substring(env.RELEASE_VERSION.lastIndexOf(".") + 1)) + 1 nextVersion = RELEASE_VERSION.substring(0, env.RELEASE_VERSION.lastIndexOf(".")) + "." + nextRevision + "-SNAPSHOT" - sh "sed -i 's/${env.RELEASE_VERSION}/${nextVersion}/g' deployment/overlays/prod/kustomization.yaml" sh "mvn versions:set scm:checkin -DnewVersion=${nextVersion} -Dmessage='update version to ${nextVersion}' -B" } } @@ -113,10 +122,19 @@ pipeline { script { if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { sh "mvn scm:checkout -DscmVersion=${env.RELEASE_VERSION} -DscmVersionType=tag -B" - sh 'kubectl apply -k deployment/overlays/prod' + sh """ + sshpass -p jenkins ssh -o StrictHostKeyChecking=no -p 2222 jenkins@prod "~/customer-service-distribution/bin/meecrowave.sh stop\ + && rm -rf ~/customer-service-distribution\ + && unzip ~/customer-service-meecrowave-distribution.zip\ + && ~/customer-service-distribution/bin/meecrowave.sh start" + """ } else { - sh 'kubectl apply -k deployment/overlays/test' - sh "sed -i 's/${env.GIT_COMMIT}/${env.SNAPSHOT_VERSION}/g' deployment/overlays/test/kustomization.yaml" + sh """ + sshpass -p jenkins ssh -o StrictHostKeyChecking=no -p 2222 jenkins@test "~/customer-service-distribution/bin/meecrowave.sh stop\ + && rm -rf ~/customer-service-distribution\ + && unzip ~/customer-service-meecrowave-distribution.zip\ + && ~/customer-service-distribution/bin/meecrowave.sh start" + """ } } } diff --git a/customer-service/pom.xml b/customer-service/pom.xml index f4ae147..5acf3a3 100644 --- a/customer-service/pom.xml +++ b/customer-service/pom.xml @@ -17,8 +17,8 @@ war - scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/customer-service.git - scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/customer-service.git + scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/customer-service.git + scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/customer-service.git @@ -219,6 +219,14 @@ ${pactBroker.url} + + org.apache.meecrowave + meecrowave-maven-plugin + ${meecrowave.version} + + ${project.basedir}/src/main/meecrowave/conf + + diff --git a/customer-service/src/main/meecrowave/conf/meecrowave.properties b/customer-service/src/main/meecrowave/conf/meecrowave.properties new file mode 100644 index 0000000..fc05e42 --- /dev/null +++ b/customer-service/src/main/meecrowave/conf/meecrowave.properties @@ -0,0 +1,5 @@ +# This file contains the meecrowave default configuration +# More on http://openwebbeans.apache.org/meecrowave/meecrowave-core/cli.html + +tomcat-access-log-pattern = %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i" +http=8084 diff --git a/delivery-service/Dockerfile b/delivery-service/Dockerfile index 5f57dd4..8623310 100644 --- a/delivery-service/Dockerfile +++ b/delivery-service/Dockerfile @@ -1,15 +1,8 @@ -FROM maven:3.6.3-jdk-11-openj9 AS mvn +FROM openjdk:11-jre -WORKDIR /usr/src/online-shop -COPY pom.xml ./ -RUN mvn package dependency:go-offline # cache dependencies -COPY src ./src -RUN mvn clean package -Dservice.name=delivery-service -DskipTests +RUN wget https://repo.maven.apache.org/maven2/javax/xml/bind/jaxb-api/2.3.1/jaxb-api-2.3.1.jar -O /opt/jaxb-api.jar +RUN wget https://repo.maven.apache.org/maven2/org/apache/meecrowave/meecrowave-core/1.2.13/meecrowave-core-1.2.13-runner.jar -O /opt/meecrowave-core-runner.jar +ADD target/delivery-service.war /opt/delivery-service.war -FROM openjdk:11 - -EXPOSE 8080 -COPY --from=mvn /usr/src/online-shop/target/runner/meecrowave-core-runner.jar /opt/meecrowave-runner.jar -COPY --from=mvn /usr/src/online-shop/target/delivery-service.war /opt/delivery-service.war - -ENTRYPOINT ["java", "--illegal-access=permit", "-Djava.net.preferIPv4Stack=true", "-jar", "/opt/meecrowave-runner.jar", "--webapp", "/opt/delivery-service.war"] +EXPOSE 4002 +ENTRYPOINT ["java", "--illegal-access=permit", "-Djava.net.preferIPv4Stack=true", "-cp", "/opt/meecrowave-core-runner.jar:/opt/jaxb-api.jar", "org.apache.meecrowave.runner.Cli", "--http", "4002", "--webapp","/opt/delivery-service.war"] diff --git a/delivery-service/Jenkinsfile b/delivery-service/Jenkinsfile index 589bf08..97adc51 100644 --- a/delivery-service/Jenkinsfile +++ b/delivery-service/Jenkinsfile @@ -2,6 +2,10 @@ pipeline { agent any + parameters { + booleanParam(name: 'verifyPacts', defaultValue: false, description: 'should this job just run to verify pacts from a consumer') + } + options { disableConcurrentBuilds() } @@ -12,6 +16,7 @@ pipeline { PERFORM_RELEASE = "${env.SNAPSHOT_VERSION.contains('-SNAPSHOT') && env.BRANCH_NAME == 'main' && !env.LAST_COMMIT_MESSAGE.startsWith('update version to ')}" RELEASE_VERSION = "${env.SNAPSHOT_VERSION.contains('-SNAPSHOT') ? env.SNAPSHOT_VERSION.substring(0, env.SNAPSHOT_VERSION.lastIndexOf('-SNAPSHOT')) : SNAPSHOT_VERSION}" VERSION = "${env.BRANCH_NAME == 'main' && !env.LAST_COMMIT_MESSAGE.startsWith('update version to ') ? env.RELEASE_VERSION : env.SNAPSHOT_VERSION}" + ROOT_DIRECTORY = "${params.verifyPacts == true && env.BRANCH_NAME == 'main' && env.SNAPSHOT_VERSION.endsWith("-SNAPSHOT") ? 'target/checkout' : '.'}" } triggers { @@ -26,19 +31,29 @@ pipeline { branch 'main' } environment name: 'PERFORM_RELEASE', value: 'true' + expression { + params.verifyPacts == true + } } } steps { echo "Building version ${env.VERSION}" script { - if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { + if (params.verifyPacts == true && env.BRANCH_NAME == 'main' && env.SNAPSHOT_VERSION.endsWith("-SNAPSHOT")) { + int previousRevision = Integer.parseInt(env.RELEASE_VERSION.substring(env.RELEASE_VERSION.lastIndexOf(".") + 1)) - 1 + if (previousRevision >= 0) { + previousVersion = RELEASE_VERSION.substring(0, env.RELEASE_VERSION.lastIndexOf(".")) + "." + previousRevision + sh "mvn scm:checkout -DscmVersionType=tag -DscmVersion=${previousVersion}" + echo "Testing against version ${previousVersion}" + } + } else if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { sh "mvn versions:set -DnewVersion=${env.RELEASE_VERSION} -B" - sh "sed -i 's/${env.SNAPSHOT_VERSION}/${env.RELEASE_VERSION}/g' deployment/overlays/prod/kustomization.yaml" - } else { - sh "sed -i 's/${env.SNAPSHOT_VERSION}/${env.GIT_COMMIT}/g' deployment/overlays/test/kustomization.yaml" } } - sh 'mvn clean test-compile -B' + sh """ + cd ${ROOT_DIRECTORY} + mvn clean test-compile -B + """ } } stage ('Test') { @@ -48,10 +63,33 @@ pipeline { branch 'main' } environment name: 'PERFORM_RELEASE', value: 'true' + expression { + params.verifyPacts == true + } } } steps { - sh "mvn test pact:publish -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -B" + sh """ + cd ${ROOT_DIRECTORY} + mvn test -DpactBroker.url=http://pact:9292 -Dpact.verifier.publishResults=true -B + """ + } + } + stage ('Test providers') { + when { + anyOf { + not { + branch 'main' + } + environment name: 'PERFORM_RELEASE', value: 'true' + } + expression { + params.verifyPacts == false + } + } + steps { + sh 'mvn pact:publish -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -B' + build job: "address-validation-service/${env.BRANCH_NAME}", parameters: [booleanParam(name: 'verifyPacts', value: true)] } } stage ('Package') { @@ -62,10 +100,12 @@ pipeline { } environment name: 'PERFORM_RELEASE', value: 'true' } + expression { + params.verifyPacts == false + } } steps { - sh 'mvn package -DskipTests -B' - sh 'docker build -t delivery .' + sh 'mvn package meecrowave:bundle -DskipTests -B' } } stage ('Push') { @@ -76,16 +116,13 @@ pipeline { } environment name: 'PERFORM_RELEASE', value: 'true' } + expression { + params.verifyPacts == false + } } steps { - sh """ - docker tag delivery localhost:30010/delivery:${env.VERSION} - docker tag delivery localhost:30010/delivery:${env.BRANCH_NAME == 'main' ? 'stable' : 'latest'} - docker tag delivery localhost:30010/delivery:${env.GIT_COMMIT} - docker push localhost:30010/delivery:${env.VERSION} - docker push localhost:30010/delivery:${env.BRANCH_NAME == 'main' ? 'stable' : 'latest'} - docker push localhost:30010/delivery:${env.GIT_COMMIT} - """ + sh 'sshpass -p jenkins scp -o StrictHostKeyChecking=no -P 2222 target/delivery-service-meecrowave-distribution.zip jenkins@test:~/' + sh 'sshpass -p jenkins scp -o StrictHostKeyChecking=no -P 2222 target/delivery-service-meecrowave-distribution.zip jenkins@prod:~/' script { if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { sh 'git config --global user.name "Jenkins"' @@ -94,7 +131,6 @@ pipeline { sh "mvn scm:tag -Dtag=${env.RELEASE_VERSION} -B" int nextRevision = Integer.parseInt(env.RELEASE_VERSION.substring(env.RELEASE_VERSION.lastIndexOf(".") + 1)) + 1 nextVersion = RELEASE_VERSION.substring(0, env.RELEASE_VERSION.lastIndexOf(".")) + "." + nextRevision + "-SNAPSHOT" - sh "sed -i 's/${env.RELEASE_VERSION}/${nextVersion}/g' deployment/overlays/prod/kustomization.yaml" sh "mvn versions:set scm:checkin -DnewVersion=${nextVersion} -Dmessage='update version to ${nextVersion}' -B" } } @@ -102,6 +138,9 @@ pipeline { } stage ('Deploy') { when { + expression { + params.verifyPacts == false + } anyOf { not { branch 'main' @@ -113,10 +152,19 @@ pipeline { script { if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) { sh "mvn scm:checkout -DscmVersion=${env.RELEASE_VERSION} -DscmVersionType=tag -B" - sh 'kubectl apply -k deployment/overlays/prod' + sh """ + sshpass -p jenkins ssh -o StrictHostKeyChecking=no -p 2222 jenkins@prod "~/delivery-service-distribution/bin/meecrowave.sh stop\ + && rm -rf ~/delivery-service-distribution\ + && unzip ~/delivery-service-meecrowave-distribution.zip\ + && ~/delivery-service-distribution/bin/meecrowave.sh start" + """ } else { - sh 'kubectl apply -k deployment/overlays/test' - sh "sed -i 's/${env.GIT_COMMIT}/${env.SNAPSHOT_VERSION}/g' deployment/overlays/test/kustomization.yaml" + sh """ + sshpass -p jenkins ssh -o StrictHostKeyChecking=no -p 2222 jenkins@test "~/delivery-service-distribution/bin/meecrowave.sh stop\ + && rm -rf ~/delivery-service-distribution\ + && unzip ~/delivery-service-meecrowave-distribution.zip\ + && ~/delivery-service-distribution/bin/meecrowave.sh start" + """ } } } diff --git a/delivery-service/namespaces.yaml b/delivery-service/namespaces.yaml deleted file mode 100644 index ab5c6df..0000000 --- a/delivery-service/namespaces.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - name: prod - labels: - name: prod ---- -apiVersion: v1 -kind: Namespace -metadata: - name: test - labels: - name: test diff --git a/delivery-service/pom.xml b/delivery-service/pom.xml index 442c238..433fedc 100644 --- a/delivery-service/pom.xml +++ b/delivery-service/pom.xml @@ -17,8 +17,8 @@ war - scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/delivery-service.git - scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/delivery-service.git + scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/delivery-service.git + scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/delivery-service.git @@ -263,6 +263,14 @@ ${pactBroker.url} + + org.apache.meecrowave + meecrowave-maven-plugin + ${meecrowave.version} + + ${project.basedir}/src/main/meecrowave/conf + + diff --git a/delivery-service/src/main/meecrowave/conf/meecrowave.properties b/delivery-service/src/main/meecrowave/conf/meecrowave.properties new file mode 100644 index 0000000..fc05e42 --- /dev/null +++ b/delivery-service/src/main/meecrowave/conf/meecrowave.properties @@ -0,0 +1,5 @@ +# This file contains the meecrowave default configuration +# More on http://openwebbeans.apache.org/meecrowave/meecrowave-core/cli.html + +tomcat-access-log-pattern = %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i" +http=8084 diff --git a/delivery-service/src/test/java/de/openknowledge/sample/address/DeliveryAddressServiceTest.java b/delivery-service/src/test/java/de/openknowledge/sample/address/DeliveryAddressServiceTest.java index 185cf27..fafa383 100644 --- a/delivery-service/src/test/java/de/openknowledge/sample/address/DeliveryAddressServiceTest.java +++ b/delivery-service/src/test/java/de/openknowledge/sample/address/DeliveryAddressServiceTest.java @@ -17,6 +17,7 @@ import static de.openknowledge.sample.infrastructure.DatabaseCleanup.with; import static de.openknowledge.sample.infrastructure.ScriptExecutor.executeWith; +import static java.util.Optional.ofNullable; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.doThrow; @@ -66,13 +67,13 @@ public class DeliveryAddressServiceTest { public void setUp(PactVerificationContext context) { doThrow(new ValidationException("City not found")) .when(addressValidationService).validate(argThat(a -> a.getCity().toString().contains("London"))); - context.setTarget(new HttpTestTarget("localhost", config.getHttpPort(), "/")); + ofNullable(context).ifPresent(c -> c.setTarget(new HttpTestTarget("localhost", config.getHttpPort(), "/"))); } @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { - context.verifyInteraction(); + ofNullable(context).ifPresent(PactVerificationContext::verifyInteraction); } @State("Three customers")