-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:humanmade/node-tachyon
Showing
2 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
FROM ubuntu:latest | ||
FROM ubuntu:trusty | ||
RUN apt-get update && apt-get install -y curl build-essential python2.7 | ||
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - | ||
RUN apt-get update && apt-get -y install nodejs npm | ||
RUN apt-get update && apt-get -y install nodejs | ||
RUN ln -sf /usr/bin/python2.7 /usr/bin/python | ||
CMD cd /build ; npm install --production |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const http = require('http'); | ||
const url = require('url'); | ||
const querystring = require('querystring'); | ||
const { | ||
spawn | ||
} = require('child_process'); | ||
|
||
|
||
http.createServer(function (request, response) { | ||
const bucket = 'hmn-uploads-eu'; | ||
const region = 'eu-west-1'; | ||
const task = __dirname; | ||
|
||
const pathName = url.parse(request.url).pathname; | ||
const query = url.parse(request.url).query; | ||
const args = { | ||
path: pathName, | ||
queryStringParameters: querystring.parse( query ), | ||
headers: request.headers, | ||
}; | ||
const childArgs = ['run', '--rm', '-e', `S3_BUCKET=${ bucket }`, '-e', `S3_REGION=${ region }`, '-v', `${ task }:/var/task`, 'lambci/lambda:nodejs6.10', 'lambda-handler.handler', JSON.stringify(args)]; | ||
const child = spawn('docker', childArgs); | ||
var stdout = ''; | ||
child.stdout.on('data', data => stdout += data); | ||
child.stderr.on('data', data => console.warn(String(data))); | ||
child.on('close', function () { | ||
const lambdaExec = JSON.parse(stdout); | ||
if ( lambdaExec.errorMessage ) { | ||
response.writeHead( 500 ); | ||
response.write(JSON.stringify( lambdaExec ) ); | ||
response.end(); | ||
return; | ||
} | ||
response.writeHead(lambdaExec.statusCode, lambdaExec.headers); | ||
response.write(Buffer.from(lambdaExec.body, 'base64')); | ||
response.end(); | ||
}); | ||
}).listen(7000); |