Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson Silva committed Sep 13, 2013
0 parents commit d7498ef
Show file tree
Hide file tree
Showing 23 changed files with 235 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.deps
.vagrant
aws_config.json
packer_cache
18 changes: 18 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[submodule "cookbooks/git"]
path = cookbooks/git
url = https://github.com/opscode-cookbooks/git.git
[submodule "cookbooks/maven"]
path = cookbooks/maven
url = https://github.com/opscode-cookbooks/maven.git
[submodule "cookbooks/java"]
path = cookbooks/java
url = https://github.com/opscode-cookbooks/java.git
[submodule "cookbooks/ark"]
path = cookbooks/ark
url = https://github.com/opscode-cookbooks/ark.git
[submodule "cookbooks/nodejs"]
path = cookbooks/nodejs
url = https://github.com/inevo/nodejs-cookbook.git
[submodule "cookbooks/apt"]
path = cookbooks/apt
url = https://github.com/opscode-cookbooks/apt.git
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
DEPS = .deps
PACKER = $(DEPS)/packer/packer
VAGRANT = /usr/bin/vagrant

$(VAGRANT):
@echo "Downloading vagrant"
wget http://files.vagrantup.com/packages/b12c7e8814171c1295ef82416ffe51e8a168a244/vagrant_1.3.1_x86_64.deb -P $(DEPS)
sudo dpkg -i $(DEPS)/vagrant_1.3.1_x86_64.deb
rm $(DEPS)/vagrant_1.3.1_x86_64.deb

$(PACKER):
@echo "Downloading packer"
wget https://dl.bintray.com/mitchellh/packer/0.3.7_linux_amd64.zip -P $(DEPS)/packer
unzip -d $(DEPS)/packer $(DEPS)/packer/0.3.7_linux_amd64.zip
rm $(DEPS)/packer/0.3.7_linux_amd64.zip

aws: $(PACKER)
$(PACKER) build -only=aws -var-file=aws_config.json bamboo_elastic.json

vagrant: $(VAGRANT)
$(VAGRANT) up
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Bamboo Elastic Image
### a Template for Packer

## Quick Start

* Copy `aws_config.json.sample` to `aws_config.json` and add your access/secret keys for AWS.
* Run `make aws`
20 changes: 20 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

config.vm.box = "raring"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/raring/current/raring-server-cloudimg-amd64-vagrant-disk1.box"

# DRY, let's read the config from the packet config
bamboo_elastic = JSON.parse(File.read("bamboo_elastic.json"))

# find the chef-solo provisioner
p = bamboo_elastic["provisioners"].find {|p| p["type"] == "chef-solo"}

config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = p["cookbook_paths"]
chef.json = p["json"]
p["run_list"].each {|r| chef.add_recipe r}
end

end
5 changes: 5 additions & 0 deletions aws_config.json.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"aws_access_key": "ACCESS_KEY",
"aws_secret_key": "SECRET_KEY",
"aws_region": "eu-west-1"
}
62 changes: 62 additions & 0 deletions bamboo_elastic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"variables": {
"aws_access_key": "",
"aws_secret_key": "",
"aws_region": "us-east-1",
"aws_ami": "ami-e894719f"
},

"builders": [
{
"name": "aws",
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "{{user `aws_region`}}",
"source_ami": "{{user `aws_ami`}}",
"instance_type": "t1.micro",
"ssh_username": "ubuntu",
"ami_name": "Bamboo Elastic Image {{timestamp}}"
}
],

"provisioners": [
{
"type": "shell",
"scripts": [
"scripts/update.sh",
"scripts/bamboo_agent.sh"
],
"execute_command": "{{ .Vars }} sudo -E sh '{{ .Path }}'"
},
{
"type": "chef-solo",
"cookbook_paths": ["cookbooks", "site-cookbooks"],
"run_list": [
"git",
"java",
"maven",
"nodejs",
"grunt",
"bower"
],
"json": {
"java": {
"install_flavor": "openjdk",
"jdk_version": "7",
"arch": "x86_64",
"oracle": { "accept_oracle_download_terms": true}
},
"maven": {
"m2_home": "/opt/maven-3.0"
},
"nodejs": {
"install_method": "binary",
"version": "0.10.18",
"dir": "/opt/node-0.10",
"check_sha": false
}
}
}
]
}
1 change: 1 addition & 0 deletions cookbooks/apt
Submodule apt added at b58c75
1 change: 1 addition & 0 deletions cookbooks/ark
Submodule ark added at 7704a9
1 change: 1 addition & 0 deletions cookbooks/git
Submodule git added at 575a3e
1 change: 1 addition & 0 deletions cookbooks/java
Submodule java added at c6ef8a
1 change: 1 addition & 0 deletions cookbooks/maven
Submodule maven added at e6852f
1 change: 1 addition & 0 deletions cookbooks/nodejs
Submodule nodejs added at 747bf8
34 changes: 34 additions & 0 deletions scripts/bamboo_agent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

