22
Build & Deployment Pascal Robert Druide informatique

Build and deployment

Embed Size (px)

Citation preview

Page 1: Build and deployment

Build & DeploymentPascal Robert Druide informatique

Page 2: Build and deployment

Git

Page 3: Build and deployment

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

Page 4: Build and deployment

Git and remote

• Push changes to each deployment server

• Have the post-receive script on each server

• … or use branches and central Git repo

Page 5: Build and deployment

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

Page 6: Build and deployment

Submodules

• You could use Git submodules to build everything at the same time

Page 7: Build and deployment

Puppet

Page 8: Build and deployment

Puppet ?

• Not about politicians, consumers or Metallica

• Configuration management tool

• Rapid deployment

• Central point

• Changes history

• Standalone or client/server

Page 9: Build and deployment

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.

Page 10: Build and deployment

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 }

Page 11: Build and deployment

Puppet tips

• Use Git to store the configuration

• Be modular

• Use it!

Page 12: Build and deployment

Native Packages

Page 13: Build and deployment

Native packages

• Deploy with natives packages!

• Can mix it with Puppet or Chef

• Deploy from a central repository or manually

Page 14: Build and deployment

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

Page 15: Build and deployment

fpm

• Ruby gem to create packages

• .pkg/.deb/.rpm/Puppet!

• Much more flexible than the Ant task

Page 16: Build and deployment

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

Page 17: Build and deployment

Activating the app

• Bundle a shell script inside the package

• Use Puppet to install the package + restart the app

Page 18: Build and deployment

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’}

Page 19: Build and deployment

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")

Page 20: Build and deployment

Large distribution

• Use a central repository

• Use Puppet

• … or both

Page 21: Build and deployment

Maven

Page 22: Build and deployment

Q&A