Skip to content

Commit

Permalink
basic version of ivy works w/ dynamic attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanwb committed Feb 29, 2012
1 parent fbf0703 commit b40a9d2
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 6 deletions.
4 changes: 4 additions & 0 deletions ark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Resources/Providers
- checksum: sha256 checksum, used for security
- prefix_root: prefix_root for installation, defaults to /usr/local/
- mode: file mode for app_home, is an integer
- install_dir:
- home_dir:
- no_symlink: install_dir and home_dir are the same, no symlink used
- has_binaries: array of binary commands to symlink to /usr/local/bin/
- add_global_bin_dir: boolean, similar to has_binaries but less granular
- If true, append the ./bin directory of the extracted directory to
Expand All @@ -64,6 +67,7 @@ Resources/Providers
/usr/bin/* . Examples are mvn, java, javac, etc. This option
provides more granularity than the boolean option
- user: owner of extracted directory, set to "root" by default

- strip_leading_dir: by default, strip the leading directory from the
extracted archive this can cause unexpected results if there is more
than one subdirectory in the archive
Expand Down
2 changes: 2 additions & 0 deletions ark/resources/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
:install_python
)

attr_reader :home_dir

attribute :name, :name_attribute => true

# URL for the tarball/zip file to install from. If it is named something like
Expand Down
33 changes: 32 additions & 1 deletion ivy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,41 @@ Description
installs apache ivy and provides and lwrp for downloading jars and
their dependencies from ivy and maven repositories

Eventually should have an LWRP to define additional ivy and maven
repositories to pull jars from

Providers/Resources
===================

* artifactId: if this is not specified, the resource's name is used
* groupId: groupId for the artifact
* version: version of the artifact
* dest: the destination folder for the jar and its dependencies
* dest_attr: This is funky, use a node attribute optionally with subdirectory
* owner: the owner of the resulting file
* mode: file permissions


# Examples

ivy "mysql-connector-java" do
groupId "mysql"
version "5.1.18"
dest "/usr/local/tomcat/lib/"
end

ivy "mysql-connector-java" do
groupId "mysql"
version "5.1.18"
dest_attr "tomcat_base/lib"
end

dest_attr resolves to "#{node[current_cookbook_name]['tomcat']['base']}/lib"

## License and Author

Author:: Bryan W. Berry (<[email protected]>)
Copyright:: 2011, Bryan W. Berry
Copyright:: 2012, Bryan W. Berry

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 2 additions & 0 deletions ivy/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

default['ivy']['url'] = 'http://apache.mirrors.tds.net/ant/ivy/2.2.0/apache-ivy-2.2.0-bin.tar.gz'
default['ivy']['checksum'] = 'ff1e40094a4e65878efd1a31589b492752b7f18c810839db3119dbf296086d69'
default['ivy']['version'] = "2.2.0"
default['ivy']['command'] = ""
51 changes: 51 additions & 0 deletions ivy/providers/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# Cookbook Name:: ivy
# Provider:: default
#
# Author:: Bryan W. Berry <[email protected]>
# Copyright 2012, Bryan W. Berry
#
# 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.
#

def resolve_dest(resource)
# use a glob because file can have different extensions
file_glob = "#{resource.artifactId}-#{resource.version}\.*"
if resource.dest_attr
dest_attrs = resource.dest_attr.split(':')
subdirectory = dest_attrs[-1].match('/') ? dest_attrs.pop : ""
node_attr = eval( "node['#{self.cookbook_name}']" +
dest_attrs.map{ |attr| "['" + attr + "']" }.join('') )
dest = "#{node_attr}/#{subdirectory}"
else
dest = "#{resource.dest}"
end
"#{dest}/#{file_glob}"
end

action :install do
full_name = [ new_resource.groupId, new_resource.artifactId, new_resource.version ].join(' ')
dest = resolve_dest new_resource
Chef::Log.debug("dest is #{dest}")
dest_pattern = "#{dest}/[artifact]-[revision].[ext]"
full_command = %Q{#{node['ivy']['command']} -dependency #{full_name} -retrieve #{dest_pattern} }
Chef::Log.debug("dest is #{dest}")
bash "get the dependency" do
code <<-EOH
#{full_command}
chown #{new_resource.owner}:#{new_resource.owner} #{dest}
chmod #{new_resource.mode.to_s} #{dest}
EOH
only_if { Dir.glob("#{dest}\.*").empty? }
end
end
15 changes: 12 additions & 3 deletions ivy/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@

include_recipe "ark"

ark "ivy" do
url node['ivy']['url']
a = ark "ivy" do
release_url node['ivy']['url']
checksum node['ivy']['checksum']
version "2.2.0"
version node['ivy']['version']
end

ruby_block "build the ivy command" do
block do
java_cmd = "#{node['java']['java_home']}/bin/java"
ivy_jar = "#{a.home_dir}/ivy-#{node['ivy']['version']}.jar"
node['ivy']['command'] = "#{java_cmd} -jar #{ivy_jar} "
Chef::Log.debug("ivy command is #{node['ivy']['command']}")
end
end
36 changes: 36 additions & 0 deletions ivy/resources/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Cookbook Name:: ivy
# Resource:: default
#
# Author:: Bryan W. Berry <[email protected]>
# Copyright 2012, Bryan W. Berry
#
# 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.
#

actions :install

attribute :artifactId, :kind_of => String
attribute :groupId, :kind_of => String, :required => true
attribute :version, :kind_of => String, :required => true
attribute :dest, :kind_of => String
attribute :dest_attr, :kind_of => String
attribute :owner, :kind_of => String, :default => "root"
attribute :mode, :kind_of => [String, Integer], :default => "0755"

def initialize(*args)
super
# we can't use the node properties when initially specifying the resource
@artifactId ||= @name
@action = :install
end
26 changes: 26 additions & 0 deletions jira/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Overview
========

This cookbook installs jira from Atlassian


Attributes
==========


## License and Author

Author:: Bryan W. Berry (<[email protected]>)
copyright:: 2012, Bryan W. Berry

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.
23 changes: 23 additions & 0 deletions jira/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Cookbook Name:: jira
# Description:: installs jira
# Attributes:: default
# Author:: Bryan W. Berry
#
# Copyright 2012, Bryan W. Berry
#
# 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.
#

default['jira']['user'] = "jira"
default['jira']['war_url'] = "http://www.atlassian.com/software/jira/downloads/binary/atlassian-jira-5.0-war.zip"
16 changes: 16 additions & 0 deletions jira/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
maintainer "Bryan W. Berry"
maintainer_email "[email protected]"
license "Apache 2.0"
description "Installs/Configures jira"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.0.1"

%w{ java ark tomcat }.each do |cb|
depends cb
end

%w{ debian ubuntu centos redhat fedora }.each do |os|
supports os
end

recipe "jira::default", "Installs and configures jira"
44 changes: 44 additions & 0 deletions jira/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# Cookbook Name:: jira
# Description:: installs jira
# Recipe:: default
# Author:: Bryan W. Berry
#
# Copyright 2012, Bryan W. Berry
#
# 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 "ark"
include_recipe "tomcat::base"
include_recipe "ivy"
base = "/tmp/"

t = tomcat "jira" do
user node['jira']['user']
action :install
end

# get mysql connector
ivy "mysql-connector-java" do
groupId "mysql"
version "5.1.18"
dest_attr ":tomcat:base:/lib"
end

# ark "jira_war" do
# release_url node['jira']['war_url']
# version "5.0"
# install_dir "/usr/local/tomcat/jira/webapps/ROOT"
# no_symlink true
# end
2 changes: 1 addition & 1 deletion pgbouncer/recipes/userlist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@
minute "0"
user "postgres"
shell "/bin/bash"
command "/usr/local/bin/cron_userlist.sh"
command "/home/postgres/cron_userlist.sh"
end
5 changes: 4 additions & 1 deletion tomcat/providers/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def get_resource_hash(resource)
resource_h['home'] = node['tomcat']['home']
resource_h['base'] = "#{catalina_parent}/#{resource_h['name']}"
new_resource.base = resource_h['base']
Chef::Log.debug("cookbook_name is #{self.cookbook_name}")
node[self.cookbook_name]['tomcat'] = {}
node[self.cookbook_name]['tomcat']['base'] = resource_h['base']
resource_h['context_dir'] = "#{resource_h['base']}/conf/Catalina/localhost"
resource_h['log_dir'] = "#{resource_h['base']}/logs"
resource_h['tmp_dir'] = "#{resource_h['base']}/temp"
Expand Down Expand Up @@ -137,7 +140,7 @@ def get_resource_hash(resource)
])
end
s.run_action( :enable )
s.run_action( :start )
#s.run_action( :start )

new_resource.updated_by_last_action(true)
end
Expand Down

0 comments on commit b40a9d2

Please sign in to comment.