Skip to content
Permalink
Browse files

Bug 1131747 - Add testdroid proxy feature to docker-worker

  • Loading branch information...
Greg Arndt
Greg Arndt committed Jan 30, 2015
1 parent abc3f5f commit 02e4d8405302c7f2a404736cfd8b4e46f053da4b
@@ -7,3 +7,4 @@
/test/settings/configure
/test/settings/billingCycleRemaining
/deploy.json
docker-worker.conf.json
@@ -0,0 +1,3 @@
{
"esnext": true
}
@@ -9,6 +9,7 @@ module.exports = {
// Image used to create the taskcluster proxy container.
taskclusterProxyImage: 'taskcluster/proxy',
taskclusterLogImage: 'taskcluster/logserve',
testdroidProxyImage: 'quay.io/mozilla/testdroid-proxy:0.0.3',

alivenessCheckInterval: 30000, // 30 seconds

@@ -81,5 +82,11 @@ module.exports = {
url: process.env.STATSD_URL || 'tcp://localhost:8125'
},

testdroid: {
url: process.env.TESTDROID_URL,
username: process.env.TESTDROID_USERNAME,
password: process.env.TESTDROID_PASSWORD
},

dockerWorkerPrivateKey: '/etc/docker-worker-priv.pem'
};
@@ -2,12 +2,16 @@ CONFIG_FILE?=./deploy.json
TARGETS?=$(shell find template -type file | sed 's/template/target/')
DEPLOY_TAR?=deploy.tar.gz
PRIVATE_KEY?=$(shell ./bin/resolve_path_in_config $(CONFIG_FILE) privateKeyLocation)
VPN_PROFILE?=$(shell ./bin/resolve_path_in_config $(CONFIG_FILE) vpnProfileLocation)
VPN_CREDENTIALS?=$(shell ./bin/resolve_path_in_config $(CONFIG_FILE) vpnCredentialsLocation)

$(DEPLOY_TAR): all
tar cvfz $@ target/
rm target/etc/$(shell basename $(PRIVATE_KEY))
rm target/etc/openvpn/$(shell basename $(VPN_PROFILE))
rm target/etc/openvpn/$(shell basename $(VPN_CREDENTIALS))

all: $(TARGETS) private_key
all: $(TARGETS) private_key vpn

# Pick up changes when we update variables.js or configure.js
$(CONFIG_FILE): variables.js bin/configure.js
@@ -28,6 +32,15 @@ private_key: $(CONFIG_FILE)
mkdir -p target/etc/
cp $(PRIVATE_KEY) target/etc/

# Copy openvpn profile to be used with testdroid remote device lab
.PHONY: vpn
vpn: $(CONFIG_FILE)
test -f $(VPN_PROFILE)
test -f $(VPN_CREDENTIALS)
mkdir -p target/etc/openvpn
cp $(VPN_PROFILE) target/etc/openvpn/
cp $(VPN_CREDENTIALS) target/etc/openvpn/

.PHONY: clean
clean:
rm -Rf target $(DEPLOY_TAR)
@@ -4,7 +4,7 @@
"variables": {
"npmPackage": "",
"templateContents": "",
"sourceAMI": "ami-df6c37ef",
"sourceAMI": "ami-e39dc5d3",
"logglyAccount": "",
"logglyAuth": "",
"papertrail": "",
@@ -18,4 +18,4 @@ sudo sh -c "echo deb https://get.docker.io/ubuntu docker main\
sudo apt-get update -y

## Install all the packages
sudo apt-get install -y lxc-docker btrfs-tools lvm2 curl build-essential linux-image-extra-`uname -r` git-core pbuilder python-mock python-configobj python-support cdbs python-pip jq rsyslog-gnutls
sudo apt-get install -y lxc-docker btrfs-tools lvm2 curl build-essential linux-image-extra-`uname -r` git-core pbuilder python-mock python-configobj python-support cdbs python-pip jq openvpn
@@ -12,5 +12,11 @@
"pulse": {
"username": "{{pulse.username}}",
"password": "{{pulse.password}}"
},

"testdroid": {
"url": "{{testdroid.url}}",
"username": "{{testdroid.username}}",
"password": "{{testdroid.password}}"
}
}
@@ -36,6 +36,14 @@ module.exports = {
description: 'Location of private RSA key for docker-worker'
},

