From cd09b9f86d38ea2e6c49b01add0c3d0896a0f39f Mon Sep 17 00:00:00 2001 From: Patrick Brandt Date: Tue, 3 May 2016 14:43:35 -0400 Subject: [PATCH 1/4] refactoring dockerfile locations --- docker-compose.yml | 2 +- Dockerfile => dockerfiles/Dockerfile_python | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename Dockerfile => dockerfiles/Dockerfile_python (100%) diff --git a/docker-compose.yml b/docker-compose.yml index bc8a741..1e65ae9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,5 @@ lambda-python: - build: . + build: ./dockerfiles/Dockerfile_python container_name: python-lambda-local volumes: - ./:/usr/src diff --git a/Dockerfile b/dockerfiles/Dockerfile_python similarity index 100% rename from Dockerfile rename to dockerfiles/Dockerfile_python From 0dc9b135dc5dfbc2d0ec965a43ddcf1544cd9936 Mon Sep 17 00:00:00 2001 From: Patrick Brandt Date: Thu, 5 May 2016 15:08:23 -0400 Subject: [PATCH 2/4] WIP: lambda-node is functioning --- Dockerfile | 13 +++++++++++++ docker-compose.yml | 14 +++++++++++--- dockerfiles/node/Dockerfile | 13 +++++++++++++ .../{Dockerfile_python => python/Dockerfile} | 0 lambda_functions/hello/hello.js | 12 ++++++++++++ run_lambda_node.sh | 17 +++++++++++++++++ 6 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 Dockerfile create mode 100644 dockerfiles/node/Dockerfile rename dockerfiles/{Dockerfile_python => python/Dockerfile} (100%) create mode 100644 lambda_functions/hello/hello.js create mode 100644 run_lambda_node.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f8931e0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node:4 +RUN npm install -g lambda-local +# install image-magick +RUN apt-get update +RUN apt-get install -y imagemagick --fix-missing +# TODO: find all package.json files and npm install them globally +ADD ./run_lambda_node.sh /usr/bin +# fixing up line-endings in case this container is run in a Windows environment +RUN sed -i -e 's/\r$//' /usr/bin/run_lambda_node.sh +RUN chmod +x /usr/bin/run_lambda_node.sh +RUN mkdir -p /usr/src +VOLUME ["/usr/src/"] +ENTRYPOINT exec run_lambda_node.sh $FUNCTION_NAME docker \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 1e65ae9..4223001 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,14 @@ -lambda-python: - build: ./dockerfiles/Dockerfile_python - container_name: python-lambda-local +#lambda-python: +# build: . +# container_name: python-lambda-local +# volumes: +# - ./:/usr/src +# links: +# - dynamodb +# working_dir: /usr/src +lambda-node: + build: . + container_name: node-lambda-local volumes: - ./:/usr/src links: diff --git a/dockerfiles/node/Dockerfile b/dockerfiles/node/Dockerfile new file mode 100644 index 0000000..f8931e0 --- /dev/null +++ b/dockerfiles/node/Dockerfile @@ -0,0 +1,13 @@ +FROM node:4 +RUN npm install -g lambda-local +# install image-magick +RUN apt-get update +RUN apt-get install -y imagemagick --fix-missing +# TODO: find all package.json files and npm install them globally +ADD ./run_lambda_node.sh /usr/bin +# fixing up line-endings in case this container is run in a Windows environment +RUN sed -i -e 's/\r$//' /usr/bin/run_lambda_node.sh +RUN chmod +x /usr/bin/run_lambda_node.sh +RUN mkdir -p /usr/src +VOLUME ["/usr/src/"] +ENTRYPOINT exec run_lambda_node.sh $FUNCTION_NAME docker \ No newline at end of file diff --git a/dockerfiles/Dockerfile_python b/dockerfiles/python/Dockerfile similarity index 100% rename from dockerfiles/Dockerfile_python rename to dockerfiles/python/Dockerfile diff --git a/lambda_functions/hello/hello.js b/lambda_functions/hello/hello.js new file mode 100644 index 0000000..1f07e8b --- /dev/null +++ b/lambda_functions/hello/hello.js @@ -0,0 +1,12 @@ +'use strict'; +console.log('Loading function'); + +exports.hello_handler = (event, context, callback) => { + //console.log('Received event:', JSON.stringify(event, null, 2)); + console.log('first name =', event.first_name); + console.log('last name =', event.last_name); + //callback(null, event.key1); // Echo back the first key value + // callback('Something went wrong'); + + context.done(null, 'great!'); +}; \ No newline at end of file diff --git a/run_lambda_node.sh b/run_lambda_node.sh new file mode 100644 index 0000000..a2b9c62 --- /dev/null +++ b/run_lambda_node.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +rm -rf /local_build/$1 +mkdir -p /local_build/$1 + +cp /usr/src/lambda_functions/$1/* /local_build/$1 +cp /usr/src/local_events/$1.json /local_build/$1 +cp /usr/src/config/* /local_build/$1 +cp /usr/src/lib/* /local_build/$1 + +cd /local_build/$1 +if [ -e "package.json" ] ; then + npm install . +fi + +echo "executing $1 function locally:" +lambda-local -l $1.js -h $1_handler -e $1.json \ No newline at end of file From 2a232a2cd55faf7ec4ca0b06fd7db7ea8241b9e8 Mon Sep 17 00:00:00 2001 From: Patrick Brandt Date: Thu, 5 May 2016 15:24:08 -0400 Subject: [PATCH 3/4] python and node lambda side-by-side --- docker-compose.yml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 11183dd..d9529e8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,19 @@ version: '2' services: - #lambda-python: - # build: . - # container_name: python-lambda-local - # volumes: - # - ./:/usr/src - # links: - # - dynamodb - # working_dir: /usr/src + lambda-python: + build: + context: . + dockerfile: dockerfiles/python/Dockerfile + container_name: python-lambda-local + volumes: + - ./:/usr/src + links: + - dynamodb + working_dir: /usr/src lambda-node: - build: . + build: + context: . + dockerfile: dockerfiles/node/Dockerfile container_name: node-lambda-local volumes: - ./:/usr/src From 7035407d556926352ee2ef5b7ccc601cbc843eec Mon Sep 17 00:00:00 2001 From: Patrick Brandt Date: Thu, 5 May 2016 15:40:42 -0400 Subject: [PATCH 4/4] refactoring dockerfile locations --- docker-compose.yml | 4 ++-- dockerfiles/{node/Dockerfile => Dockerfile_node} | 0 dockerfiles/{python/Dockerfile => Dockerfile_python} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename dockerfiles/{node/Dockerfile => Dockerfile_node} (100%) rename dockerfiles/{python/Dockerfile => Dockerfile_python} (100%) diff --git a/docker-compose.yml b/docker-compose.yml index d9529e8..4c57152 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: lambda-python: build: context: . - dockerfile: dockerfiles/python/Dockerfile + dockerfile: dockerfiles/python/Dockerfile_python container_name: python-lambda-local volumes: - ./:/usr/src @@ -13,7 +13,7 @@ services: lambda-node: build: context: . - dockerfile: dockerfiles/node/Dockerfile + dockerfile: dockerfiles/node/Dockerfile_node container_name: node-lambda-local volumes: - ./:/usr/src diff --git a/dockerfiles/node/Dockerfile b/dockerfiles/Dockerfile_node similarity index 100% rename from dockerfiles/node/Dockerfile rename to dockerfiles/Dockerfile_node diff --git a/dockerfiles/python/Dockerfile b/dockerfiles/Dockerfile_python similarity index 100% rename from dockerfiles/python/Dockerfile rename to dockerfiles/Dockerfile_python