miggle - DrupalCamp Brighton

Transcription

miggle - DrupalCamp Brighton
jenkins, drupal & testing
automating every phing!
miggle
about me
>
>
>
>
>
Drupal dev for 6+ years
PHP dev for 10+ years
Husband
Cyclist
Frustrated rockstar…
@8ballmedia
miggle
miggle
miggle
aims
>
>
>
>
>
Encourage best practices
Ensure quality at scale
Release more frequently and reliably
Develop more robust solutions
Deploy with confidence
miggle
improving quality control
>
>
>
Write better code
• Adhering to Drupal coding standards!
• Evaluate code complexity
• Detect messy copy/paste code
Validate that our code achieves objectives
• Simpletests
• Behat tests
Automate labour intensive tasks
miggle
my requirements
>
>
>
>
Create something reusable & future proof
Create a starting point for future projects
Use open source
Report failures
• email accountable team members!
miggle
Intercept obvious issues
* not obvious if you have devel installed of course ;)
miggle
…before they reach the
stakeholders!
miggle
create a development
pipeline…
CI
>
STG
LIVE
Validate code ahead of any release to a client env
miggle
continuously integrating?
miggle
miggle
barrier to entry
miggle
buzz words & acronyms!
>
>
>
>
>
>
Devops - a state of mind man!
• bridging the gap between sys/dev
BDD - Behaviour Driven Development
CDD - Code Driven Development
TDD - Test Driven Development
CI - Continous Integration
CD - Compact Disc Continuous Delivery
miggle
hi, I’m jenkins
>
>
>
>
>
>
Continuous Integration application
Automate tasks
Huge library of plugins
Trigger tasks from other jobs or Github for example
Report Success/failures
Communicate with other servers
miggle
community rules!
>
>
http://jenkins-php.org/
http://reload.github.io/jenkins-drupal-template
miggle
creating your own ci setup
>
>
>
>
Tools
Requirements
Guidelines
Screencast Walkthrough
miggle
tool box
>
>
>
>
>
>
>
Ubuntu - Digital Ocean 1GB+
Jenkins - CI server with numerous plugins
Github - good compatibility w/ Jenkins
Composer - dependency manager
Phing - Automation using XML files and PHP
Automated testing - Simpletest, Behat
Drupal w/ Sqlite
miggle
evaluating code quality
>
>
>
>
Code analysis w/ Coder
Duplicate code detection
PHP Mess detection, copy/paste detection
JS & CSS linting
miggle
why composer
>
>
>
>
>
PHP package manager
Alternative to PEAR
Allows for dependencies per project
Requires additional PATH config in Jenkins
Simpler transition to hosted services
miggle
composer.json
{
"repositories": [
{
"type": "package",
"package": {
"name": "drupal/phing-drush-task",
"version": "1.0",
"source": {
"url": "http://git.drupal.org/project/phingdrushtask.git",
"type": "git",
"reference": "7.x-1.0"
},
"autoload": {
"classmap": [
"DrushTask.php"
]
},
"include-path": [
"."
]
}
}
],
"require": {
"phing/phing": "2.*",
"drupal/phing-drush-task": "1.0",
"drupal/drupal-extension": "1.0.*@stable",
"drush/drush": "6.2.*",
"squizlabs/php_codesniffer": "1.5.*",
"phpmd/phpmd": "1.5.*",
"sebastian/phpcpd": "*",
"phploc/phploc": "*",
"drupal/coder": "7.2.*"
},
"config": {
"bin-dir": "bin/"
},
"minimum-stability": "beta"
}
miggle
phing
>
>
>
>
>
Build automation tool
Based on Apache ANT
Good integration w/ Jenkins
XML & PHP based
Drush integration available
<?xml version="1.0" encoding="UTF-8"?>
<project name="phing-drupal" default="build">
<!-- ## Main targets —>
<target name="build" depends="init,
clean,
verify,
analyze" />
</project>
<drush command="site-install" assume="yes"">
<option name="locale">uk</option>
<option name="site-name" value="${sitename}" />
<param>expert</param>
</drush>
>
https://www.drupal.org/project/phingdrushtask
miggle
build.default.properties
>
>
>
Specify project properties
Can be overridden in Jenkins
Multiple properties files
• useful for different envs.
# The directory containing the modules and themes
for the project relative to the drupal root
directory.
project.code.dir = sites/all
# A common prefix for modules to evaluate
project.code.prefix = master
# The names of other modules and themes to evaluate
project.code.custom = master_dependency
<drush command="site-install" assume="yes">
<option name="db-url">${drupal.db.url}</option>
<param>${drupal.profile}</param>
</drush>
miggle
follow the rules
>
>
>
>
Standardisation is key
Naming conventions from the outset
Standard directory structures
Prefixing
build.xml
build.default.properties
build.components/
build.components/build.drupal_site_install.xml
composer.json
docroot/
docroot/sites/all/modules/features/my_feature/
docroot/sites/all/modules/features/my_feature2/
docroot/sites/all/modules/custom/my_helper/
miggle
let’s get going…
https://github.com/miggle/Migl-Phing-Drupal
disclaimer: work in progress!
miggle
miggle
what just happened…
>
>
>
Installed and started Jenkins
Installed required server packages
Installed composer globally
miggle
miggle
miggle
miggle
…finalising
>
>
>
>
>
Configured Jenkins
Install Drupal-Jenkins template
Initial build
Configure Apache
Final build
miggle
review the results
>
>
>
>
Set the levels at which a build is marked:
• unstable
• broken
Email contributing developers a status update
• happens by default w/ github plugin
Advise developers of where code can be improved
Provide metrics on code
miggle
caveats
>
>
>
>
>
Additional overhead writing automated tests
• devs need to learn how to write tests
Tests need to be written correctly
• false positives are not useful!
Initial project setup overhead
• although could be automated
Tests take time to run…but
…automated on push so no need to wait!
miggle
hosted alternatives to
jenkins
>
>
>
Travis CI - free for open source
Circle CI, Magnum CI and more…
Benefits of hosted CI
• infrastructure managed elsewhere
• 100% self contained
miggle
thanks!
>
Huge thanks to these amazing people!!:
>
https://github.com/nlisgo
http://reload.github.io/jenkins-drupal-template/
https://github.com/omissis/drupal-ignite
https://github.com/lhridley/drupal7-jenkins-templates
>
>
>
miggle
let’s discuss…
>
http://tinyurl.com/mwjgomv
>
Twitter: @8ballmedia
Web: 8ballmedia.co.uk
D.O. 8ballsteve
LinkedIn: uk.linkedin.com/in/stevegushrichards
miggle
>
>
>