Skip to content

Commit

Permalink
Merge pull request #248 from denoland/cleanup
Browse files Browse the repository at this point in the history
chore: cleanup and setup CI
  • Loading branch information
igorzi committed Feb 9, 2024
2 parents e464ccf + 8b219f0 commit b8b90fd
Show file tree
Hide file tree
Showing 40 changed files with 50 additions and 2,682 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: |
echo existing=${{ steps.version.outputs.existing }}
echo latest=${{ steps.version.outputs.latest }}
sed -i "s/${{ steps.version.outputs.existing }}/${{ steps.version.outputs.latest }}/" tests/*.json tests/Dockerfile example-aws-cdk/cdk/example-aws-cdk-stack.ts example-serverless/serverless.yml example-sam/template.yml docker/base.dockerfile
sed -i "s/${{ steps.version.outputs.existing }}/${{ steps.version.outputs.latest }}/" tests/*.json tests/Dockerfile docker/base.dockerfile
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
id: cpr
Expand Down
44 changes: 14 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,17 @@ jobs:
docker cp extract:/src/runtime/deno-lambda-layer.zip deno-lambda-layer.zip
docker cp extract:/src/runtime/deno-lambda-example.zip deno-lambda-example.zip
test_example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: denoland/setup-deno@main
- name: start a local dynamodb
run: |
mkdir dyno
curl -q https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz | tar --directory=dyno -zxf -
java -D"java.library.path=$DIR/DynamoDBLocal_lib" -jar "dyno/DynamoDBLocal.jar" -sharedDb &
sleep 4.2
- name: run serverless tests
working-directory: example-serverless
run: |
AWS_ACCESS_KEY_ID=fakeMyKeyId AWS_SECRET_ACCESS_KEY=fakeSecretAccessKey AWS_DEFAULT_REGION=local deno test --allow-env --allow-net test.ts
test_docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build Docker Image
run: |
docker build -f docker/base.dockerfile -t hayd/deno-lambda .
- name: Test Docker Example
run: |
cd example-docker-container
docker build -t example .
docker run -p=9000:8080 example &
sleep 5
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"payload":"hello world!"}'
# test_docker:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - name: Build Docker Image
# run: |
# docker build -f docker/base.dockerfile -t denoland/deno-lambda .
# - name: Test Docker Example
# run: |
# cd example-docker-container
# docker build -t example .
# docker run -p=9000:8080 example &
# sleep 5
# curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"payload":"hello world!"}'
3 changes: 0 additions & 3 deletions .github/workflows/fmt_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ jobs:
- name: Run lint
run: |
deno lint --unstable hello.ts tests
deno lint --unstable example-aws-cdk --ignore=example-aws-cdk/node_modules
deno lint --unstable example-sam --ignore=example-sam/.aws-sam
deno lint --unstable example-serverless --ignore=example-serverless/node_modules,example-serverless/.deno_dir
- name: Sanity check types
run: |
deno run runtime/mod.ts
41 changes: 4 additions & 37 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,24 @@ jobs:
docker cp extract:/src/runtime/deno-lambda-layer.zip deno-lambda-layer.zip
docker cp extract:/src/runtime/deno-lambda-example.zip deno-lambda-example.zip
- name: Verify Release Version Matches Deno Version
if: startsWith(github.ref, 'refs/tags/') && github.repository == 'hayd/deno-lambda'
if: startsWith(github.ref, 'refs/tags/') && github.repository == 'denoland/deno-lambda'
run: |
export DENO_LAMBDA_VERSION=$(echo $GITHUB_REF | tr / '\n' | tail -n 1)
docker run -e DENO_LAMBDA_VERSION=$DENO_LAMBDA_VERSION test-runner _deno test --allow-env /src/tests/version_check.ts
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/') && github.repository == 'hayd/deno-lambda'
if: startsWith(github.ref, 'refs/tags/') && github.repository == 'denoland/deno-lambda'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
deno-lambda-layer.zip
deno-lambda-example.zip
draft: true
- name: Publish to SAR
if: startsWith(github.ref, 'refs/tags/') && github.repository == 'hayd/deno-lambda'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
DENO_LAMBDA_BUCKET: ${{ secrets.DENO_LAMBDA_BUCKET }}
run: |
export DENO_LAMBDA_VERSION=$(echo $GITHUB_REF | tr / '\n' | tail -n 1)
echo tag: $DENO_LAMBDA_VERSION
# FIXME: Installation of sam is fiddly.
export DEBIAN_FRONTEND=noninteractive
sudo apt -qq update &> /dev/null
sudo apt -qq install -y awscli python3-setuptools python3-testresources &> /dev/null
pip3 -q install -U --force pip
export PATH=/home/runner/.local/bin:$PATH
export SAM_CLI_TELEMETRY=1
python3 -m pip -q install --user aws-sam-cli
export AWS_EC2_METADATA_DISABLED=true
aws s3 cp --quiet deno-lambda-layer.zip s3://$DENO_LAMBDA_BUCKET/deno-lambda-layer_$DENO_LAMBDA_VERSION.zip --acl public-read
aws s3 cp --quiet deno-lambda-example.zip s3://$DENO_LAMBDA_BUCKET/deno-lambda-example_$DENO_LAMBDA_VERSION.zip --acl public-read
echo ---
cd SAR
sed -i -e s/DENO_LAMBDA_BUCKET/$DENO_LAMBDA_BUCKET/g template.yml
sed -i -e s/DENO_LAMBDA_VERSION/$DENO_LAMBDA_VERSION/g template.yml
cat template.yml
sam publish --region us-east-1
echo ---
cd blueprint
sed -i -e s/DENO_LAMBDA_BUCKET/$DENO_LAMBDA_BUCKET/g template.yml
sed -i -e s/DENO_LAMBDA_VERSION/$DENO_LAMBDA_VERSION/g template.yml
cat template.yml
sam publish --region us-east-1
echo ---

publish_deno_lambda:
# FIXME prefer to use no_push (in with block) instead of if.
if: startsWith(github.ref, 'refs/tags/') && github.repository == 'hayd/deno-lambda'
if: startsWith(github.ref, 'refs/tags/') && github.repository == 'denoland/deno-lambda'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand All @@ -78,7 +45,7 @@ jobs:
- name: Publish Deno Lambda
uses: elgohr/Publish-Docker-Github-Action@3.02
with:
name: "hayd/deno-lambda"
name: "denoland/deno-lambda"
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
dockerfile: docker/base.dockerfile
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2019- Andy Hayden
Copyright 2018-2024 the Deno authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
38 changes: 10 additions & 28 deletions QUICK-START.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
For an even quicker start, deploy the example application
[deno-hello-world](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:390065572566:applications~deno-hello-world)
sample SAR application.

## Quick Start in the AWS console

1. Visit the
[deno SAR application](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:390065572566:applications~deno)
and click the Deploy button:

<img width="1301" alt="Screen Shot 2020-02-17 at 14 42 36" src="https://user-images.githubusercontent.com/1931852/74705321-50da1500-51c8-11ea-8709-afc3d46dde8c.png">

This will take you to your preferred region to Deploy:
From the [AWS console](https://console.aws.amazon.com/lambda/):

<img width="1249" alt="Screen Shot 2020-02-17 at 14 43 05" src="https://user-images.githubusercontent.com/1931852/74705319-50417e80-51c8-11ea-8082-329ff3e7ea9f.png">
1. Download zip files from the
[releases](https://github.com/denoland/deno-lambda/releases) page.

2. Now the serverless repo will `CREATE` the deno layer:
2. Create a _layer_ and upload `deno-lambda-layer.zip`.

<img width="1250" alt="Screen Shot 2020-02-17 at 14 43 44" src="https://user-images.githubusercontent.com/1931852/74705318-4e77bb00-51c8-11ea-8d4d-3b3282adb2ea.png">
<img width="828" alt="Create layer" src="https://user-images.githubusercontent.com/1931852/68455786-0b618100-01b1-11ea-988a-ba3a5810a8d5.png">

Click on "View Cloudformation Stack":
<img width="1122" alt="Layer created" src="https://user-images.githubusercontent.com/1931852/68455785-0b618100-01b1-11ea-9686-8ebefe3b00ff.png">

<img width="1157" alt="Screen Shot 2020-02-17 at 14 46 52" src="https://user-images.githubusercontent.com/1931852/74705317-4d468e00-51c8-11ea-845c-1a2e5bf8bb3d.png">
Note its Version ARN.

On the "Outputs" tab copy the `LayerArn`.

3. Visit the [lambda console](https://console.aws.amazon.com/lambda/). Create a
lambda function from scratch with runtime "provide your own bootstrap".
3. Create a lambda function from scratch with runtime "provide your own
bootstrap".

<img width="1295" alt="Create function" src="https://user-images.githubusercontent.com/1931852/68455784-0ac8ea80-01b1-11ea-93ba-8c64a4e487e7.png">

Expand All @@ -35,17 +24,10 @@ On the "Outputs" tab copy the `LayerArn`.

<img width="820" alt="Add layer to function" src="https://user-images.githubusercontent.com/1931852/68455782-0ac8ea80-01b1-11ea-9a1b-0a87f8052c25.png">

5. Upload the latest
[deno-lambda-example.zip](https://github.com/hayd/deno-lambda/releases) as
function code.
5. Upload deno-lambda-example.zip as function code.

<img width="1300" alt="Upload function code" src="https://user-images.githubusercontent.com/1931852/68455780-0ac8ea80-01b1-11ea-87ee-164abe110c77.png">

6. "Save". "Test" (use the default event).

<img width="1277" alt="Execution successful" src="https://user-images.githubusercontent.com/1931852/70288824-bb61e400-1787-11ea-95a6-61bb3a260c05.png">

---

_To "roll your own", without SAR, see the earlier version of this
[QUICK-START.md](https://github.com/hayd/deno-lambda/blob/56d8b4e4030c0096f7b5c589ba1194201e2f97dc/QUICK-START.md)._
54 changes: 8 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
A [deno](https://github.com/denoland/deno/) runtime for AWS Lambda.

_Deploy deno code via
[SAR application](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:390065572566:applications~deno)
(see
[quick start](https://github.com/hayd/deno-lambda/blob/master/QUICK-START.md)),
[SAM](https://github.com/hayd/deno-lambda/tree/master/example-sam),
[serverless](https://github.com/hayd/deno-lambda/tree/master/example-serverless),
or bundle it yourself._
[docker container](https://github.com/denoland/deno-lambda/tree/master/example-docker-container)
or
[bundle it yourself](https://github.com/denoland/deno-lambda/blob/master/QUICK-START.md)._

![ci status](https://github.com/hayd/deno-lambda/workflows/Test/badge.svg?branch=master)
![ci status](https://github.com/denoland/deno-lambda/workflows/Test/badge.svg?branch=master)

Define a handler function, for example:

Expand Down Expand Up @@ -76,26 +73,8 @@ of an `APIGatewayProxyEventV2`._

## How to deploy

The recommended way to deploy is to use the
[SAR application](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:390065572566:applications~deno)
and either reference the outputted `LayerArn` as a layer in your function.

- :bowtie:
[SAR application](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:390065572566:applications~deno)
(see
[quick start](https://github.com/hayd/deno-lambda/blob/master/QUICK-START.md))
- [SAM example](https://github.com/hayd/deno-lambda/tree/master/example-sam)
- [Serverless example](https://github.com/hayd/deno-lambda/tree/master/example-serverless)
(feat. [Dynamodb](https://github.com/chiefbiiko/dynamodb/))
- [AWS CDK example](https://github.com/hayd/deno-lambda/tree/master/example-aws-cdk)
- [Docker container example](https://github.com/hayd/deno-lambda/tree/master/example-docker-container)
- Zipped source example,
[`deno-lambda-example.zip`](https://github.com/hayd/deno-lambda/releases/),
see [bundling-code](#bundling-code) section.

_See
[earlier version of quick start](https://github.com/hayd/deno-lambda/blob/56d8b4e4030c0096f7b5c589ba1194201e2f97dc/QUICK-START.md)
for a walkthrough of how to bundle yourself._
- [Docker container example](https://github.com/denoland/deno-lambda/tree/master/example-docker-container)
- [Bundle yourself](https://github.com/denoland/deno-lambda/blob/master/QUICK-START.md)

See the [deno_dir-remapping](#deno_dir-remapping) section for how to include the
correct DENO_DIR files to avoid any runtime compilation.
Expand Down Expand Up @@ -167,29 +146,12 @@ cp -R .deno_dir/gen/file/$PWD/ .deno_dir/LAMBDA_TASK_ROOT
zip lambda.zip -x '.deno_dir/gen/file/*' -r .deno_dir hello.ts # other source files
```

### Serverless pre-deploy remapping

In a `serverless.yml` this can be automatically prior to each upload using the
[`serverless-scriptable-plugin`](https://www.npmjs.com/package/serverless-scriptable-plugin):

```
plugins:
- serverless-scriptable-plugin
custom:
scriptHooks:
before:package:createDeploymentArtifacts: DENO_DIR=.deno_dir deno cache api/candidate.ts && cp -R .deno_dir/gen/file/$PWD/ .deno_dir/LAMBDA_TASK_ROOT
```

See
[`example-serverless/serverless.yml`](https://github.com/hayd/deno-lambda/blob/master/example-serverless/serverless.yml).

## Testing locally with docker-lambda

You can execute deno-lambda locally using
[docker-lambda](https://github.com/lambci/docker-lambda). First, unzip the
[deno-lambda-layer.zip](https://github.com/hayd/deno-lambda/releases) layer into
a directory.
[deno-lambda-layer.zip](https://github.com/denoland/deno-lambda/releases) layer
into a directory.

Now, from the directory of your application:

Expand Down
34 changes: 0 additions & 34 deletions SAR/README.md

This file was deleted.

36 changes: 0 additions & 36 deletions SAR/blueprint/README.md

This file was deleted.

Loading

0 comments on commit b8b90fd

Please sign in to comment.