diff --git a/runtime/artifacts b/runtime/artifacts index 388875df..23e111f2 100644 --- a/runtime/artifacts +++ b/runtime/artifacts @@ -10,8 +10,15 @@ DENO_DIR=.deno_dir ./amz-deno fetch hello.ts # assert the required files are going to be present in the zip ls amz-deno &> /dev/null && ls bootstrap &> /dev/null && ls hello.ts &> /dev/null -cp -R .deno_dir/gen/file/$PWD/ .deno_dir/LAMBDA_TASK_ROOT +cp -R .deno_dir/gen/file/$PWD/. .deno_dir/LAMBDA_TASK_ROOT zip -qq deno-lambda-layer.zip -x '.deno_dir/gen/file/*' -r .deno_dir amz-deno bootstrap hello.ts zip -qq deno-lambda-example.zip -x '.deno_dir/gen/file/*' -r .deno_dir hello.ts DENO_DIR=.deno_dir ./amz-deno bundle bundle.ts bundle.bundle.js + +rm -rf .deno_dir +mkdir -p .deno_dir/deps/https/deno.land/x/lambda/ +cp mod.ts .deno_dir/deps/https/deno.land/x/lambda/mod.ts +DENO_DIR=.deno_dir ./amz-deno fetch remote.ts +cp -R .deno_dir/gen/file/$PWD/. .deno_dir/LAMBDA_TASK_ROOT +zip -qq remote.zip -x '.deno_dir/gen/file/*' -r .deno_dir remote.ts diff --git a/runtime/bootstrap b/runtime/bootstrap index c7185ecf..e201b963 100755 --- a/runtime/bootstrap +++ b/runtime/bootstrap @@ -9,7 +9,10 @@ API_ROOT=http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/ # If this ENV variable is set then copy that directory as DENO_DIR (default = .deno_dir). # Note: For permissions reasons we need the actual DENO_DIR to be somewhere in /tmp. -DENO_DIR=${DENO_DIR-'.deno_dir'} +DENO_DIR=${DENO_DIR-.deno_dir} +if [[ -z "$DENO_DIR" ]]; then + DENO_DIR=.deno_dir +fi # whether to use ts, js, bundle.js, etc. HANDLER_EXT=${HANDLER_EXT-'ts'} @@ -121,14 +124,15 @@ while (true) { mkdir -p /tmp/deno_dir/gen/file$LAMBDA_TASK_ROOT # We cp first from the deno-lambda-layer. -cp -R /opt/.deno_dir/gen /tmp/deno_dir/gen &> /dev/null \ - && cp -R /opt/.deno_dir/deps /tmp/deno_dir/deps &> /dev/null \ - && cp -R /opt/.deno_dir/LAMBDA_TASK_ROOT/ /tmp/deno_dir/gen/file$LAMBDA_TASK_ROOT &> /dev/null \ +cp -R /opt/.deno_dir/gen/. /tmp/deno_dir/gen &> /dev/null \ + && cp -R /opt/.deno_dir/deps/. /tmp/deno_dir/deps &> /dev/null \ + && cp -R /opt/.deno_dir/LAMBDA_TASK_ROOT/. /tmp/deno_dir/gen/file$LAMBDA_TASK_ROOT &> /dev/null \ || true # Then we overwrite with from the DENO_DIR in the function code. -cp -R $LAMBDA_TASK_ROOT/$DENO_DIR/gen /tmp/deno_dir/gen &> /dev/null \ - && cp -R $LAMBDA_TASK_ROOT/$DENO_DIR/deps /tmp/deno_dir/deps &> /dev/null \ - && cp -R $LAMBDA_TASK_ROOT/$DENO_DIR/LAMBDA_TASK_ROOT/ /tmp/deno_dir/gen/file$LAMBDA_TASK_ROOT &> /dev/null \ +cp -R $LAMBDA_TASK_ROOT/$DENO_DIR/gen/. /tmp/deno_dir/gen &> /dev/null \ + && cp -R $LAMBDA_TASK_ROOT/$DENO_DIR/deps/. /tmp/deno_dir/deps &> /dev/null \ + && cp -R $LAMBDA_TASK_ROOT/$DENO_DIR/gen/. /tmp/deno_dir/gen &> /dev/null \ + && cp -R $LAMBDA_TASK_ROOT/$DENO_DIR/LAMBDA_TASK_ROOT/. /tmp/deno_dir/gen/file$LAMBDA_TASK_ROOT &> /dev/null \ || echo "warn: unable to import '$DENO_DIR/' as DENO_DIR" DENO_DIR=/tmp/deno_dir NO_COLOR=true $SCRIPT_DIR/amz-deno run --allow-net --allow-read --allow-env /tmp/runtime.js \ diff --git a/tests/Dockerfile b/tests/Dockerfile index bb10d227..ab4b6602 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -28,7 +28,7 @@ RUN deno fetch /src/tests/deps.ts ADD hello.ts /src/runtime/hello.ts ADD hello.ts /src/tests/hello.ts ADD tests/bundle.ts /src/runtime/bundle.ts - +ADD tests/remote.ts /src/runtime/remote.ts ADD runtime /src/runtime WORKDIR /src/runtime diff --git a/tests/remote.ts b/tests/remote.ts new file mode 100644 index 00000000..b3d9591c --- /dev/null +++ b/tests/remote.ts @@ -0,0 +1,6 @@ +import { Context, Event } from "https://deno.land/x/lambda/mod.ts"; +import { pad } from "https://deno.land/std/strings/pad.ts"; + +export function handler(event: Event, context: Context) { + return pad("deno", 5); +} diff --git a/tests/server.ts b/tests/server.ts index 1038a4ab..2e9d3f39 100644 --- a/tests/server.ts +++ b/tests/server.ts @@ -12,10 +12,13 @@ function bootstrap(testJson) { ? "/var/task/bootstrap" : "/opt/bootstrap"; + if (!testJson.env.DENO_DIR) { + testJson.env.DENO_DIR = ""; + } return Deno.run({ args: [bootstrapScript], stdout: "piped", - stderr: "piped", // comment this out to debug + // stderr: "piped", // comment this out to debug env: testJson.env, cwd: "/var/task" }); @@ -73,12 +76,11 @@ export async function serveEvents(testJson) { } } } - const out = await read(p.stdout); + /// const out = await read(p.stdout); p.kill(9); s.close(); await p.status(); return { - responses, - out + responses: responses }; } diff --git a/tests/test_denodir.json b/tests/test_denodir.json new file mode 100644 index 00000000..dff12e25 --- /dev/null +++ b/tests/test_denodir.json @@ -0,0 +1,18 @@ +{ + "env": { + "_HANDLER": "remote.handler" + }, + "events": [{ "hello": "deno" }, { "hello": "again" }], + "expected": [ + { + "status": "ok", + "content": "\" deno\"" + }, + { + "status": "ok", + "content": "\" deno\"" + } + ], + "files": "remote.zip", + "layer": "deno-lambda-layer.zip" +}