2 # Rakefile for Chef Server Repository
4 # Author:: Adam Jacob (<adam@opscode.com>)
5 # Copyright:: Copyright (c) 2008 Opscode, Inc.
6 # License:: Apache License, Version 2.0
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
25 # Load constants from rake config file.
26 require File.join(File.dirname(__FILE__), 'config', 'rake')
28 # Detect the version control system and assign to $vcs. Used by the update
29 # task in chef_repo.rake (below). The install task calls update, so this
30 # is run whenever the repo is installed.
32 # Comment out these lines to skip the update.
34 if File.directory?(File.join(TOPDIR, ".svn"))
36 elsif File.directory?(File.join(TOPDIR, ".git"))
40 # Load common, useful tasks from Chef.
41 # rake -T to see the tasks this loads.
43 load 'chef/tasks/chef_repo.rake'
45 desc "Bundle a single cookbook for distribution"
46 task :bundle_cookbook => [ :metadata ]
47 task :bundle_cookbook, :cookbook do |t, args|
48 tarball_name = "#{args.cookbook}.tar.gz"
49 temp_dir = File.join(Dir.tmpdir, "chef-upload-cookbooks")
50 temp_cookbook_dir = File.join(temp_dir, args.cookbook)
51 tarball_dir = File.join(TOPDIR, "pkgs")
52 FileUtils.mkdir_p(tarball_dir)
53 FileUtils.mkdir(temp_dir)
54 FileUtils.mkdir(temp_cookbook_dir)
56 child_folders = [ "cookbooks/#{args.cookbook}", "site-cookbooks/#{args.cookbook}" ]
57 child_folders.each do |folder|
58 file_path = File.join(TOPDIR, folder, ".")
59 FileUtils.cp_r(file_path, temp_cookbook_dir) if File.directory?(file_path)
62 system("tar", "-C", temp_dir, "-cvzf", File.join(tarball_dir, tarball_name), "./#{args.cookbook}")
64 FileUtils.rm_rf temp_dir