So#ware Architektur - johner.org: Home€¦ · Jenkins, maven SonarQube SOLID Schrife zum CD HTWG...
Transcript of So#ware Architektur - johner.org: Home€¦ · Jenkins, maven SonarQube SOLID Schrife zum CD HTWG...
MarkusGerhartHTWGKonstanz
So#wareArchitekturCon2nuousIntegra2onBuildManagementandCon2nuousDeployment
ZieledieserVeranstaltung
HTWGKonstanz MarkusGerhart 2
• Con<nuousIntegra<on(CI)verstehen§ Jenkins
• BuildManagementverstehen§ Ant§ Maven§ Gradle
• UndCon<nuousDeployment(CD)verstehen§ SaaS:SoKwareasaService
DasTempoderSoKwareentwicklung
HTWGKonstanz MarkusGerhart 3
• DesktopAnwendungen§ OfficeSuites,Browser,IDEs,Toolsetc.§ ReleasesimBereichvon3bis0.5Jahren§ ReleaseTrains,FixeReleaseZeitpunkte,alle12Monate
• MobileAnwendungen§ Instagram,§ Automa<scheUpdates§ Releasesalle1bis3Monate
• WebAnwendungen§ GoogleMail/Search/Drive,Github§ ReleasesallepaarTageoderWochen
AnforderungenandenSW-Entwicklungsprozess
HTWGKonstanz MarkusGerhart 4
• KleineTeams• AgileEntwicklung• TestgetriebeneEntwicklung• KomponentenbasierteArchitektur• PassendezugrundeliegendeArchitektur• Wenigabhängigkeiten(auchzu3rdpartySW)• Con<nousintegra<on(CI)• HoherAutoma<sierungsgrad
ToolsfürCon<nousIntegra<on
HTWGKonstanz MarkusGerhart 5
• CruiseControl§ EntwickeltvonThoughtWorks(Mar<nFowler)fürXP
• Hudson§ KohsukeKawaguchi,Sun,jetztOracle§ OpenSource,aberderNameunddieInfrastrukturwirdvonOraclekontrolliert/betrieben
• Jenkins§ AbwandlungvonHudsonin2011§ OpenSource,geleitetvonKohsukeKawaguchi
JenkinsvsHudson
HTWGKonstanz MarkusGerhart 6
Source:hfp://blog.cloudbees.com/2011/10/jenkins-safe-and-sensible-choice-for-ci.html
Tickets
Jenkins
HTWGKonstanz MarkusGerhart 7
• Con<nouseIntegra<onBuildServer§ LäuKineinemServletContainero AnwendungsserverwieTomcat,Jefy,
• Pluginbasiert§ Über600Pluginssindverfügbaro VersionControlSystemso Buildtoolso BugDatabaseso MetricToolso Reportgeneratorso Databasebackendso Lookandfeel
BuildAutoma<sierungstools
HTWGKonstanz MarkusGerhart 8
• BisherhatEclipsedieSWgebaut/kompiliert• JenkinsistunabhängigvonEclipse/IDEundeswirdeinunabhängigerBuildprozessbenö<gt
• Ant§ EntwickeltvonSunalseineOO-Alterna<vezumakeo FürdieJSP/ServletEngineundTomcat
§ Implemen<ertinJava§ XMLfürdieDefini<ondesAblaufsunderAbhängigkeiten,build.xml
• Maven• Gradle
Maven• MavenisteinSoKware-ManagementundVerständnisWerkzeugbasierendaufdemKonzepteinesProjektObjectModel(POM).EskanndasProjektBuildverwalten,Repor<ngFunk<onenbereitstellenunddieDokumenta<onaneinemzentralenPunktverwalten
• EinePOMDateiisteineXML-Datei,diealleInforma<onenüberdasProjektundKonfigura<onsdetailsenthält,dievonMavenfürdenBuildProzessbenö<gtwerden
HTWGKonstanz MarkusGerhart 10
ZieleundMerkmalevonMAVEN• MavenistmehralsnureinBuildTool• MavenFunk<onsumfang:§ EinfacherBuildProcess§ EinheitlichesBuildSystem§ Abhängigkeits-ManagementTool§ Dokumenta<onstool§ Qualitätsinforma<on§ RichtlinienfürdieBestPrac<cesEntwicklung
HTWGKonstanz MarkusGerhart 11
ProjektErstellung• VonderKommandozeilemvn archetype:generate-DgroupId = com.mycompany.app -DartifactId = my-app -DarchetypeArtifactId = maven-archetype-quickstart -DinteractiveMode = false
HTWGKonstanz MarkusGerhart 12
DiePom.xml<project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion> 4.0.0 </modelVersion><groupId> com.mycompany.app </groupId><artifactId> my-app </artifactId><packaging> jar </packaging><version> 1.0-SNAPSHOT </version><name> Maven Quick Start Archetype </name>
<url> http://maven.apache.org </url><dependencies>
<dependency><groupId> junit </groupId><artifactId> junit </artifactId><version> 4.8.2 </version><scope> test </scope>
</dependency></dependencies>
</project>HTWGKonstanz MarkusGerhart 13
StandardOrdnerStruktur
HTWGKonstanz MarkusGerhart 14
• EclipseJavaProjectsrc->NormalJavaclassestest->JUnitTestclasses
• Maven
Ziele
HTWGKonstanz MarkusGerhart 15
• derStandard-LebenszyklushatdiefolgendenAupauphasen§ validate–ValidiertdasProjekt§ compile–KompiliertdenQuellcodedesProjekts§ test–TestetdenkompiliertenQuellcode§ package–PacktdenQuellcodeineineJarDatei§ integra<on-test–FührtdasDeploymentdurchundtestetdieses§ verify–FührtTestsfürdieVerifika<ondesPackagesdurch§ install–InsalliertdasPackageindaslokaleRepository§ deploy–KopiertdasPackageaufdasremoteRepository
• Beispielemvn compile; mvn test; mvn deploy
EineFunk<onsfähigePom.xmlDatei
HTWGKonstanz MarkusGerhart 16
<projectxmlns="hfp://maven.apache.org/POM/4.0.0"xmlns:xsi="hfp://www.w3.org/2001/XMLSchema-instance"xsi:schemaLoca<on="hfp://maven.apache.org/POM/4.0.0hfp://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>de.htwg.se</groupId><ar<factId>Uno2</ar<factId><version>0.0.1-SNAPSHOT</version><build><sourceDirectory>src</sourceDirectory><testSourceDirectory>test</testSourceDirectory><plugins><plugin><ar<factId>maven-compiler-plugin</ar<factId><version>3.1</version><configura<on><source/><target/></configura<on></plugin></plugins></build><dependencies><dependency><groupId>junit</groupId><ar<factId>junit</ar<factId><version>4.10</version><scope>test</scope></dependency></dependencies></project>
WasistGradle?
HTWGKonstanz MarkusGerhart 17
• Build-Management&Automa<sierungstool• Groovy-basierendeProjekt-Konfigura<on• ErsterRelease2009• DistributedunterderApacheLizenz2.0• OffiziellesBuildSystemfürAndroid
WarumGradle?
HTWGKonstanz MarkusGerhart 18
• Deklara<vebuildsundbuilds-by-conven<on
• GroovyalsBasisProgrammierspracheerlaubtdieimpera<veProgrammierung
• LeichteIntegra<onundMigra<on§ Out-of-the-box-supportfürAnt,MavenandIvy
• SchnelleraufgrundinkrementellerBuilds• SchlankerundbesserLesbar: task helloWorld << { println "Hello, world!" }
Impera<ve(Befehle)(Lösungsorien<ert)
Ant
Declara<ve(Funk<onal)(Zielorien<ert)
MavenGradle
SchlankesteGradlevs.MavenDatei
HTWGKonstanz MarkusGerhart 19
<project> <modelVersion>4.0.0</modelVersion> <groupId>de.htwg.examples</groupId> <artifactId>example</artifactId> <version>0.1-SNAPSHOT</version>
</project>
apply plugin: 'java'
Maven(pom.xml)
Gradle(build.gradle)
BuildPhasen
HTWGKonstanz MarkusGerhart 20
• Ini<alisierung§ UnterstütztEinzelundMul<Projektbuilds§ ErzeugtProjekt-Instanzenfüralle,dieandemBuildbeteiligtsind
• Konfigura<on§ ErzeugtDAG(DependencyAcyclicGraph)fürAufgaben
• Ausführung
DependencyManagement
HTWGKonstanz MarkusGerhart 21
• Vollkompa<belmitMavenundIvyundderenRepositories• IntegrierteKonfliktlösung• Ausschluss• Transi<vitätop<onal
dependencies { compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
}
dependencies { compile 'org.hibernate:hibernate-core:3.6.7.Final'
}
build.gradle
shortway
DependencyManagement
HTWGKonstanz MarkusGerhart 22
• UnterschiedlicheKonfigura<onen§ compileo ErforderlichfürdenKompilierungsvorgang
§ testCompileo ErforderlichfürdieKompilierungvonTests
§ run<meo ErforderlichfürdieKlassenzurLaufzeit§ testRun<meo Erforderlich,umdieTestsauszuführen
DependencyManagement
HTWGKonstanz MarkusGerhart 23
if (environment != 'production') { println 'Production build!'
providedCompile 'javax.servlet:servlet-api:3.+'
compile('org.springframework.boot:spring-boot-starter-web: ${springBootVersion}') {
exclude module: 'spring-boot-starter-tomcat' exclude module: 'spring-boot-starter-jetty' } } else { if (embeddedserver == 'jetty') { compile('org.springframework.boot:spring-boot-starter-web') {
exclude module: 'spring-boot-starter-tomcat' } compile('org.springframework.boot:spring-boot-starter-jetty') } else { compile('org.springframework.boot:spring-boot-starter-web:
${springBootVersion}') }
testCompile 'junit:junit:4.12' }
FortgeschrifeneFeatures
HTWGKonstanz MarkusGerhart 24
• Groovy• Plugins• Tasks• GradleWrapper• AndroidExample
GradleistGroovy,GroovyistJava
HTWGKonstanz MarkusGerhart 25
import java.io.File; … String parentDir = new File("test.txt")
.getAbsoluteFile() .getParentPath();
def parentDir = new File("test.txt") .absoluteFile .parentPath
parentDir = file("test.txt") .absoluteFile .parentPath
Java
Groovy
Gradle
Plugins
HTWGKonstanz MarkusGerhart 26
• GradleselbstistsehrkleinundbietetnurwenigeFunk<onen
• HinzufügenvonAufgabenund/oderUnterstützungfürSprachenundPlaxormen
• ErweiterbardurchPlugins,wiez.B.§ Java§ Android§ Scala§ IDEA(IntelliJ)§ NodeJS(‘com.moowork.node’)§ C++§ OtherlocalGradlescripts§ Seehfp://plugin.gradle.orgformore
apply plugin: 'java' apply plugin: 'com.moowork.node' apply from: 'other-script.gradle'
Tasks
HTWGKonstanz MarkusGerhart 28
• SindEinzelneAtomareAufgaben• Taskssindverfügbarausdembuilt-inverhalten,angewendetenpluginsundderbuildSpezifika<on
• KönnenAbhängigkeitenzuanderenTaskshaben§ Gradleorganisiertdieablaufreihenfolgeselbst
• Taskswerdenerweitertnichtüberschrieben§ Benö<gt'overwrite:true‘indertaskDeklara<on
• StandardTasks§ HelperTaskso taskso dependencieso projectso help§ Plugin'java'o buildo cleano jaro javadoc§ Plugin'applica<on'o installAppo run
Tasks–Defini<onvonTasks
HTWGKonstanz MarkusGerhart 29
task hello hello << {
print 'hello, world' }
task(hello) << { println 'hello, world'
}
task(copy, type: Copy) { from(file('srcDir')) into(buildDir) include('**/*.txt', '**/*.xml', '**/*.properties')
}
Copy myCopy = task(myCopy, type: Copy) myCopy.from 'resources' myCopy.into 'target' myCopy.include('**/*.txt', '**/*.xml', '**/*.properties')
equivalentresult
Tasks–doFirst&doLast
HTWGKonstanz MarkusGerhart 30
• doLastistequivalentzu<<
task hello << { print "world" } hello.doLast { println "!!" } hello.doFirst { print "Hello, " }
Tasks–dependsOn
HTWGKonstanz MarkusGerhart 31
• GradleorganisiertdieAblaufreihenfolgealsGraph
task compileTestClasses << { println "First compiling test classes"
} task createSchema << {
println "Next, creating schema, now ready for load testing" } task loadTestData(dependsOn: [compileTestClasses, createSchema]) << {
println "Finally, running the load tests." }
Tasks–Typen
HTWGKonstanz MarkusGerhart 32
task hello(type: HelloTask) task greeting(type: HelloTask) {
greeting = 'greetings from new Task' } class HelloTask extends DefaultTask {
def greeting = 'hello from HelloTask' @org.gradle.api.tasks.TaskAction def printGreeting() { println greeting
} }
GradleWrapper
HTWGKonstanz MarkusGerhart 33
• Leichtgewich<gesBatchscript(Windows)resp.Shellscript(Unix)
• Ausführbarmit'gradlew <task>'resp.'gradlew.bat <task>'
• EmpfohlenerWegfürProjekte§ SolltemitindasVCSeingechecktwerden
• LädtGradleherunter,installiertesundführtdieTasksausàGradlemussnichtvonHandinstalliertwerden!
task wrapper(type: Wrapper) { gradleVersion = '2.3'
}
build.gradle
AndroidBeispiel
HTWGKonstanz MarkusGerhart 34
apply plugin: 'com.android.application' android {
compileSdkVersion 21
buildToolsVersion '21.1'
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
versionCode 101
versionName '1.0.1'
}
buildTypes {
release {
minifyEnabled true
proguardFiles \ getDefaultProguardFile('proguard- android.txt'), \ 'proguard-rules.pro'
}
debug { debuggable true }
}
}
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) }
BuchEmpfehlungen
HTWGKonstanz MarkusGerhart 35
• hfps://gradle.org/documenta<on• hfps://gradle.org/books/§ E.g.:(freeeBooks!)
Zykluszeit
HTWGKonstanz MarkusGerhart 36
• "WielangewürdeesinIhrerOrganisa<ondauerneineCodeÄnderungzu„deployen“,dienureineeinzigeZeileCodebeinhaltet?Wirddiesaufeinewiederholbare,zuverlässigeArtundWeisegemacht?“-MaryPoppendieck
HTWGKonstanz MarkusGerhart 37
Developmentprocess
SourcecodeManagement
AutomatedBuild
QualityFeedback
SchrifezumCD
HTWGKonstanz MarkusGerhart 39
AgileDevelopment
AutomatedTes<ng
Configura<onManagement
Con<nousIntegra<on
DeploymentAutoma<on
DeploymentPipeline
Con<nousDeployment
SpezifischeWerkzeuge
HTWGKonstanz MarkusGerhart 40
• Selbstop<mierendeProzesse§ Agile(Scrum)
• Versionsverwaltung§ git
• DependencyManagement§ Maven,sbt§ Ar<factory
• Con<nousIntegra<on§ Jenkins
• BuildAutoma<sierung§ Ant,Maven,sbt,Gradle