Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #13 from hayd/fix-cache
Browse files Browse the repository at this point in the history
Fix deno_dir caching of deps and gen
  • Loading branch information
hayd authored Dec 4, 2019
2 parents 6978e5f + 0c198a3 commit 48a382e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 13 deletions.
9 changes: 8 additions & 1 deletion runtime/artifacts
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 11 additions & 7 deletions runtime/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/remote.ts
Original file line number Diff line number Diff line change
@@ -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);
}
10 changes: 6 additions & 4 deletions tests/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
});
Expand Down Expand Up @@ -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
};
}
18 changes: 18 additions & 0 deletions tests/test_denodir.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 48a382e

Please sign in to comment.