'vpnProfileLocation': {
description: 'Location of testdroid openvpn profile'
},

'vpnCredentialsLocation': {
description: 'Location of testdroid vpn credentials file'
},

'taskcluster.clientId': {
description: 'Taskcluster client id',
value: process.env.TASKCLUSTER_CLIENT_ID
@@ -46,6 +54,21 @@ module.exports = {
value: process.env.TASKCLUSTER_ACCESS_TOKEN
},

'testdroid.url': {
description: 'Testdroid Cloud url',
value: process.env.TESTDROID_URL
},

'testdroid.username': {
description: 'Testdroid Cloud username',
value: process.env.TESTDROID_USERNAME
},

'testdroid.password': {
description: 'Testdroid Cloud password',
value: process.env.TESTDROID_password
},

'statsd.prefix': {
description: 'statsd prefix token',
value: process.env.STATSD_PREFIX
@@ -44,6 +44,12 @@ module.exports = {
defaults: false,
module: require('./features/taskcluster_proxy')
},
testdroidProxy: {
title: 'Testdroid proxy service',
description: '',
defaults: false,
module: require('./features/testdroid_proxy')
},

artifacts: {
title: 'Artifact uploads',
@@ -0,0 +1,84 @@
var waitForPort = require('../wait_for_port');
var pullImage = require('../pull_image_to_stream');
var request = require('superagent-promise');
var debug = require('debug')('docker-worker:features:testdroid-proxy');

// Alias used to link the proxy.
var ALIAS = 'testdroid';
// Maximum time in MS to wait for socket to become available
var INIT_TIMEOUT = 5000;

function TestdroidProxy() {}

TestdroidProxy.prototype = {
/**
Docker container used in the linking process.
*/
container: null,

link: function* (task) {
var docker = task.runtime.docker;

// Image name for the proxy container.
var image = task.runtime.testdroidProxyImage;

yield pullImage(docker, image, process.stdout);

var cmd = [
'--cloud-url=' + task.runtime.testdroid.url,
'--username=' + task.runtime.testdroid.username,
'--password=' + task.runtime.testdroid.password
];

var envs = [];
if (process.env.DEBUG) {
envs.push('DEBUG=' + process.env.DEBUG);
}

// create the container.
this.container = yield docker.createContainer({
Image: image,
Env: envs,
Tty: true,
AttachStdin: false,
AttachStdout: true,
AttachStderr: true,

Cmd: cmd
});

this.container = docker.getContainer(this.container.id);

if (process.env.DEBUG) {
var stream = yield this.container.attach({stream: true, stdout: true, stderr: true});
stream.pipe(process.stdout);
}

yield this.container.start({});

var inspect = yield this.container.inspect();
var host = inspect.NetworkSettings.IPAddress;
var name = inspect.Name.slice(1)

try {
// wait for the initial server response...
debug('waiting for port');
yield waitForPort(host, '80', INIT_TIMEOUT);
} catch (e) {
throw new Error('Failed to initialize testdroid proxy service.')
}

this.host = host;
return [{ name: name, alias: ALIAS }];
},

killed: function*(task) {
debug('in testdroid proxy');
// attempt to release the device in case task did not do so. Calling release
// is idempotent.
var res = yield request.post('http://'+this.host+'/device/release').end();
task.runtime.gc.removeContainer(this.container.id);
}
};

module.exports = TestdroidProxy;
@@ -45,8 +45,8 @@
"openpgp": "0.8.1",
"promise": "^5.0.0",
"proxy": "^0.2.3",
"rimraf": "^2.2.8",
"readdirrsync": "0.0.3",
"rimraf": "^2.2.8",
"statsd-client": "0.0.15",
"superagent": "^0.18.0",
"superagent-promise": "^0.1.1",
@@ -60,8 +60,8 @@
"wordwrap": "0.0.2"
},
"devDependencies": {
"aws-sdk": "^2.0.7",
"aws-sdk-promise": "0.0.0",
"aws-sdk": "^2.1.5",
"aws-sdk-promise": "0.0.2",
"cli-color": "^0.3.2",
"co-fs": "^1.2.0",
"co-prompt": "^1.0.0",

0 comments on commit 02e4d84

Please sign in to comment.
You can’t perform that action at this time.