lrt

Merge lp:~canonical-platform-qa/lrt/lxd_setup into lp:lrt

Proposed by Federico Gimenez
Status: Work in progress
Proposed branch: lp:~canonical-platform-qa/lrt/lxd_setup
Merge into: lp:lrt
Diff against target: 58 lines (+54/-0)
1 file modified
lxd_jenkins.sh (+54/-0)
To merge this branch: bzr merge lp:~canonical-platform-qa/lrt/lxd_setup
Reviewer Review Type Date Requested Status
Canonical Platform QA Team Pending
Review via email: mp+259950@code.launchpad.net

Commit message

Provision script for setting up a lxd-managed jenkins container

Description of the change

Provision script for setting up a lxd-managed jenkins container

To post a comment you must log in.
100. By Federico Gimenez

Some fixes

Unmerged revisions

100. By Federico Gimenez

Some fixes

99. By Federico Gimenez

Provision script for setting up a lxd-managed jenkins container

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'lxd_jenkins.sh'
2--- lxd_jenkins.sh 1970-01-01 00:00:00 +0000
3+++ lxd_jenkins.sh 2015-05-22 17:33:16 +0000
4@@ -0,0 +1,54 @@
5+#/bin/sh
6+set -x
7+
8+sudo apt-get -qq install lxd lxc
9+
10+CONTAINER_NAME=jenkins-test
11+IMAGE_NAME=${CONTAINER_NAME}-image
12+IMAGE_EXISTS=`lxc image list | grep $IMAGE_NAME | awk '{print $2}'`
13+CONTAINER_EXISTS=`lxc list | grep $CONTAINER_NAME | awk '{print $2}'`
14+
15+lxc_exec() {
16+ lxc exec $CONTAINER_NAME -- "$@"
17+}
18+
19+provision() {
20+ lxc_exec sudo apt-get update
21+ lxc_exec sudo apt-get install -y wget bzr autopkgtest libusb-dev usbutils android-tools-adb phablet-tools iptables
22+ lxc_exec sh -c "wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -"
23+ lxc_exec sudo bash -c "echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list"
24+ lxc_exec sudo apt-get update
25+ lxc_exec sudo apt-get install -y jenkins
26+}
27+
28+setup_usb(){
29+ read -r -d '' LXC_CONF << EOF
30+lxc.cgroup.devices.allow = c 189:* rwm
31+lxc.mount.entry = /dev/bus/usb dev/bus/usb none bind,optional,create=dir
32+EOF
33+ lxc config set $CONTAINER_NAME raw.lxc "$LXC_CONF"
34+ lxc_exec sudo sh -c "iptables -t nat -A PREROUTING -p tcp --dport 5555:5585 -j DNAT --to 10.0.3.1"
35+ lxc_exec sudo sh -c "iptables-save -t nat > /etc/iptables.rules"
36+ lxc_exec sudo sh -c "echo \"iptables-restore < /etc/iptables.rules\" > /etc/rc.local"
37+ lxc_exec sudo sh -c "echo \"exit 0\" >> /etc/rc.local"
38+}
39+
40+echo 'Creating base image...'
41+if [ -z $IMAGE_EXISTS ]; then
42+ lxd-images import lxc ubuntu trusty amd64 --alias $IMAGE_NAME
43+fi
44+
45+if [ $CONTAINER_EXISTS ]; then
46+ echo 'Deleting existing container...'
47+ lxc delete $CONTAINER_NAME
48+fi
49+
50+echo 'Launching container...'
51+lxc launch $IMAGE_NAME $CONTAINER_NAME
52+sleep 5
53+
54+echo 'Provisioning container...'
55+provision
56+
57+echo 'Setting up usb access...'
58+setup_usb

Subscribers

People subscribed via source and target branches

to all changes: