Continuous Integration 1 0
-
Upload
panche-isajeski -
Category
Documents
-
view
214 -
download
0
Transcript of Continuous Integration 1 0
-
7/29/2019 Continuous Integration 1 0
1/6
DZone, Inc. | www.dzone.com
By Paul M. Duva
C
ontinuousIntegration:Patt
ernsand
Anti-patterns
www.dzone.com
GetMoreRefcardz!Vis
itrefcardz.com
84
Continuous IntegrationPatterns and Anti-Pattern
CONTENTS INCLUDE:
n About Continuous Integrationn Build Sotware at Every Changen Patterns and Anti-patternsnVersion Controln Build Managementn Build Practices and more...
AldonChange. Collaborate. Comp
ABOUT CONTINUOUS INTEGRATION
Continuous Integration (CI) is the process o building sotware
with every change committed to a projects version control
repository.
CI can be explained via patterns (i.e., a solution to a problem
in a particular context) and anti-patterns (i.e., ineective
approaches sometimes used to x the particular problem)
associated with the process. Anti-patterns are solutions that
appear to be benecial, but, in the end, they tend to produce
adverse eects. They are not necessarily bad practices, but canproduce unintended results when compared to implementing
the pattern.
Continuous Integration
While the conventional use o the term Continuous Integration
generally reers to the build and test cycle, this Recard
expands on the notion o CI to include concepts such as
Deployment and Provisioning. The end result is learning
whether you are capable o delivering working sotware with
every source change.
Pattern Run a sotware build with every change applied to the Repository
Anti-Patterns scheduled builds, nightly builds, building periodically, building exclusively on
developers machines, not building at all
BUILD SOFTWARE AT EVERY CHANGE
The ollowing table contains a summary o all the patterns
covered in this Recard:
A CI scenario starts with the developer committing source
code to the repository. There are our eatures required or CI.
A connection to a version control repository
An automated build script
Some sort of feedback mechanism (such as e-mail)
A process for integrating the source code changes
(manual or CI server)
Pattern Description
Private Workspace Develop sotware in a Private Workspace to isolate changes
Repository Commit all les to a version-control repository
Mainline Develop on a mainline to minimize merging and to manageactive code lines
Codeline Policy Developing sotware within a system that utilizes multiplecodelines
Task-Level Commit Organize source code changes by task-oriented units o workand submit changes as a Task Level Commit
Label Build Label the build with unique name
Automated Build Automate all activities to build sotware rom source withoutmanual conguration
Minimal Dependencies Reduce pre-installed tool dependencies to the bare minimum
Binary Integrity For each tagged deployment, use the same deploymentpackage (e.g. WAR or EAR) in each target environment
Dependency Management Centralize all dependent libraries
Template Verifer Create a single template le that all target environmentproperties are based on
Staged Builds Run remote builds into dierent target environments
Private Build Perorm a Private Build beore committing changes to theRepository
Integration Build Perorm an Integration Build periodically, continually, etc.
Continuous Feedback Send automated eedback rom CI server to development tea
Expeditious Fixes Fix build errors as soon as they occur
Developer Documentation Generate developer documentation with builds based onchecked-in source code
Independent Build Separate build scripts rom the IDE
Single Command Ensure all build and deployment processes can be run througa single command
Dedicated Machine Run builds on a separate dedicated machine
Externalize Confguration Externalize all variable values rom the application conguratiointo build-time properties
Tokenize Confguration Token values are entered into conguration les and thenreplaced during the Scripted Deployment
Protected Confguration Files are shared by authorized team members only
brought to you by...
http://www.dzone.com/http://www.dzone.com/http://www.dzone.com/http://www.dzone.com/http://www.dzone.com/http://www.dzone.com/http://www.dzone.com/http://www.dzone.com/http://www.dzone.com/http://www.dzone.com/http://www.dzone.com/http://www.dzone.com/http://www.dzone.com/http://www.dzone.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.aldon.com/http://www.aldon.com/http://www.aldon.com/http://info.aldon.com/l/904/2010-01-14/G8A3Jhttp://www.aldon.com/http://www.refcardz.com/http://www.refcardz.com/http://www.dzone.com/http://www.dzone.com/http://www.refcardz.com/ -
7/29/2019 Continuous Integration 1 0
2/6DZone, Inc. | www.dzone.com
2
Continuous Integration: Patterns and Anti-patterns
PATTERNS AND ANTI-PATTERNS
Binary Integrity
Pattern For each tagged deployment, the same deployment package (e.g. WAR orEAR) is used in each target environment.
Anti-Patterns Separate compilation or each target environment on the same tag.
Version ControlThe patterns in this section were originally described in the
book Sotware Conguration Management Patterns (Addison-
Wesley, 2003, Berczuk and Appleton), except or Label Build:
Pattern Description
Private Workspace Prevent integration issues rom distracting you, and rom your changescausing others problems by developing in a Private Workspace.
Repository All les are committed to version-control repository in the deploymentcontext, all o the conguration les and tools.
Mainline Minimize merging and keep the number o active code linesmanageable by developing on a Mainline
Codeline Policy The policy should be brie, and should spell out the rules o the roador the codeline
Task-Level Commit
Pattern Organize source code changes by task-oriented units o work and submitchanges as a Task Level Commit. (rom SCM Patterns)
Anti-Patterns Keeping changes local to developer or several days and stacking up changesuntil committing all changes. This oten causes build ailures or requirescomplex troubleshooting.
Label Build
Pattern Label the build with unique name so that you can run the same build at
another time.
Anti-Patterns Not labeling builds, Using revisions or branches as labels.
Build ManagementAutomated Build
Pattern Automate all activities to build sotware rom source without manualconguration. Create build scripts that are decoupled rom IDEs. Later, thesebuild scripts will be executed by a CI system so that sotware is built at everychange.
Anti-Patterns Continually repeating the same processes with manual builds or partiallyautomated builds requiring numerous manual conguration activities.
Minimal Dependencies
Pattern Reduce pre-installed tool dependencies to the bare minimum. Eliminaterequired environment variables rom the Automated Build and ScriptedDeployment.
Anti-Patterns Requiring developer to dene and congure environment variables. Requiredeveloper to install numerous tools in order or the build/deployment to work.
Scripted Database Script all database actions
Database Sandbox Create a lightweight version o your database
Database Upgrade Use scripts and database to apply incremental changes in eachtarget environment
Automated Tests Write an automated test or each unique path
Categorize Tests Categorize tests by type
Continuous Inspection Run automated code analysis to nd common problems
Build Threshold Use thresholds to notiy team members o code aberrations
Deployment Test Script sel-testing capabilities into Scripted Deployments
Scripted Deployment All deployment processes are written in a script
Headless Execution Securely interace with multiple machines without typing acommand
Unifed Deployment Create a single deployment script capable o running ondierent platorms and target environments
Disposable Container Automate the installation and conguration o Web anddatabase containers
Remote Deployment Use a centralized machine or cluster to deploy sotware tomultiple target environments
Environment Rollback Provide an automated Single Command rollback o changesater an unsuccessul deployment
Continuous Deployment Deploy sotware with every change applied to the projectsversion control repository
Single-CommandProvisioningRun a single command to provision target environment
Decouple Installation Separate the conguration rom the installation
Dependency Management
Pattern Centralize all dependent libraries to reduce bloat, classpath problems, andrepetition o the same dependent libraries and transitive dependencies romproject to project.
Anti-Patterns Multiple copies o the same JAR dependencies in each and every project.Redening the same inormation or each project. Classpath hell!
Tools such as Ivy and Maven can be used or managing
dependencies.
AldonChange. Collaborate. Comply.
http://www.dzone.com/http://www.aldon.com/http://www.aldon.com/http://www.aldon.com/http://www.aldon.com/http://www.refcardz.com/http://www.dzone.com/ -
7/29/2019 Continuous Integration 1 0
3/6DZone, Inc. | www.dzone.com
3
Continuous Integration: Patterns and Anti-patterns
Single Command
Pattern Ensure all build and deployment processes can be run through a singlecommand. This makes it easier to use, reduces deployment complexitiesand ensures a Headless Execution o the deployment process. Deployers, orheadless processes, can type a single command to generate working sotware
or users.
Anti-Patterns Some deployment processes require people to enter multiple commandsand procedures such as copying les, modiying conguration les, restartinga server, setting passwords, and other repetitive, error-prone actions.
Single-command deployment execution using Ant:
ant-Dproperties.le=$USERHOME/projects/petstore/properties/dev-install.properties deploy:remote:install
Dedicated Machine
Pattern Run builds on a separate dedicated machine.
Anti-Patterns Existing environmental and conguration assumptions can lead to the but itworks on my machine problem.
When creating an integration build machine consider the
ollowing:
Build ConfgurationIndependent Build
Pattern Separate build scripts rom the IDE. Create build scripts that are decoupled
rom IDEs. Later, these build scripts will be executed by a CI system so thatsotware is built at every change.
Anti-Patterns Automated Build relies on IDE settings. Build cannot run rom thecommand line.
Consistent Directories
Pattern Create a simple, yet well-dened directory structure to optimize sotwarebuilds and increase cross-project knowledge transer.
Anti-Patterns Putting code, documentation and large les in the same parent directorystructure, leading to long-running builds.
Template Verifer
Pattern Create a single template le that all target environment properties are based on.
Anti-Patterns
Use manual verication, trial and error (when deployment ails, check the logs),or keeping les hidden on a machine.
Integration Build
Pattern Ensure that your code base always builds reliably by doing an IntegrationBuild periodically.
Anti-Patterns Works on My Machine (WOMM). Continuous Compilation.
Continuous Feedback
Pattern Sending automated eedback rom CI server to development team.
Anti-Patterns Minimal eedback, which prevents action rom occurring. Receiving spameedback, which causes people to ignore messages.
Examples Email, RSS, SMS, X10, Monitors, Web Notiers
Expeditious Fixes
Pattern Fix build errors as soon as they occur.
Anti-Patterns Build entropy - problems stack up causing more complex troubleshootingand some claim that CI is the problem.
Fix broken buildsimmediately
Although it is the teams responsibility, the developer who recentlycommitted code must be involved in xing the ailed build
Run privatebuilds
To prevent Integration ailures, get changes rom other developers bygetting the latest changes rom the repository and run a ull integrationbuild locally, known as a Private Build
Avoid gettingbroken code
I the build has ailed, you will losetime i you get coderom the Repository.Wait or the change or help the developer(s) x the build ailure and thenget the latest code
Developer Documentation
Pattern Generate developer documentation with builds (at appropriate intervals)based on checked-in source code.
Anti-Patterns Developer documentation is manually generated, periodically. This is botha burdensome process and one in which the inormation becomes uselessquickly because it does not refect the checked-in source code.
Automating your documentations generation will help you
keep it up to date and thereby make it more useul or your
sotwares users.
SchemaSpy
Note: Private Build and Integration Build are also rom Berczuk and Appletons bookSotware Conguration Management Patterns (Addison-Wesley, 2003, Berczuk and Appleton)Staged Builds
Pattern Using the Remote Deployment pattern, run remote builds into dierent targetenvironments
Anti-Patterns Deploying directly to production.
Build PracticesPrivate Build
Pattern Veriy your changes will not break the Integration Build by perorming aPrivate Build prior to committing changes to the Repository.
Anti-Patterns Checking in changes to version-control repository without running a build ondevelopers workstation.
AldonChange. Collaborate. Comply.
http://www.dzone.com/http://www.aldon.com/http://www.aldon.com/http://www.aldon.com/http://www.aldon.com/http://www.refcardz.com/http://www.dzone.com/ -
7/29/2019 Continuous Integration 1 0
4/6DZone, Inc. | www.dzone.com
4
Continuous Integration: Patterns and Anti-patterns
Recommended systemresources
Increase hardware resources or an integration build machinerather than wasting time waiting or slow builds.
All sotware assets in theversion control repository
See the Repository pattern.
Clean environment CI process removes any code dependencies on the integrationenvironment. Automated build must set test data and any otherconguration elements to a known state.
Externalize Confguration
Pattern All variable values are externalized rom the application conguration intobuild-time properties.
Anti-Patterns Some hardcode these values, manually, or each o the target environments,or they might use GUI tools to do the same.
Example properties that are external to application-specic les:
authentication.type=dbapplication.url=http://${tomcat.server.hostname}:${tomcat.server.port}/brewery-webappdatabase.type=mysqldatabase.server=localhostdatabase.port=3306database.name=mydbdatabase.user=myuser!database.password=mypa$$!database.url=jdbc:mysql://${database.server}:${database.port}/${database.name}tomcat.server.hostname=localhosttomcat.server.name=defaulttomcat.web.password=pa$$123!
tomcat.cobraorb.port=12748
Tokenize Confguration
Pattern Token values are entered into conguration les and then replaced duringthe Scripted Deployment based on Externalized Conguration propertieschecked into Repository.
Anti-Patterns Target-specic data is entered into conguration les in each environment.
Protected Confguration
Pattern Using the repository, les are shared by authorized team members only.
Anti-Patterns Files are managed on team members machines or stored on shared drivesaccessible by authorized team members.
DatabaseScripted Database
Pattern Script all database actions.
Anti-Patterns Late and manual migration o a database in the development cycle is painuland expensive.
Script all DDL and DML so that database changes can be run
rom the command line. Use a version-control repository to
manage all database-related changes. (i.e. reer to the pattern)
Database Sandbox
Pattern * Create a lightweight version o your database (only enough records to testunctionality)
* Use this lightweight DML to populate local database sandboxes or eachdeveloper
* Use this data in development environments to expedite test execution
Anti-Patterns Shared development database.
Give each developer, tester or test user a separate database
instance. Install a lightweight database server in each users
test environment (e.g., MySQL, Personal Oracle), which can
be installed on the users private workstation, on a shared test
server, or on a dedicated virtual server running on a shared
server.
Database Upgrade
Pattern Use scripts and database to apply incremental changes in each targetenvironment, which provides a centrally managed and scripted process toapplying incremental changes to the database.
Anti-Patterns Manually applying database and data changes in each target environment.
Running a custom SQL le rom a LiquiBase change set:
build.xml
db.change.xml
Testing and Code QualityAutomated Tests
Pattern Write an automated test or each unique path.
Anti-Patterns Not running tests, no regression tests, manual testing
Examples A Simple Unit Testpublic void setUp() {beerService = new BeerDaoStub();}
public void testUnitGetBeer() {
Collection beers = beerService.ndAll();assertTrue(beers != null && beers.size() > 0);}
Running a Unit Test in Ant
Categorize Tests
Pattern Categorize tests by type and your builds become more agile, tests can be run
more requently, and tests no longer take hours to complete.
Anti-Patterns Tests take hours to run, leading to excessive wait times and increased expense.
Continuous Inspection
Pattern Run automated code analysis to nd common problems. Have these tools runas part o continuous integration or periodic builds.
Anti-Patterns Long, manual code reviews or no code reviews.
Examples:
CheckStyle
AldonChange. Collaborate. Comply.
http://www.dzone.com/http://www.aldon.com/http://www.aldon.com/http://www.aldon.com/http://www.aldon.com/http://www.refcardz.com/http://www.dzone.com/ -
7/29/2019 Continuous Integration 1 0
5/6DZone, Inc. | www.dzone.com
5
Continuous Integration: Patterns and Anti-patterns
Unifed Deployment
Pattern Create a single deployment script capable o running on dierent platormsand target environments.
Anti-Patterns Some may use a dierent deployment script or each target environment oreven or a specic machine.
Disposable Container
Pattern Automate the installation and conguration o Web and database containersby decoupling installation and conguration.
Anti-Patterns Manually install and congure containers into each target environment.
Remote Deployment
Pattern Use a centralized machine or cluster to deploy sotware to multiple targetenvironments.
Anti-Patterns Manually applying deployments locally in each target environment.
Build Threshold
Pattern Notiy team members o code aberrations such as low code coverage orhigh cyclomatic complexity. Fail a build when a project rule is violated. Usecontinuous eedback mechanisms to notiy team members.
Anti-Patterns Manual code reviews. Learning o code quality issues later in the developmentcycle.
Deployment Test
Pattern Script sel-testing capabilities into Scripted Deployments.
Anti-Patterns Deployments are veried by running through manual unctional tests that donot ocus on deployment-specic aspects. No deployment tests are run.
The table below describes examples o the types o test that
might be run as part o a Deployment Test smoke suite.
Example Test Type Description
Database Write an automated unctional test that inserts data into a database.Veriy the data was entered in the database.
Simple Mail TranserProtocol (SMTP)
Write an automated unctional test to send an e-mail message romthe application.
Web service Use a tool like SoapAPI to submit a Web service and veriy the output.
Web container(s) Veriy all container services are operating correctly.
Lightweight DirectoryAccess Protocol (LDAP)
Using the application, authenticate via LDAP.
Logging Write a test that writes a log using the applications loggingmechanism.
Deployment
Scripted DeploymentPattern All deployment processes are written in a script.
Anti-Patterns Manually installing and conguring a Web container. Use o the GUI-basedadministration tool provided by the container to modiy the container basedon a specic environment.
Headless Execution
Pattern Securely interace with multiple machines without typing a command.
Anti-Patterns People manually access machines by logging into each o the machines asdierent users; then they copy les, congure values, and so on.
AldonChange. Collaborate. Comply.
http://www.dzone.com/http://www.aldon.com/http://www.aldon.com/http://www.aldon.com/http://www.aldon.com/http://www.refcardz.com/http://www.dzone.com/ -
7/29/2019 Continuous Integration 1 0
6/6
http://www.aldon.com/http://books.dzone.com/books/continuous-integrationhttp://www.ibm.com/developerworks/views/java/libraryview.jsp?search_by=automation+peoplehttp://www.amazone.com/gp/product0321336380/?tag=integratecom-20http://www.refcardz.com/mailto:[email protected]:[email protected]://www.dzone.com/http://www.dzone.com/http://refcardz.com/