Last active
March 16, 2016 23:43
-
-
Save santigimeno/4b534c2c2f77f3d90b29 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
FROM debian:wheezy | |
MAINTAINER Santiago Gimeno <[email protected]> | |
# Add ionpad development-tools repository | |
RUN echo "deb http://http.us.debian.org/debian wheezy main non-free contrib" >> /etc/apt/sources.list && \ | |
echo "deb http://snapshot.debian.org/archive/debian/20110416T035407Z/ stable main contrib non-free" >> /etc/apt/sources.list.d/snapshots.list && \ | |
echo "deb http://snapshot.debian.org/archive/debian/20110416T035407Z/ testing main contrib non-free" >> /etc/apt/sources.list.d/snapshots.list && \ | |
echo "deb http://snapshot.debian.org/archive/debian/20110416T035407Z/ unstable main contrib non-free" >> /etc/apt/sources.list.d/snapshots.list && \ | |
echo "deb http://snapshot.debian.org/archive/debian/20110416T035407Z/ experimental main contrib non-free" >> /etc/apt/sources.list.d/snapshots.list && \ | |
echo "Acquire::Check-Valid-Until \"0\";" >> /etc/apt/apt.conf.d/10no--check-valid-until | |
RUN apt-get upgrade -y --force-yes | |
RUN apt-get update && \ | |
apt-get install -y --force-yes \ | |
curl \ | |
vim \ | |
nodejs=0.2.0-1 |
This file contains hidden or 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
// http://groups.google.com/group/nodejs/browse_thread/thread/f66cd3c960406919 | |
var assert = require('assert'); | |
var http = require('http'), | |
cp = require('child_process'); | |
if (process.argv[2] === 'request') { | |
var client = http.createClient(12345, '127.0.0.1'); | |
var request = client.request('GET', | |
'/', | |
{ host: '127.0.0.1'}); | |
request.on('response', function (response) { | |
response.on('data', function(d) { | |
process.stdout.write(d); | |
}); | |
}); | |
request.end(); | |
return; | |
} | |
if (process.argv[2] === 'shasum') { | |
var crypto = require('crypto'); | |
var shasum = crypto.createHash('sha1'); | |
var stdin = process.openStdin(); | |
stdin.on('data', function(d) { | |
shasum.update(d); | |
}); | |
stdin.on('end', function() { | |
process.stdout.write(shasum.digest('hex')); | |
}); | |
return; | |
} | |
var filename = require('path').join('/tmp', 'big'); | |
function executeRequest (cb) { | |
cp.exec([ process.execPath, | |
__filename, | |
'request', | |
'|', | |
process.execPath, | |
__filename, | |
'shasum' ].join(' '), | |
function (err, stdout, stderr) { | |
if (err) throw err; | |
assert.equal('8c206a1a87599f532ce68675536f0b1546900d7a', stdout.slice(0, 40)); | |
console.log("got the correct response"); | |
cb(); | |
}); | |
} | |
cp.exec('dd if=/dev/zero of=' + filename + ' bs=1024 count=10240', | |
function (err, stdout, stderr) { | |
if (err) throw err; | |
var server = http.createServer(function (req, res) { | |
res.writeHead(200); | |
// Create the subprocess | |
var cat = cp.spawn('cat', [filename]); | |
// Stream the data through to the response as binary chunks | |
cat.stdout.on('data', function (data) { | |
res.write(data); | |
}); | |
// End the response on exit (and log errors) | |
cat.on('exit', function (code) { | |
if (code !== 0) { | |
console.error('subprocess exited with code ' + code); | |
exit(1); | |
} | |
res.end(); | |
}); | |
}); | |
server.listen(12345, function() { | |
console.log('Server running at http://localhost:8080'); | |
executeRequest(function() { | |
server.close(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment