This commit is contained in:
Sebastian Sdorra 2018-05-16 16:42:53 +02:00
commit d5d8a83ddc
6 changed files with 333 additions and 307 deletions

99
Jenkinsfile vendored
View file

@ -1,56 +1,81 @@
#!groovy #!groovy
node { node {
cesFqdn = "ecosystem.cloudogu.net"; properties([
cesUrl = "https://${cesFqdn}"; // Don't run concurrent builds, because the ITs use the same port causing random failures on concurrent builds.
credentials = usernamePassword(credentialsId: 'scmCredentials', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME'); disableConcurrentBuilds()
])
stage('Checkout') { cesFqdn = findHostName()
checkout scm cesUrl = "https://${cesFqdn}"
} credentials = usernamePassword(credentialsId: 'scmCredentials', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')
stage('Build') { catchError {
mvn "-DskipTests clean package"
// archive artifact stage('Checkout') {
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true checkout scm
} }
stage('Test') { stage('Build') {
String jacoco = "org.jacoco:jacoco-maven-plugin:0.7.7.201606060606"; mvn "-DskipTests clean package"
mvn "${jacoco}:prepare-agent verify ${jacoco}:report"
// Archive JUnit results, if any // archive artifact
junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml' archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
} }
stage('SonarQube Analysis') { parallel(
withCredentials([credentials]) { test: {
//noinspection GroovyAssignabilityCheck stage('Test') {
mvn "org.codehaus.mojo:sonar-maven-plugin:3.2:sonar -Dsonar.host.url=${cesUrl}/sonar " + String jacoco = "org.jacoco:jacoco-maven-plugin:0.7.7.201606060606"
"-Dsonar.login=${USERNAME} -Dsonar.password=${PASSWORD} -Dsonar.exclusions=target/**" mvn "${jacoco}:prepare-agent test ${jacoco}:report"
}
},
integrationTest: {
stage('Integration Test') {
String jacoco = "org.jacoco:jacoco-maven-plugin:0.7.7.201606060606";
mvn "${jacoco}:prepare-agent-integration failsafe:integration-test ${jacoco}:report-integration"
}
}
)
stage('SonarQube Analysis') {
withCredentials([credentials]) {
//noinspection GroovyAssignabilityCheck
mvn "org.codehaus.mojo:sonar-maven-plugin:3.2:sonar -Dsonar.host.url=${cesUrl}/sonar " +
"-Dsonar.login=${USERNAME} -Dsonar.password=${PASSWORD} -Dsonar.exclusions=target/**"
}
}
stage('Deploy Artifacts') {
String releaseProp = "-DaltReleaseDeploymentRepository=${cesFqdn}::default::${cesUrl}/nexus/content/repositories/releases/";
String snapshotProp = "-DaltSnapshotDeploymentRepository=${cesFqdn}::default::${cesUrl}/nexus/content/repositories/snapshots/";
mvn "-DskipTests deploy ${releaseProp} ${snapshotProp}"
} }
} }
stage('Deploy Artifacts') { // Archive Unit and integration test results, if any
String releaseProp = "-DaltReleaseDeploymentRepository=${cesFqdn}::default::${cesUrl}/nexus/content/repositories/releases/"; junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/TEST-*.xml,**/target/surefire-reports/TEST-*.xml'
String snapshotProp = "-DaltSnapshotDeploymentRepository=${cesFqdn}::default::${cesUrl}/nexus/content/repositories/snapshots/";
mvn "-DskipTests deploy ${releaseProp} ${snapshotProp}"
}
stage('Deploy Application') {
sh "ansible-playbook playbook.yaml"
}
} }
String cesFqdn; // Init global vars in order to avoid NPE
String cesUrl; String cesFqdn = ''
def credentials; String cesUrl = ''
def credentials= {}
void mvn(String args) { void mvn(String args) {
writeSettingsXml() writeSettingsXml()
sh "./mvnw -s settings.xml --batch-mode -V -U -e -Dsurefire.useFile=false ${args}" sh "./mvnw -s settings.xml --batch-mode -V -U -e -Dsurefire.useFile=false ${args}"
sh 'rm -f settings.xml' sh 'rm -f settings.xml'
}
String findHostName() {
String regexMatchesHostName = 'https?://([^:/]*)'
// Storing matcher in a variable might lead to java.io.NotSerializableException: java.util.regex.Matcher
if (!(env.JENKINS_URL =~ regexMatchesHostName)) {
script.error 'Unable to determine hostname from env.JENKINS_URL. Expecting http(s)://server:port/jenkins'
}
return (env.JENKINS_URL =~ regexMatchesHostName)[0][1]
} }
void writeSettingsXml() { void writeSettingsXml() {

7
docs/Home.md Normal file
View file

@ -0,0 +1,7 @@
# Hello world!
Welcome to the Smeagol-Demo! Have some embedded PlantUML:
@startuml
Bob -> Alice : hello
@enduml

View file

@ -1,39 +0,0 @@
---
- hosts: all
become: yes
gather_facts: yes
tasks:
- name: Copy systemd descriptor
copy:
src: src/main/systemd/spring-petclinic.service
dest: /etc/systemd/system/spring-petclinic.service
notify:
- reload systemd
- name: Copy spring-petclinic
copy:
src: target/spring-petclinic.jar
dest: /opt/spring-petclinic.jar
owner: deploy
mode: u+rwx
notify:
- restart service
- name: Enable service
service:
name: spring-petclinic
enabled: yes
handlers:
- name: reload systemd
systemd:
name: spring-petclinic
daemon_reload: yes
- name: restart service
service:
name: spring-petclinic
state: restarted

453
pom.xml
View file

@ -1,230 +1,245 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.samples</groupId> <groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic</artifactId> <artifactId>spring-petclinic</artifactId>
<version>1.5.2-SNAPSHOT</version> <version>1.5.2-SNAPSHOT</version>
<parent> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<name>petclinic</name>
<properties>
<!-- Generic properties -->
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Web dependencies -->
<webjars-bootstrap.version>3.3.6</webjars-bootstrap.version>
<webjars-jquery-ui.version>1.11.4</webjars-jquery-ui.version>
<webjars-jquery.version>2.2.4</webjars-jquery.version>
<wro4j.version>1.8.0</wro4j.version>
<thymeleaf.version>3.0.6.RELEASE</thymeleaf.version>
<cobertura.version>2.7</cobertura.version>
</properties>
<dependencies>
<!-- Spring and Spring Boot dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<exclusions>
<exclusion>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Databases - Uses HSQL by default -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- caching -->
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<!-- webjars -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>${webjars-jquery.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery-ui</artifactId>
<version>${webjars-jquery-ui.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>${webjars-bootstrap.version}</version>
</dependency>
<!-- end of webjars -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>spring-petclinic</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<executions> <version>1.5.4.RELEASE</version>
<execution> </parent>
<!-- Spring Boot Actuator displays build-related information <name>petclinic</name>
if a META-INF/build-info.properties file is present -->
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<executable>true</executable>
<additionalProperties>
<encoding.source>${project.build.sourceEncoding}</encoding.source>
<encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting>
<java.source>${maven.compiler.source}</java.source>
<java.target>${maven.compiler.target}</java.target>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.version}</version>
<configuration>
<check />
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Spring Boot Actuator displays build-related information if a git.properties <properties>
file is present at the classpath -->
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties
</generateGitPropertiesFilename>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
</configuration>
</plugin>
<plugin> <!-- Generic properties -->
<groupId>ro.isdc.wro4j</groupId> <java.version>1.8</java.version>
<artifactId>wro4j-maven-plugin</artifactId> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version>${wro4j.version}</version> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<executions>
<execution> <!-- Web dependencies -->
<phase>generate-resources</phase> <webjars-bootstrap.version>3.3.6</webjars-bootstrap.version>
<goals> <webjars-jquery-ui.version>1.11.4</webjars-jquery-ui.version>
<goal>run</goal> <webjars-jquery.version>2.2.4</webjars-jquery.version>
</goals> <wro4j.version>1.8.0</wro4j.version>
</execution> <thymeleaf.version>3.0.6.RELEASE</thymeleaf.version>
</executions>
<configuration> <cobertura.version>2.7</cobertura.version>
<wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
<cssDestinationFolder>${project.build.directory}/classes/static/resources/css</cssDestinationFolder> </properties>
<wroFile>${basedir}/src/main/wro/wro.xml</wroFile>
<extraConfigFile>${basedir}/src/main/wro/wro.properties</extraConfigFile> <dependencies>
<contextFolder>${basedir}/src/main/less</contextFolder> <!-- Spring and Spring Boot dependencies -->
</configuration> <dependency>
<dependencies> <groupId>org.springframework.boot</groupId>
<dependency> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<exclusions>
<exclusion>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Databases - Uses HSQL by default -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- caching -->
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<!-- webjars -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>${webjars-jquery.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery-ui</artifactId>
<version>${webjars-jquery-ui.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId> <groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId> <artifactId>bootstrap</artifactId>
<version>${webjars-bootstrap.version}</version> <version>${webjars-bootstrap.version}</version>
</dependency> </dependency>
</dependencies> <!-- end of webjars -->
</plugin>
</plugins> <dependency>
</build> <groupId>org.springframework.boot</groupId>
<reporting> <artifactId>spring-boot-devtools</artifactId>
<plugins> <scope>runtime</scope>
<!-- integrate maven-cobertura-plugin to project site --> </dependency>
<plugin> </dependencies>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId> <build>
<version>${cobertura.version}</version> <finalName>spring-petclinic</finalName>
<configuration> <plugins>
<formats> <plugin>
<format>html</format> <groupId>org.springframework.boot</groupId>
</formats> <artifactId>spring-boot-maven-plugin</artifactId>
<check /> <executions>
</configuration> <execution>
</plugin> <!-- Spring Boot Actuator displays build-related information
</plugins> if a META-INF/build-info.properties file is present -->
</reporting> <goals>
<goal>build-info</goal>
</goals>
<configuration>
<executable>true</executable>
<additionalProperties>
<encoding.source>${project.build.sourceEncoding}</encoding.source>
<encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting>
<java.source>${maven.compiler.source}</java.source>
<java.target>${maven.compiler.target}</java.target>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.version}</version>
<configuration>
<check/>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Spring Boot Actuator displays build-related information if a git.properties
file is present at the classpath -->
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties
</generateGitPropertiesFilename>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
</configuration>
</plugin>
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>${wro4j.version}</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory
</wroManagerFactory>
<cssDestinationFolder>${project.build.directory}/classes/static/resources/css</cssDestinationFolder>
<wroFile>${basedir}/src/main/wro/wro.xml</wroFile>
<extraConfigFile>${basedir}/src/main/wro/wro.properties</extraConfigFile>
<contextFolder>${basedir}/src/main/less</contextFolder>
</configuration>
<dependencies>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>${webjars-bootstrap.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<!-- integrate maven-cobertura-plugin to project site -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.version}</version>
<configuration>
<formats>
<format>html</format>
</formats>
<check/>
</configuration>
</plugin>
</plugins>
</reporting>
</project> </project>

View file

@ -1,11 +0,0 @@
[Unit]
Description=spring-petclinic
After=syslog.target
[Service]
User=deploy
ExecStart=/opt/spring-petclinic.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,29 @@
package org.springframework.samples.petclinic.owner;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class OwnerControllerITCase {
@Autowired
private TestRestTemplate restTemplate;
/**
* Note: This test exists only for the purpose of serving as an example! Please write tests more sensible
* than this for your own applications.
*/
@Test
public void assertsUser1IsGeorgeFranklin() {
String body = this.restTemplate.getForObject("/owners/1", String.class);
assertThat(body).contains("<td><b>George Franklin</b></td>");
}
}