diff --git a/src/dockerproxy.js b/src/dockerproxy.js index e1db0005b..81bae75c3 100644 --- a/src/dockerproxy.js +++ b/src/dockerproxy.js @@ -80,8 +80,8 @@ function containersCreate(req, res, next) { let binds = []; for (let bind of (req.body.HostConfig.Binds || [])) { - if (bind.startsWith('/app/data')) binds.push(bind.replace(new RegExp('^/app/data'), appDataDir)); - + if (bind.startsWith(appDataDir)) binds.push(bind); // eclipse will inspect docker to find out the host folders and pass that to child containers + else if (bind.startsWith('/app/data')) binds.push(bind.replace(new RegExp('^/app/data'), appDataDir)); else binds.push(`${dockerDataDir}/${bind}`); } @@ -99,7 +99,7 @@ function containersCreate(req, res, next) { function process(req, res, next) { // we have to rebuild the body since we consumed in in the parser - if (req.body) { + if (Object.keys(req.body).length !== 0) { let plainBody = JSON.stringify(req.body); req.dockerRequest.setHeader('Content-Length', Buffer.byteLength(plainBody)); req.dockerRequest.end(plainBody); @@ -119,6 +119,9 @@ function start(callback) { router.post('/:version/containers/create', containersCreate); let proxyServer = express(); + + if (config.TEST) proxyServer.use(function (req, res, next) { console.log('Proxying: ' + req.method, req.url); next(); }) + proxyServer.use(authorizeApp) .use(attachDockerRequest) .use(json) diff --git a/src/test/dockerproxy-test.js b/src/test/dockerproxy-test.js index 48c6784a2..67dc2b2dc 100644 --- a/src/test/dockerproxy-test.js +++ b/src/test/dockerproxy-test.js @@ -14,11 +14,13 @@ var dockerProxy = require('../dockerproxy.js'), const DOCKER = `docker -H tcp://localhost:${config.get('dockerProxyPort')} `; describe('Cloudron', function () { - this.timeout(1000000); - before(dockerProxy.start); after(dockerProxy.stop); + // uncomment this to run the proxy for manual testing + // this.timeout(1000000); + // it('wait', function (done) {} ); + it('can get info', function (done) { exec(DOCKER + ' info', function (error, stdout, stderr) { expect(error).to.be(null); @@ -69,4 +71,26 @@ describe('Cloudron', function () { }); }); }); + + it('can use PUT to upload archive into a container', function (done) { + exec(`${DOCKER} run -d ubuntu "bin/bash" "-c" "while true; do echo 'perpetual walrus'; sleep 1; done"`, function (error, stdout, stderr) { + expect(error).to.be(null); + expect(stderr).to.be.empty(); + + var containerId = stdout.slice(0, -1); // removes the trailing \n + + exec(`${DOCKER} cp -a ${__dirname}/proxytestarchive.tar ${containerId}:/tmp/`, function (error, stdout, stderr) { + expect(error).to.be(null); + expect(stderr).to.be.empty(); + expect(stdout).to.be.empty(); + + exec(`${DOCKER} rm -f ${containerId}`, function (error, stdout, stderr) { + expect(error).to.be(null); + expect(stderr).to.be.empty(); + + done(); + }); + }); + }); + }); }); diff --git a/src/test/proxytestarchive.tar b/src/test/proxytestarchive.tar new file mode 100644 index 000000000..7f11df6b7 Binary files /dev/null and b/src/test/proxytestarchive.tar differ