Skip to content

Commit

Permalink
[OC-4782] add dev recipe for easy hacking on Chef Server core
Browse files Browse the repository at this point in the history
This recipe will flip a Chef Server installation into development mode
for easy hacking on the underlying server components.

After this recipe has been applied git checkouts for all of Chef Server's
main software components will be available at `/opt/chef-server-dev/code`.
These component checkouts will also be fully symlinked into the underlying
Chef Server installation which means changes made to any component will
be reflected in the running Chef Server instance.
  • Loading branch information
schisamo committed Dec 4, 2012
1 parent a667dd3 commit 658d19d
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Berksfile
@@ -1,3 +1,7 @@
site :opscode site :opscode


metadata metadata

group :dev do
cookbook 'git'
end
101 changes: 101 additions & 0 deletions libraries/dev_helper.rb
@@ -0,0 +1,101 @@
#
# Copyright:: Copyright (c) 2012 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'mixlib/shellout'

module DevHelper

def self.omnibus_path
"/opt/chef-server/bin:/opt/chef-server/embedded/bin:/opt/chef-server/embedded/jre/bin"
end

def self.code_root
"/opt/chef-server-dev/code"
end

def self.backup_root
"/opt/chef-server-dev/backup"
end

def self.omnibus_service_root
"/opt/chef-server/embedded/service"
end

class Project

attr_accessor :name, :options
attr_accessor :checkout_path, :omnibus_path
attr_accessor :build_command, :preserved_paths

def initialize(name, options)
@name = name
@options = options
@checkout_path = File.join(DevHelper.code_root, name)
@omnibus_path = options[:omnibus_path] || File.join(DevHelper.omnibus_service_root, name)
@build_command = options[:build_command] || nil
@preserved_paths = options[:preserved_paths] || []
end

def build_and_load
shell_out("chef-server-ctl stop #{options[:service_name]}") if options.key?(:service_name)
build
link
configure
shell_out("chef-server-ctl start #{options[:service_name]}") if options.key?(:service_name)
end

private

def build
if build_command
shell_out(options[:build_command], :cwd => checkout_path)
end
end

def link
if File.exists?(omnibus_path) && !File.symlink?(omnibus_path)
release_path = options.key?(:release_path) ?
File.join(checkout_path, options[:release_path]) :
checkout_path
FileUtils.mv(omnibus_path, DevHelper.backup_root)
FileUtils.ln_s(release_path, omnibus_path)
end
end

def configure
preserved_paths.each do |path|
backup_path = File.join(DevHelper.backup_root, name, path)
dest_path = File.join(omnibus_path, path)
if File.exists?(backup_path)
FileUtils.mkdir_p(File.dirname(dest_path))
FileUtils.cp_r(backup_path, dest_path, {:remove_destination => true,
:preserve => true})
end
end
end

def shell_out(command, options={})
default_opts = {
:environment => {'PATH' => "#{DevHelper.omnibus_path}:#{ENV['PATH']}"},
:live_stream => STDOUT
}
c = Mixlib::ShellOut.new(command, default_opts.merge(options))
c.run_command
c.error!
end
end
end
82 changes: 82 additions & 0 deletions recipes/dev.rb
@@ -0,0 +1,82 @@
#
# Copyright:: Copyright (c) 2012 Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include_recipe "git"

repos = {
'chef_authn' => {},
'chef_certgen' => {},
'chef_db' => {},
'chef_index' => {},
'chef_objects' => {},
'chef_wm' => {},
'erchef' => {
:service_name => 'erchef',
:preserved_paths => ["etc/app.config",
"log",
"bin/erchef"],
:build_command => "rebar get-deps && make clean relclean devrel",
:release_path => "rel/erchef"
},
'chef-server-webui' => {
:service_name => 'chef-server-webui',
:preserved_paths => ["config/environments/chefserver.rb",
"tmp",
"config/initializers/secret_token.rb",
"config/initializers/session_store.rb",
"config.ru"],
:build_command => "bundle install --deployment --without development"
},
'omnibus-chef' => {
:omnibus_path => "/opt/chef-server/embedded/cookbooks",
:release_path => "files/chef-server-cookbooks"
},
'chef-pedant' => {
:build_command => "bundle install"
}
}

[ DevHelper.code_root, DevHelper.backup_root].each do |dir|
directory dir do
owner "root"
group "root"
recursive true
action :create
end
end

repos.each do |project, options|

github_name = options.key?(:github_name) ? options[:github_name] : project

git ::File.join(DevHelper.code_root, project) do
repository "git://github.com/opscode/#{github_name}"
reference "master"
action :checkout
end

ruby_block "build and load #{project}" do
block do
p = DevHelper::Project.new(project, options)
p.build_and_load
end
end
end

# Ensure the /opt/chef-server bin/ dirs is first in our PATH
file "/etc/profile.d/omnibus-embedded.sh" do
content "export PATH=\"#{DevHelper.omnibus_path}:$PATH\""
action :create
end

0 comments on commit 658d19d

Please sign in to comment.