Skip to content

Commit

Permalink
updates to cookbook, and install scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorOgg committed Feb 26, 2017
1 parent 3f5ec83 commit 0299935
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 9 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# chef-itdrc-snap-it Cookbook

# Vagrant requirements
# Dev requirements
vagrant plugin install vagrant-omnibus
vagrant plugin install vagrant-berkshelf
vagrant plugin install vagrant-vbguest
vagrant plugin install chef
chef gem install berkshelf


https://downloads.chef.io/chefdk
https://www.vagrantup.com

https://packages.chef.io/files/stable/chef/12.19.36/debian/8/chef_12.19.36-1_amd64.deb
5 changes: 5 additions & 0 deletions chef-solo-install/Berksfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://supermarket.chef.io'
cookbook 'composer', '~> 2.5.2'
cookbook 'chef-itdrc-snap-it', git: "https://github.com/DoctorOgg/chef-itdrc-snap-it.git"
cookbook 'apt', '~> 6.0.0'
cookbook 'acme', '~> 2.0.0'
82 changes: 82 additions & 0 deletions chef-solo-install/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash
# This script used to bootstrap a chef-solo install of the itdrc Snap IT cookbook.
# For debian 8/8.5 machiens ONLY!!!!
# 'curl -sSL https://raw.githubusercontent.com/DoctorOgg/chef-itdrc-snap-it/chef-solo-install/install.sh | sudo bash'
# or:
# 'wget -qO- https://raw.githubusercontent.com/DoctorOgg/chef-itdrc-snap-it/chef-solo-install/install.sh | sudo bash'

# Fyi, i borrowed inspiration for this script for the docker folk, thanks guys!

set -e
CHEF_SOLO_DIR='/root/itdrc-sanp-it-installer'
BERKS_URL="https://raw.githubusercontent.com/DoctorOgg/chef-itdrc-snap-it/chef-solo-install/Berksfile"
SOLO_JSON_URL="https://raw.githubusercontent.com/DoctorOgg/chef-itdrc-snap-it/chef-solo-install/solo.json"
SOLO_RB_URL="https://raw.githubusercontent.com/DoctorOgg/chef-itdrc-snap-it/chef-solo-install/solo.rb"
CHEF_DK_URL="https://packages.chef.io/files/current/chefdk/1.3.10/debian/8/chefdk_1.3.10-1_amd64.deb"
RUN_CHEF_URL="https://raw.githubusercontent.com/DoctorOgg/chef-itdrc-snap-it/chef-solo-install/run-chef.sh"

URLS=( $BERKS_URL $SOLO_JSON_URL $SOLO_RB_URL $CHEF_DK_URL $RUN_CHEF_URL)
command_exists() {
command -v "$@" > /dev/null 2>&1
}

if ! command_exists "curl"; then
echo "Alright, I dont have curl, i'm going to install curl!"
apt-get update
apt-get install -y curl
fi

if ! command_exists "bc"; then
echo "Alright, I dont have curl, i'm going to install curl!"
apt-get update
apt-get install -y bc
fi

# Before we continue, are we running debian 8 or above? Simple test, but better than nothing
if [ -e /etc/debian_version ]; then
echo "Looks like we are running a flavor of debian, now to check version."
debian_version=`cat /etc/debian_version`
if ! [ $(echo "$debian_version >= 8" | bc) -eq 1 ]; then
echo "Sorry, your ${debian_version}", is too old!
exit 1
fi
else
echo "Hi, it looks like /etc/debian_version, does not exist, so i'm guessing we are not running debian."
echo "So i'm going to exit now, before we make more mistakes."
exit 1
fi

if [ -d $CHEF_SOLO_DIR ]; then
echo "Directory exists: ${CHEF_SOLO_DIR}"
else
mkdir -v ${CHEF_SOLO_DIR}
fi

