forked from eucalyptus/micro-qa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
140 lines (121 loc) · 4.5 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash -x
### Add EPEL repo
if [ ! -e /etc/yum.repos.d/epel.repo ];then
yum install -y http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
fi
### Install deps
yum install -y python-devel python-setuptools gcc make python-virtualenv java-1.7.0-openjdk-devel git ntp wget unzip ant
### Install jenkins
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
yum install -y jenkins
chkconfig jenkins on
### Configure NTP
chkconfig ntpd on
service ntpd start
ntpdate -u pool.ntp.org
### Setup IPtables
iptables -F
iptables -F -t nat
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables-save > /etc/sysconfig/iptables
### Initialize Jenkins Home
rsync -va /vagrant/jenkins/ /var/lib/jenkins/
chown -R jenkins:jenkins /var/lib/jenkins
### Get IP address
if curl http://169.254.169.254/latest/meta-data;then
### This is an instance
ipaddress=`curl http://169.254.169.254/latest/meta-data/public-ipv4/`
else
### This is a virtualbox vm
ipaddress=`ifconfig eth1 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'`
fi
sed -i s/localhost/$ipaddress/g /var/lib/jenkins/jenkins.model.JenkinsLocationConfiguration.xml /var/lib/jenkins/org.codefirst.SimpleThemeDecorator.xml
echo "$ipaddress `hostname`" >> /etc/hosts
### Start jenkins
service jenkins start
### Setup Jenkins sync script
SYNC_COMMAND=/usr/bin/jenkins-sync
cat > $SYNC_COMMAND <<EOF
#!/bin/bash
rsync -va /var/lib/jenkins/ /vagrant/jenkins/ --exclude workspace --exclude builds --exclude nextBuildNumber --exclude lastStable --exclude lastSuccessful --exclude .git --exclude share
EOF
chmod +x $SYNC_COMMAND
### Setup eutester-base virtualenv
pushd /var/lib/jenkins/
mkdir share
pushd share
virtualenv eutester-base
source eutester-base/bin/activate
./eutester-base/bin/easy_install 'paramiko>=1.7' 'boto==2.5.2' 'jinja2>=2.7' argparse futures python-dateutil mock
chown -R jenkins:jenkins eutester-base
popd
popd
### Install Selenium Dependencies
easy_install selenium
yum -y install make rubygems ruby-devel xorg-x11-font* wget xorg-x11-server-Xvfb firefox
cd /
wget -q https://selenium.googlecode.com/files/selenium-server-2.35.0.zip
unzip selenium-server-2.35.0.zip
dbus-uuidgen > /var/lib/dbus/machine-id
Xvfb :0 -ac 2> /dev/null &
export DISPLAY=":0" && nohup java -jar selenium-2.35.0/selenium-server-standalone-2.35.0.jar -trustAllSSLCertificates &
### Install chef dependencies
curl -L https://www.opscode.com/chef/install.sh | bash
yum -y install https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.10-1.el6.x86_64.rpm
chef-server-ctl reconfigure
mkdir ~/.chef
cp /etc/chef-server/admin.pem ~/.chef
cp /etc/chef-server/chef-validator.pem ~/.chef
cat > ~/.chef/knife.rb <<EOF
log_level :info
log_location STDOUT
node_name 'admin'
client_key '/var/lib/jenkins/.chef/admin.pem'
validation_client_name 'chef-validator'
validation_key '/var/lib/jenkins/.chef/chef-validator.pem'
chef_server_url 'https://localhost:443'
syntax_check_cache_path '/var/lib/jenkins/.chef/syntax_check_cache'
cookbook_path [
"/root/cookbooks",
]
EOF
echo 'erchef['s3_url_ttl'] = 3600' >> /etc/chef-server/chef-server.rb
echo "bookshelf['vip'] = '$ipaddress'"
echo "bookshelf['url'] = 'https://$ipaddress'"
chef-server-ctl reconfigure
sed -i s/localhost/$ipaddress/g ~/.chef/knife.rb
cp -a /root/.chef/ /var/lib/jenkins/
chown -R jenkins:jenkins /var/lib/jenkins/.chef/
## Download cookbooks
mkdir /root/cookbooks
pushd /root/cookbooks
git init
echo "Chef Repo" >> README
git add .
git commit -a -m "Initial commit"
knife cookbook site install ntp
knife cookbook upload ntp
knife cookbook site install partial_search
knife cookbook upload partial_search
knife cookbook site install ssh_known_hosts
knife cookbook upload ssh_known_hosts
knife cookbook site install selinux
knife cookbook upload selinux
knife cookbook site install yum
knife cookbook upload yum
knife cookbook site install iptables
knife cookbook upload iptables
git clone https://github.com/viglesiasce/eucalyptus-cookbook.git eucalyptus
knife cookbook upload eucalyptus
## Upload roles
knife role from file eucalyptus/roles/*
popd
### Create rc.local
cat > /etc/rc.local <<EOF
#!/bin/bash
Xvfb :0 -ac &
export DISPLAY=":0" && nohup java -jar /selenium-2.35.0/selenium-server-standalone-2.35.0.jar -trustAllSSLCertificates &
exit 0
EOF
chmod +x /etc/rc.local