Upload
wo-community
View
483
Download
2
Tags:
Embed Size (px)
Citation preview
Build & DeploymentPascal Robert Druide informatique
Git
Git hooks
• Stored in .git/hooks
• Hooks can be anything runnable
• The useful ones: post-commit and post-receive
• post-receive will receive branch reference
Git and remote
• Push changes to each deployment server
• Have the post-receive script on each server
• … or use branches and central Git repo
post-receive examples#!/bin/bash!while read oldrev newrev refdo if [[ $newrev == "0000000000000000000000000000000000000000" ]]; then exit 0 fi! branch=`echo $ref | cut -d/ -f3` umask 0022! if [ ! -d /tmp/SimpleBlog ]; then git clone /Users/probert/SimpleBlog.git /tmp/SimpleBlog fi! if [ $branch == "dev" ]; then ant -lib /opt/woproject.jar install fifi
Submodules
• You could use Git submodules to build everything at the same time
Puppet
Puppet ?
• Not about politicians, consumers or Metallica
• Configuration management tool
• Rapid deployment
• Central point
• Changes history
• Standalone or client/server
Puppet
• Puppet uses recipes (modules)
• Ruby-like declarative language
• Works on UNIX/Linux, OS X and Windows
• You can install packages, create user account, start services, etc.
Sample configuration
manifests/site.pp:! node server.wocommunity.org { include wodeploy }!modules/wodeploy/manifests/init.pp:! package { ‘apache’: name => ‘httpd’, ensure => present }! service { ‘httpd’: name => ‘httpd’, ensure => running, require => Package[‘apache’] }! package { ‘wotaskd’: name => ‘wotaskd’, ensure => present }! user { ‘appserver’: name => ‘appserver’ ensure => present }
Puppet tips
• Use Git to store the configuration
• Be modular
• Use it!
Native Packages
Native packages
• Deploy with natives packages!
• Can mix it with Puppet or Chef
• Deploy from a central repository or manually
Ant RPM task
• Build a RPM package for RedHat-based Linux
• Still need to write a SPEC file
• Use it only if you really like Ant
fpm
• Ruby gem to create packages
• .pkg/.deb/.rpm/Puppet!
• Much more flexible than the Ant task
fpm in two steps
• gem install fpm
• fpm --prefix /WOApps -a noarch —rpm-user _appserver --rpm-os linux -t rpm -s dir -n SimpleBlog -v 1.0 SimpleBlog.woa
Activating the app
• Bundle a shell script inside the package
• Use Puppet to install the package + restart the app
Puppet + RPM
package { ‘SimpleBlog’: source => ‘http://myserver/storage/SimpleBlog-1.0-1.rpm', name => ‘SimpleBlog’, ensure => ‘installed’}!file { ‘wodeploy.py’: { source => ‘puppet:///modules/wotools/scripts/wodeploy.py', path => ‘/opt/bin/wodeploy.py’}!exec { ‘run-wodeploy’ command => ‘/opt/bin/wodeploy.py SimpleBlog’}
wodeploy.py
#!/usr/bin/python!import json, urllib2, sys!base_url = "http://mywotaskd:1085/cgi-bin/WebObjects/JavaMonitor.woa/ra/mApplications"app_name = sys.argv[1]!stop_instance = Trueresponse = json.load(urllib2.urlopen(base_url + ".json?type=app&name=" + app_name))if len(response) == 0: query = { 'id' : app_name, 'type' : 'MApplication', 'name' : app_name, 'unixOutputPath' : '/opt/Local/Library/WebObjects/Logs', 'unixPath' : '/opt/Local/Library/WebObjects/Applications/' + app_name + '.woa/' + app_name } query_as_json = json.dumps(query) request = urllib2.Request(base_url + ".json", query_as_json, {'Content-Type': 'application/json'}) response = urllib2.urlopen(request) stop_instance = False if stop_instance: urllib2.urlopen(base_url + "/" + app_name + "/stop")!urllib2.urlopen(base_url + "/" + app_name + "/start")
Large distribution
• Use a central repository
• Use Puppet
• … or both
Maven
Q&A