if [ -d "${CHEF_SOLO_DIR}/cookbooks" ]; then
echo "Directory exists: "${CHEF_SOLO_DIR}/cookbooks""
else
mkdir -v "${CHEF_SOLO_DIR}/cookbooks"
fi

echo "Ok, lets get the required files."
for i in "${URLS[@]}"; do
file=`echo ${i##*/}`
if ! [ -e "${CHEF_SOLO_DIR}/$file" ]; then
curl "${i}" -o "${CHEF_SOLO_DIR}/$file"
fi
done

echo "Lets ensure run-chef.sh is execuitable"
run_chef_sh=`echo ${RUN_CHEF_URL##*/}`
( cd $CHEF_SOLO_DIR && chmod +x $run_chef_sh )

echo "Installing Chef DK"
deb=`echo ${CHEF_DK_URL##*/}`
dpkg -i "${CHEF_SOLO_DIR}/${deb}"

echo "Retrieving cookbooks"
(cd $CHEF_SOLO_DIR && berks vendor cookbooks/ )

echo "Alright we got the requirements installed, you should now edit solo.json, then run ./run-chef.sh"

exit 0
2 changes: 2 additions & 0 deletions chef-solo-install/run-chef.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
chef-solo -j solo.json -c solo.rb
30 changes: 30 additions & 0 deletions chef-solo-install/solo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"run_list": [
"recipe[chef-itdrc-snap-it]",
"recipe[chef-itdrc-snap-it::configure-mariadb]"
],
"itdrc": {
"snap-it": {
"letsencrypt": {
"contact": "mailto:[email protected]",
"self-signed": false
},
"mysql": {
"root_pw": "g00dluck"
},
"app_config": {
"app_url": "https://example.com",
"db": {
"password": "g00dluck"
},
"mail": {
"host": "SETME",
"username": "SETME",
"password": "SETME",
"from_address": "SETME",
"from_name": "ITDRC SNAP-IT"
}
}
}
}
}
2 changes: 2 additions & 0 deletions chef-solo-install/solo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
file_cache_path Dir.pwd
cookbook_path file_cache_path + "/cookbooks"
7 changes: 5 additions & 2 deletions recipes/configure-mariadb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
uri 'http://downloads.mariadb.com/MariaDB/mariadb-10.1.21/repo/debian/'
trusted true
components ['main']
keyserver 'keys.gnupg.net'
key 'CBCB082A1BB943DB'
end
# apt-key adv --keyserver keys.gnupg.net --recv CBCB082A1BB943DB

package 'mariadb-server' do
action :install
Expand All @@ -19,9 +22,9 @@
code <<-EOF
mysql -h #{node["itdrc"]["snap-it"]["app_config"]["db"]["host"]} -u root -e "UPDATE mysql.user SET Password=PASSWORD('#{node["itdrc"]["snap-it"]["mysql"]["root_pw"]}') WHERE User='root'; FLUSH PRIVILEGES;"
/etc/init.d/mysql restart
touch /root/.irdc-mariadb-pw-set
touch /etc/mysql/irdc-mariadb-pw-set
EOF
not_if do ::File.exists?('/root/.irdc-mariadb-pw-set') end
not_if do ::File.exists?('/etc/mysql/irdc-mariadb-pw-set') end
end

script 'create db and user' do
Expand Down
4 changes: 2 additions & 2 deletions recipes/configure-webserver.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include_recipe 'acme'
node.set['acme']['contact'] = node["itdrc"]["snap-it"]["letsencrypt"]["contact"]
node.set['acme']['endpoint'] = 'https://acme-v01.api.letsencrypt.org'
node.override['acme']['contact'] = node["itdrc"]["snap-it"]["letsencrypt"]["contact"]
node.override['acme']['endpoint'] = 'https://acme-v01.api.letsencrypt.org'
site=URI.parse(node["itdrc"]["snap-it"]["app_config"]["app_url"]).host

service 'apache2' do
Expand Down

0 comments on commit 0299935

Please sign in to comment.