Documente Academic
Documente Profesional
Documente Cultură
Continuous Integration:
About Continuous Integration
Get More Refcardz! Visit Refcardz.com
for CI: Template Verifier Create a single template file that all target
environment properties are based on.
7
D Z O NE, INC. | DZ O NE .C O M
CONTINUOUS INTEGR ATION:
2 PATTERNS AND ANTI-PATTERNS
Staged Deployments Run automated deployments into different Disposable Automate the installation and
target environments. Container configuration of Web and database
containers.
Pre-Merge Build Perform a Pre-merge Build before
committing changes to the Repository. Remote Deployment Use a centralized machine or cluster
to deploy software to multiple target
Integration Build Perform an Integration Build periodically, environments.
continually, etc.
Environment Provide an automated Single Command
Continuous Send automated feedback from CI server to Rollback rollback of changes after an unsuccessful
Feedback development team. deployment.
Expeditious Fixes Fix build errors as soon as they occur. Continuous Deploy software with every change applied
Deployment to the projects version control repository.
Developer Generate developer documentation with Single-Command Run a single command to provision target
Documentation builds based on checked-in source code. Provisioning environment.
Independent Build Separate build scripts from the IDE. Environment- Separate the environment-specific
independent configuration from the application.
Scripted Database Script all database actions. Repository All files are committed to version-control
repositoryin the deployment context, all
of the configuration files and tools.
Database Sandbox Create a lightweight version of your
Mainline Minimize merging and keep the number of
database.
active code lines manageable by developing
Database Upgrade Use scripts and the database to apply on a Mainline.
incremental changes in each target
Branching Policy The policy should be brief, and should spell
environment.
out the rules of the road for the branch.
Automated Tests Write an automated test for each
unique path.
TASK-LEVEL COMMIT
Categorize Tests Categorize tests by type. Pattern Organize source code changes by task-
oriented units of work and submit changes
Continuous Run automated code analysis to find as a Task Level Commit.
Inspection common problems. Anti-Patterns Keeping changes local to developer for
several days and stacking up changes
Build Quality Use thresholds to notify team members of
until committing all changes. This often
Threshold code aberrations.
causes build failures or requires complex
Automated Smoke Script self-testing capabilities into Scripted troubleshooting.
Test Deployments.
BUILD MANAGEMENT
AUTOMATED BUILD
Pattern Automate all activities to build software from
source without manual configuration. Create
build scripts that are decoupled from IDEs.
Later, these build scripts will be executed by a CI
system so that software is built at every change.
TEMPLATE VERIFIER
Pattern Create a single template file that all target
environment properties are based on.
EXPEDITIOUS FIXES
Pattern Fix build errors as soon as they occur.
SCHEMASPY
<property name="reports.dir" value="${basedir}" />
<java jar="schemaSpy_3.1.1.jar" output="${reports.dir}/
output.log" error="${reports.dir}/error.log" fork="true">
<arg line="-t mysql" />
<arg line="-host localhost" />
<arg line="-port 3306" />
<arg line="-db brewery" />
<arg line="-u root" />
<arg line="-p sa" />
<arg line="-cp mysql-connector-java-5.0.5-bin.jar" />
<arg line="-o ${reports.dir}" />
</java>
DEDICATED RESOURCES
Pattern Run builds on a separate dedicated machine or
cloud service.
Clean CI process removes any code dependencies Pattern Script all database actions.
environment on the integration environment. Automated
build must set test data and any other Anti-Patterns Migrating a database manually and late in
configuration elements to a known state. the development cycle (this is painful and
expensive).
EXTERNALIZE CONFIGURATION
Script all DDL and DML so that database changes can be run
Pattern Externalize all variable values from the
from the command line. Use a version-control repository to
application configuration into build-time
manage all database-related changes (i.e. refer to the pattern).
properties.
Anti-Patterns Hardcoding these values, manually, for each of <target name="db:create" depends="filterSqlFiles"
description="Create the database definition">
the target environments, or using GUI tools to
<sql driver="com.mysql.jdbc.Driver" url="jdbc:mysql://
do the same. localhost:3306/" userid="root" password="root"
classpathref="db.lib.path" src="${filtered.sql.dir}/
Example properties that are external to application-specific files: database-definition.sql" delimiter="//" />
</target>
authentication.type=db application.url=http://${tomcat.
server.hostname}:${tomcat.server. port}/brewery-webapp
database.type=mysql DATABASE SANDBOX
database.server=localhost
database.port=3306 Pattern * Create a lightweight version of your database
database.name=mydb (only enough records to test functionality)
database.user=myuser! * Use this lightweight DML to populate local
database.password=mypa$$! database.
url=jdbc:mysql://${database.server}:${database. database sandboxes for each developer
port}/${database.name} * Use this data in development environments to
tomcat.server.hostname=localhost expedite test execution
tomcat.server.name=default
tomcat.web.password=pa$$123! Anti-Patterns Sharing development database.
tomcat.cobraorb.port=12748
Give each developer, tester, or test user a separate database CONTINUOUS INSPECTION
instance. Install a lightweight database server in each users test Pattern Run automated code analysis to find common
environment (e.g. MySQL, Personal Oracle), which can be installed problems. Have these tools run as part of
on the users private workstation, on a shared test server, or on a continuous integration or periodic builds.
dedicated virtual server running on a shared server. Anti-Patterns Reviewing through long, manual code reviews,
DATABASE UPGRADE or not reviewing code at all.
SCRIPTED DEPLOYMENT
Pattern Write all deployment processes in a script.
<available file="@{tomcat.home}/server/@{tomcat.server.
name}/bin" property="tomcat.bin.exists" />
<if>
<isset property="tomcat.bin.exists" />
<then>
<echo message="Starting tomcat instance at @{tomcat. DISPOSABLE CONTAINER
home} with start_tomcat" />
<exec executable="@{tomcat.home}/server/@{tomcat.server. Pattern Automate the installation and configuration
name}/bin/start_tomcat" osfamily="unix" /> of Web and database containers by decoupling
</then> <else> installation and configuration.
<echo message="Starting tomcat instance at @{tomcat.
home} with startup.sh" /> Anti-Patterns Manually install and configure containers into
<exec osfamily="unix" executable="chmod" spawn="true">
each target environment.
<arg value="+x" />
<arg file="@{tomcat.home}/bin/startup.sh" />
<arg file="@{tomcat.home}/bin/shutdown.sh" />
</exec>
<exec executable="sh" osfamily="unix" dir="@{tomcat.
home}/bin" spawn="true">
<env key="NOPAUSE" value="true" />
<arg line="startup.sh" />
</exec>
<exec osfamily="windows" executable="cmd" dir="@{tomcat.
home}/ bin" spawn="true" >
<env key="NOPAUSE" value="true" /> <arg line="/c
startup.sh" />
</exec>
<sleep seconds="15" />
</else>
</if>
HEADLESS EXECUTION
Pattern Interface securely with multiple machines REMOTE DEPLOYMENT
without typing a command. Pattern Use a centralized machine or cluster to deploy
Anti-Patterns People manually access machines by logging software to multiple target environments.
into each of the machines as different users; Anti-Patterns Manually applying deployments locally in each
then they copy files, configure values, and so on. target environment.
Anti-Patterns Manually rolling back application and database Anti-Patterns Deploying periodically. Manual deployments.
changes. Manual configuration of target environments.
SINGLE-COMMAND PROVISIONING
Pattern Run a single command or click a button to
provision target environment.
ENVIRONMENT-INDEPENDENT BUILDS
Pattern Separate the environment-specific
configuration from the application deliverable.
Some of the concepts and material in this Refcard were adapted from:
Continuous Integration: Improving Software Quality and Reducing Risk, by Paul M. Duvall (Addison-Wesley, 2007) -
http://www.amazon.com/gp/product0321336380/?tag=integratecom-20
IBM developerWorks series Automation for the people, by Paul Duvall -
http://www.ibm.com/developerworks/views/java/libraryview.jsp?search_by=automation+people
CREDITS:
Editor: G. Ryan Spain | Designer: Yassee Mohebbi | Production: Chris Smith | Sponsor Relations: Brandon Rosser | Marketing: Chelsea Bosworth | Reviewer: Andrew Phillips
JOIN NOW
DZONE, INC.
150 PRESTON EXECUTIVE DR.
CARY, NC 27513
DZone communities deliver over 6 million pages each month to more than 3.3 million software 888.678.0399
developers, architects and decision makers. DZone offers something for everyone, including news, 919.678.0300
tutorials, cheat sheets, research guides, feature articles, source code and more.
REFCARDZ FEEDBACK WELCOME
"DZone is a developer's dream," says PC Magazine. refcardz@dzone.com
form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. | |DZ OSPONSORSHIP
Copyright 2015 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
D Z O NE, INC DZONE, NE.C O M OPPORTUNITIES
. in anyINC.
sales@dzone.com VERSION 1.0 $7.95