# Enable the multiverse repos
sed -i "/^# deb.*multiverse/ s/^# //" /etc/apt/sources.list

apt-get update

# Install the deps
apt-get -y install ec2-api-tools unzip

# Add the bamboo user
useradd -m bamboo

# Downloading agent installer to the instance
imageVer=3.0
wget https://maven.atlassian.com/content/repositories/atlassian-public/com/atlassian/bamboo/atlassian-bamboo-elastic-image/${imageVer}/atlassian-bamboo-elastic-image-${imageVer}.zip
mkdir -p /opt/bamboo-elastic-agent
unzip -o atlassian-bamboo-elastic-image-${imageVer}.zip -d /opt/bamboo-elastic-agent
chown -R bamboo /opt/bamboo-elastic-agent
chmod -R u+r+w /opt/bamboo-elastic-agent

# Instance configuration

chown -R bamboo:bamboo /home/bamboo/

# Configure path variables
echo "export PATH=/opt/bamboo-elastic-agent/bin:\$PATH" > /etc/profile.d/bamboo.sh

# Configure automatic startup of the Bamboo agent (add before line 14 of /etc/rc.local
sed -i '14 i . /opt/bamboo-elastic-agent/etc/rc.local' /etc/rc.local

# Welcome screen
cp /opt/bamboo-elastic-agent/etc/motd /etc/motd
echo bamboo-5.0.2 >> /etc/motd
11 changes: 11 additions & 0 deletions scripts/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

apt-get update
apt-get -y upgrade
apt-get -y dist-upgrade
apt-get -y autoclean

# ensure the correct kernel headers are installed
apt-get -y install linux-headers-$(uname -r)

apt-get -y clean
3 changes: 3 additions & 0 deletions site-cookbooks/bower/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name "bower"

depends "npm"
3 changes: 3 additions & 0 deletions site-cookbooks/bower/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_recipe "npm"

npm_package "bower"
3 changes: 3 additions & 0 deletions site-cookbooks/grunt/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name "grunt"

depends "npm"
3 changes: 3 additions & 0 deletions site-cookbooks/grunt/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_recipe "npm"

npm_package "grunt-cli"
3 changes: 3 additions & 0 deletions site-cookbooks/npm/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name "npm"

depends "nodejs"
22 changes: 22 additions & 0 deletions site-cookbooks/npm/providers/package.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# encoding: utf-8

action :install do
NPM ||= "#{node['nodejs']['dir']}/bin/npm"
Chef::Log.info("Using npm from #{NPM}")
pkg_id = new_resource.name
pkg_id += "@#{new_resource.version}" if new_resource.version
execute "install NPM package #{new_resource.name}" do
command "#{NPM} -g install #{pkg_id}"
not_if "#{NPM} -g ls 2> /dev/null | grep '^[├└]─[─┬] #{pkg_id}'"
end
end

action :uninstall do
NPM ||= "#{node['nodejs']['dir']}/bin/npm"
pkg_id = new_resource.name
pkg_id += "@#{new_resource.version}" if new_resource.version
execute "uninstall NPM package #{new_resource.name}" do
command "#{NPM} -g uninstall #{pkg_id}"
only_if "#{NPM} -g ls 2> /dev/null | grep '^[├└]─[─┬] #{pkg_id}'"
end
end
1 change: 1 addition & 0 deletions site-cookbooks/npm/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NPM = "#{node['nodejs']['dir']}/bin/npm"
9 changes: 9 additions & 0 deletions site-cookbooks/npm/resources/package.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
actions :install, :uninstall

attribute :name, :name_attribute => true
attribute :version, :default => nil

def initialize(*args)
super
@action = :install
end

0 comments on commit d7498ef

Please sign in to comment.