Skip to content

Commit

Permalink
update apps to pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
schwen authored and ArneLimburg committed Nov 7, 2024
1 parent ebeb55b commit 11f4df8
Show file tree
Hide file tree
Showing 21 changed files with 299 additions and 372 deletions.
18 changes: 5 additions & 13 deletions address-validation-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
71 changes: 51 additions & 20 deletions address-validation-service/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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 {
Expand All @@ -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') {
Expand All @@ -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') {
Expand All @@ -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') {
Expand All @@ -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"'
Expand All @@ -94,14 +114,16 @@ 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"
}
}
}
}
stage ('Deploy') {
when {
expression {
params.verifyPacts == false
}
anyOf {
not {
branch 'main'
Expand All @@ -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"
"""
}
}
}
Expand Down
123 changes: 10 additions & 113 deletions address-validation-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@
<modelVersion>4.0.0</modelVersion>

<groupId>de.openkonwledge.sample.shop</groupId>
<artifactId>${service.name}</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<artifactId>address-validation-service</artifactId>
<version>1.1.0-SNAPSHOT</version>

<scm>
<connection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/address-validation-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/address-validation-service.git</developerConnection>
<connection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/address-validation-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/address-validation-service.git</developerConnection>
</scm>

<properties>
<service.name>online-shop</service.name>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<pactBroker.url>http://localhost</pactBroker.url>
<meecrowave.version>1.2.13</meecrowave.version>
<deltaspike.version>1.9.6</deltaspike.version>
<junit.version>5.8.2</junit.version>
</properties>

Expand All @@ -40,55 +38,11 @@
<version>${meecrowave.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.meecrowave</groupId>
<artifactId>meecrowave-core</artifactId>
<version>${meecrowave.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-validation_1.0_spec</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.config</groupId>
<artifactId>geronimo-config-impl</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.jwt</groupId>
<artifactId>microprofile-jwt-auth-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo</groupId>
<artifactId>geronimo-jwt-auth</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-security-module-api</artifactId>
<version>${deltaspike.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-security-module-impl</artifactId>
<version>${deltaspike.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -107,11 +61,6 @@
<version>3.22.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.28.2</version>
</dependency>
<dependency>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>junit5</artifactId>
Expand All @@ -124,22 +73,9 @@
<version>${meecrowave.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>rocks.limburg.cdimock</groupId>
<artifactId>cdimock</artifactId>
<version>1.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit</artifactId>
<version>1.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -148,56 +84,17 @@
<configuration>
<systemPropertyVariables>
<pact.provider.version>${project.version}</pact.provider.version>
<pactBroker.url>${pactBroker.url}</pactBroker.url>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-runner</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.meecrowave</groupId>
<artifactId>meecrowave-core</artifactId>
<version>${meecrowave-version}</version>
<classifier>runner</classifier>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/runner</outputDirectory>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.0</version>
<groupId>org.apache.meecrowave</groupId>
<artifactId>meecrowave-maven-plugin</artifactId>
<version>${meecrowave.version}</version>
<configuration>
<consoleOutput>true</consoleOutput>
<headerLocation>${project.basedir}/src/main/checkstyle/java.header</headerLocation>
<failsOnError>true</failsOnError>
<consoleOutput>true</consoleOutput>
<conf>${project.basedir}/src/main/meecrowave/conf</conf>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>checkstyle</goal>
</goals>
<configuration>
<configLocation>${project.basedir}/src/main/checkstyle/configuration.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
18 changes: 5 additions & 13 deletions billing-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
Loading

0 comments on commit 11f4df8

Please sign in to comment.