Skip to content

Commit

Permalink
Add support for DENO_DIR environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
hayd committed Nov 5, 2019
1 parent 204b1d5 commit 0847175
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion _dockerhub-deploy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const DENO_VERSION = '0.23.0';

console.log("Building and pushing", DENO_VERSION);
for (const name of ["alpine", "debian", "ubuntu"]) {
for (const name of ["alpine", "debian", "ubuntu", "amazonlinux-1"]) {
const p1 = Deno.run({
args: [
"docker",
Expand Down
1 change: 1 addition & 0 deletions amazonlinux-1.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ RUN curl -fsSL https://github.com/denoland/deno/releases/download/v${DENO_VERSIO
&& rm deno.tar.gz

RUN cp /bin/gn /deno/core/libdeno/buildtools/linux64/gn
RUN rm /deno/third_party/prebuilt/linux64/sccache

RUN yum install -y gcc-c++ libatomic
RUN echo "INPUT ( /usr/lib64/libatomic.so.1.2.0 )" \
Expand Down
27 changes: 15 additions & 12 deletions aws-lambda/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ HANDLER_FILE=$(echo "$_HANDLER" | cut -d. -f1)

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'}

# TODO support bundle/js etc.
HANDLER_FILE=${HANDLER_FILE}.ts

# If we fail prior to the handler loop we post an init error.
function error {
echo "error:" $1
Expand All @@ -30,25 +37,25 @@ function investigate {
$SCRIPT_DIR/amz-deno eval 'Deno.version.deno' \
|| error "bad amz-deno executable"

[ -f $LAMBDA_TASK_ROOT/$HANDLER_FILE.ts ] \
|| error "missing expected handler file '$HANDLER_FILE.ts'"
[ -f $LAMBDA_TASK_ROOT/$HANDLER_FILE ] \
|| error "missing expected handler file '$HANDLER_FILE'"

DENO_DIR=/tmp/deno_dir NO_COLOR=true $SCRIPT_DIR/amz-deno fetch $LAMBDA_TASK_ROOT/$HANDLER_FILE.ts \
|| error "unable to compile $HANDLER_FILE.ts"
DENO_DIR=/tmp/deno_dir NO_COLOR=true $SCRIPT_DIR/amz-deno fetch $LAMBDA_TASK_ROOT/$HANDLER_FILE \
|| error "unable to compile $HANDLER_FILE"

echo "
import { $HANDLER_NAME } from '$LAMBDA_TASK_ROOT/$HANDLER_FILE.ts';
import { $HANDLER_NAME } from '$LAMBDA_TASK_ROOT/$HANDLER_FILE';
" > /tmp/runtime-test.js
DENO_DIR=/tmp/deno_dir NO_COLOR=true $SCRIPT_DIR/amz-deno fetch /tmp/runtime-test.js 2> /dev/null \
|| error "$HANDLER_FILE.ts must export a function named '$HANDLER_NAME'"
|| error "$HANDLER_FILE must export a function named '$HANDLER_NAME'"

# perhaps a bug in bootstrap?
}

# Note: This is a js file to avoid a runtime compilation step.
# Hopefully $HANDLER_FILE.ts's compilation is cached in DENO_DIR.
# Hopefully $HANDLER_FILE's compilation is cached in DENO_DIR.
echo "
import { $HANDLER_NAME } from '$LAMBDA_TASK_ROOT/$HANDLER_FILE.ts';
import { $HANDLER_NAME } from '$LAMBDA_TASK_ROOT/$HANDLER_FILE';
const INVOCATION = '${API_ROOT}invocation/';
while (true) {
const next = await fetch(INVOCATION + 'next');
Expand Down Expand Up @@ -111,10 +118,6 @@ while (true) {
}
" > /tmp/runtime.js

# 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'}

# We copy DENO_DIR into a writable directory (/tmp/deno_dir)
# and expand DENO_DIR/LAMBDA_TASK_ROOT to match the new location ($LAMBDA_TASK_ROOT).
mkdir -p /tmp/deno_dir/gen/file$LAMBDA_TASK_ROOT \
Expand Down

0 comments on commit 0847175

Please sign in to comment.