~andrewjbeach/juju-ci-tools/make-local-patcher

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
#!/bin/bash
set -eux
: ${LOCAL_JENKINS_URL=$JENKINS_URL}
INSTANCE_TYPE=$1
AMI_IMAGE=$2
tarfile=$(python <<EOT
import json
import sys
import urllib2

build_data = urllib2.urlopen(
  '$LOCAL_JENKINS_URL/job/build-revision/lastSuccessfulBuild/api/json')
build_json = json.load(build_data)
for artifact in build_json['artifacts']:
  filename = artifact['fileName']
  if filename.endswith('.tar.gz'):
    break
else:
  sys.exit(1)
print filename
EOT
)
RUN_OUTPUT=$(euca-run-instances -k id_rsa -t $INSTANCE_TYPE $AMI_IMAGE)
if [ $? -ne 0 ]; then
  exit 1
fi

instance_id=$(echo $RUN_OUTPUT|sed -r 's/.*INSTANCE (i-[^ ]*) .*/\1/')
set +x
echo Starting instance $instance_id
instance_ip=''
echo -n Waiting for IP address
while [ -z "$instance_ip" ]; do
  sleep 1
  instance_ip=$(euca-describe-instances $instance_id|sed '/^INSTANCE/!d'|cut -f 17)
  echo -n .
done
echo
echo Instance has ip $instance_ip
sleep 30
echo -n Waiting for SSH
while ! netcat $instance_ip 22 -w 1 -q 0 </dev/null >/dev/null; do
  sleep 1
  echo -n .
done
echo
set -x
set +e
ssh ubuntu@$instance_ip -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" <<EOT
set -eux
ssh-keygen -t rsa -b 2048 -N "" -f ~/.ssh/id_rsa
wget -q $JENKINS_URL/job/build-revision/lastSuccessfulBuild/artifact/$tarfile
tar -xzvf $tarfile
export GOPATH=\$HOME/$(echo $tarfile|sed -r 's/(.*).tar.gz/\1/')
cd \$GOPATH/src/launchpad.net/juju-core
sudo apt-get update
sudo apt-get install -y build-essential
make install-dependencies
bzr whoami 'J. Random Hacker <jrandom@example.org>'
make check
EOT
EXIT_STATUS=$?
set -e
euca-terminate-instances $instance_id
exit $EXIT_STATUS