概要
jenkins-tomcat Cookbookの作成
詳細
jenkins-tomcat Cookbookを作成します。
仕様
基本的には下記記事の手動セットアップをChef + Vagrantに置き換えただけです。
jenkins-tomcatでTomcat+Jenkins環境を構築する
http://d.hatena.ne.jp/tbpg/20131105/1383666119
vagrant
Vagrantfile
# -*- mode: ruby -*- # vi: set ft=ruby : # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "ubuntu-12.04-x64" config.omnibus.chef_version = "11.6.0" config.vm.network :private_network, ip: "192.168.33.21" config.vm.provision :chef_solo do |chef| chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] chef.add_recipe "apt_get_update" chef.add_recipe "jenkins_tomcat" end end
cookbook(apt-get update)
site-cookbooks/apt_get_update/recipe/default.rb
log "start update apt-get" execute "update package index" do command "apt-get update" end.run_action(:run) log "end update apt-get"
cookbook(jenkins-tomcat)
site-cookbooks/jenkins_tomcat/files/default/jenkins.xml
※デフォルトでjenkins-tomcat packageが作成する内容に加えて
Contextタグにreloadable="true"属性を追加している。
これにより、warが最新化されると自動で再デプロイされる。
<!-- Context configuration file for the Jenkins Web App --> <Context path="/jenkins" docBase="/usr/share/jenkins/jenkins.war" debug="0" privileged="true" allowLinking="true" crossContext="true" reloadable="true"> <!-- make symlinks work in Tomcat --> <Resources className="org.apache.naming.resources.FileDirContext" allowLinking="true" /> <Environment name="JENKINS_HOME" type="java.lang.String" value="/var/lib/jenkins" override="true" /> </Context>
site-cookbooks/jenkins_tomcat/library/helper.rb
class Chef class Recipe def execute_with_log(name, &block) log "start #{name}" block.call log "end #{name}" end end end
site-cookbooks/jenkins_tomcat/recipe/default.rb
execute_with_log("install jenkins-tomcat") do package "jenkins-tomcat" do action :install end end execute_with_log("update jenkins.xml for tomcat(reloadable=true)") do cookbook_file "/var/lib/tomcat6/conf/Catalina/localhost/jenkins.xml" do source "jenkins.xml" owner "tomcat6" group "tomcat6" mode "0755" end end