forked from udacity/devops-intro-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add(packer): appserver scripts and config files
- Loading branch information
Gundega Dekena
committed
Apr 8, 2015
1 parent
467c59c
commit 4e2ea7a
Showing
12 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Instructions for Intro to DevOps Project | ||
======================================== | ||
|
||
Part 0 - Local Installation | ||
########################### | ||
|
||
1. Install VirtualBox | ||
2. Install Vagrant | ||
3. Install Packer | ||
4. Install git | ||
|
||
Part I - Build Boxes with Packer | ||
################################ | ||
|
||
1. run 'packer build application-server.json' | ||
2. run 'vagrant box add ubuntu-14.04.2-server-amd64-appserver_virtualbox.box --name devops-appserver' | ||
3. change directory to virtualbox | ||
4. run 'vagrant up' | ||
5. run 'vagrant ssh' to connect to the server | ||
6. run 'git clone https://github.com/chef/devops-kungfu.git' | ||
# This repo will be replaced with a lighter (smaller) version in Udacity repo later on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{ | ||
"variables": { | ||
"PACKER_OS_FLAVOUR": "ubuntu", | ||
"PACKER_BOX_NAME": "ubuntu-14.04.2-server-amd64", | ||
"AWS_ACCESS_KEY_ID": "{{env `AWS_ACCESS_KEY_ID`}}", | ||
"AWS_SECRET_ACCESS_KEY": "{{env `AWS_SECRET_ACCESS_KEY`}}" | ||
}, | ||
"builders": [ | ||
{ | ||
"type": "virtualbox-iso", | ||
"boot_command": [ | ||
"<esc><wait>", | ||
"<esc><wait>", | ||
"<enter><wait>", | ||
"/install/vmlinuz<wait>", | ||
" auto<wait>", | ||
" console-setup/ask_detect=false<wait>", | ||
" console-setup/layoutcode=us<wait>", | ||
" console-setup/modelcode=pc105<wait>", | ||
" debconf/frontend=noninteractive<wait>", | ||
" debian-installer=en_US<wait>", | ||
" fb=false<wait>", | ||
" initrd=/install/initrd.gz<wait>", | ||
" kbd-chooser/method=us<wait>", | ||
" keyboard-configuration/layout=USA<wait>", | ||
" keyboard-configuration/variant=USA<wait>", | ||
" locale=en_US<wait>", | ||
" netcfg/get_domain=vm<wait>", | ||
" netcfg/get_hostname=vagrant<wait>", | ||
" noapic<wait>", | ||
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<wait>", | ||
" -- <wait>", | ||
"<enter><wait>" | ||
], | ||
"boot_wait": "10s", | ||
"headless": false, | ||
"disk_size": 10140, | ||
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", | ||
"guest_os_type": "Ubuntu_64", | ||
"http_directory": "http", | ||
"iso_checksum": "8acd2f56bfcba2f7ac74a7e4a5e565ce68c024c38525c0285573e41c86ae90c0", | ||
"iso_checksum_type": "sha256", | ||
"iso_url": "http://releases.ubuntu.com/trusty/{{ user `PACKER_BOX_NAME` }}.iso", | ||
"shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now", | ||
"ssh_password": "vagrant", | ||
"ssh_port": 22, | ||
"ssh_username": "vagrant", | ||
"ssh_wait_timeout": "10000s", | ||
"type": "virtualbox-iso", | ||
"vm_name": "{{ user `PACKER_BOX_NAME` }}", | ||
"vboxmanage": [ | ||
["modifyvm", "{{.Name}}", "--memory", "1024"], | ||
["modifyvm", "{{.Name}}", "--cpus", "2"] | ||
], | ||
"virtualbox_version_file": ".vbox_version" | ||
} | ||
], | ||
|
||
"provisioners": [ | ||
{ | ||
"type": "shell", | ||
"execute_command": "echo 'vagrant'|{{.Vars}} sudo -S -E bash '{{.Path}}'", | ||
"scripts": [ | ||
"scripts/update.sh", | ||
"scripts/sshd.sh", | ||
"scripts/sudoers.sh" | ||
] | ||
}, | ||
{ | ||
"type": "shell", | ||
"only": ["virtualbox-iso"], | ||
"execute_command": "echo 'vagrant'|sudo -S -E bash '{{.Path}}'", | ||
"scripts": [ | ||
"scripts/virtualbox.sh", | ||
"scripts/vagrant.sh" | ||
] | ||
}, | ||
{ | ||
"type": "shell", | ||
"execute_command": "echo 'vagrant'|sudo -S -E bash '{{.Path}}'", | ||
"scripts": [ | ||
"scripts/application.sh", | ||
"scripts/cleanup.sh" | ||
] | ||
} | ||
], | ||
"post-processors": [ | ||
[ | ||
{ | ||
"type": "vagrant", | ||
"compression_level": "9", | ||
"output": "{{.Provider}}/{{ user `PACKER_BOX_NAME` }}-appserver_{{.Provider}}.box" | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
choose-mirror-bin mirror/http/proxy string | ||
d-i base-installer/kernel/override-image string linux-server | ||
d-i clock-setup/utc boolean true | ||
d-i clock-setup/utc-auto boolean true | ||
d-i finish-install/reboot_in_progress note | ||
d-i grub-installer/only_debian boolean true | ||
d-i grub-installer/with_other_os boolean true | ||
d-i partman-auto-lvm/guided_size string max | ||
d-i partman-auto/choose_recipe select atomic | ||
d-i partman-auto/method string lvm | ||
d-i partman-lvm/confirm boolean true | ||
d-i partman-lvm/confirm boolean true | ||
d-i partman-lvm/confirm_nooverwrite boolean true | ||
d-i partman-lvm/device_remove_lvm boolean true | ||
d-i partman/choose_partition select finish | ||
d-i partman/confirm boolean true | ||
d-i partman/confirm_nooverwrite boolean true | ||
d-i partman/confirm_write_new_label boolean true | ||
d-i passwd/user-fullname string vagrant | ||
d-i passwd/user-uid string 900 | ||
d-i passwd/user-password password vagrant | ||
d-i passwd/user-password-again password vagrant | ||
d-i passwd/username string vagrant | ||
d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms nfs-common | ||
d-i pkgsel/install-language-support boolean false | ||
d-i pkgsel/update-policy select none | ||
d-i pkgsel/upgrade select safe-upgrade | ||
d-i time/zone string UTC | ||
d-i user-setup/allow-password-weak boolean true | ||
d-i user-setup/encrypt-home boolean false | ||
tasksel tasksel/first multiselect standard, ubuntu-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash -eux | ||
|
||
apt-get -y install nginx | ||
sed -i -e '0,/root \/usr\/share\/nginx\/html/s//root \/home\/vagrant\/devops-kungfu/' /etc/nginx/sites-available/default | ||
|
||
|
||
# install git, needed for acquiring webapp source code | ||
apt-get -y install git | ||
|
||
# remove old node just in case | ||
apt-get remove --purge node | ||
|
||
# application and build process required packages | ||
# add Node.js maintained repositories | ||
curl -sL https://deb.nodesource.com/setup | bash - | ||
|
||
# for tests and build | ||
apt-get -y install nodejs | ||
# for phantomjs | ||
apt-get -y install libfontconfig1 fontconfig libfontconfig1-dev libfreetype6-dev | ||
|
||
# for sass | ||
apt-get -y install ruby | ||
gem install sass | ||
|
||
#for running grunt tasks manually | ||
npm install -g grunt-cli | ||
|
||
|
||
cd /home/vagrant | ||
mkdir devops-kungfu | ||
# get requirement package | ||
cd /home/vagrant/devops-kungfu | ||
wget https://raw.githubusercontent.com/chef/devops-kungfu/master/package.json | ||
|
||
# install some packeges missing in the official repo | ||
npm install lru-cache sigmund | ||
npm install accepts batch | ||
npm install qunitjs | ||
|
||
# install the rest of the requirements. This takes a while | ||
npm install | ||
|
||
# reset permissions | ||
chown vagrant -R /home/vagrant | ||
|
||
# reload nginx to serve from the directory | ||
service nginx reload | ||
|
||
echo 'Environment is ready, you should fork and clone the repo now.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash -eux | ||
|
||
dd if=/dev/zero of=/EMPTY bs=1M | ||
rm -f /EMPTY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash -eux | ||
|
||
# JDK and JRE are required | ||
|
||
apt-get install openjdk-7-jre openjdk-7-jdk | ||
|
||
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add - | ||
echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list | ||
|
||
apt-get update | ||
apt-get install jenkins | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash -eux | ||
|
||
echo "UseDNS no" >> /etc/ssh/sshd_config | ||
echo "GSSAPIAuthentication no" >> /etc/ssh/sshd_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash -eux | ||
|
||
# Only add the secure path line if it is not already present - Debian 7 | ||
# includes it by default. | ||
grep -q 'secure_path' /etc/sudoers || sed -i -e '/Defaults\s\+env_reset/a Defaults\tsecure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"' /etc/sudoers | ||
|
||
# Set up password-less sudo for the vagrant user | ||
echo 'vagrant ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/99_vagrant | ||
chmod 440 /etc/sudoers.d/99_vagrant | ||
|
||
# vagrant prefers no tty | ||
echo "Defaults !requiretty" >> /etc/sudoers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash -eux | ||
|
||
apt-get update | ||
apt-get -y upgrade | ||
|
||
# ensure the correct kernel headers are installed | ||
apt-get -y install linux-headers-$(uname -r) | ||
|
||
# update package index on boot | ||
cat <<EOF > /etc/init/refresh-apt.conf | ||
description "update package index" | ||
start on networking | ||
task | ||
exec /usr/bin/apt-get update | ||
EOF | ||
|
||
# install curl to fix broken wget while retrieving content from secured sites | ||
apt-get -y install curl | ||
|
||
# install general purpose packages | ||
# install rsync | ||
apt-get -y install rsync | ||
|
||
# install screen | ||
apt-get -y install screen | ||
|
||
# install pip | ||
apt-get -y install python-pip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash -eux | ||
|
||
mkdir -p /home/vagrant/.ssh | ||
curl -L -k 'https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub' -o /home/vagrant/.ssh/authorized_keys | ||
chown -R vagrant /home/vagrant/.ssh | ||
chmod -R go-rwsx /home/vagrant/.ssh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash -eux | ||
|
||
echo "Installing Virtualbox Guest Utils" | ||
apt-get -y install dkms | ||
VBOX_VERSION=$(cat /home/vagrant/.vbox_version) | ||
#cd /tmp | ||
#wget http://download.virtualbox.org/virtualbox/$VBOX_VERSION/VBoxGuestAdditions_$VBOX_VERSION.iso | ||
mount -o loop ~/VBoxGuestAdditions_$VBOX_VERSION.iso /mnt | ||
sh /mnt/VBoxLinuxAdditions.run | ||
umount /mnt | ||
|
||
rm ~/VBoxGuestAdditions_$VBOX_VERSION.iso |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
|
||
# All Vagrant configuration is done below. | ||
|
||
Vagrant.configure(2) do |config| | ||
|
||
config.vm.box = "devops-appserver" | ||
|
||
# Create a forwarded port mapping which allows access to a specific port | ||
# within the machine from a port on the host machine. In the example below, | ||
# accessing "localhost:8080" will access port 80 on the guest machine. | ||
config.vm.network "forwarded_port", guest: 80, host: 8080 | ||
|
||
# Share an additional folder to the guest VM. The first argument is | ||
# the path on the host to the actual folder. The second argument is | ||
# the path on the guest to mount the folder. | ||
config.vm.synced_folder "../devops-kungfu", "/home/vagrant/devops-kungfu-src", create: true | ||
|
||
end |