From d938cdf89b37eb90458273e3fc5451abaa6035e2 Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Fri, 27 Oct 2023 09:21:04 -0400 Subject: [PATCH] Add Python Lambda Fixes #1583. --- .github/workflows/deploy.yml | 5 + .../{node.js.yml => pull_request.yml} | 9 +- .gitignore | 4 + app.arc | 5 + lint-staged.config.js | 1 + package-lock.json | 119 ++++++++++-------- package.json | 6 +- python/config.arc | 7 ++ python/lambda.py | 17 +++ requirements.txt | 4 + 10 files changed, 125 insertions(+), 52 deletions(-) rename .github/workflows/{node.js.yml => pull_request.yml} (51%) create mode 100644 python/config.arc create mode 100644 python/lambda.py create mode 100644 requirements.txt diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index bb4d5d7dc..2e8659276 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -28,8 +28,13 @@ jobs: uses: actions/setup-node@v3 with: node-version: '18' + - uses: actions/setup-python@v4 + with: + python-version: '3.11' - name: NPM Install run: npm ci + - name: Pip Install + run: pip install -r requirements.txt - name: Build run: npm run build - name: Configure aws credentials diff --git a/.github/workflows/node.js.yml b/.github/workflows/pull_request.yml similarity index 51% rename from .github/workflows/node.js.yml rename to .github/workflows/pull_request.yml index a282c75a6..1dae06324 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/pull_request.yml @@ -1,4 +1,4 @@ -name: Node.js CI +name: Pull Request on: push: branches: @@ -7,5 +7,10 @@ on: branches: - main jobs: - build: + node: uses: nasa-gcn/.github/.github/workflows/node.yml@main + python: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: psf/black@stable diff --git a/.gitignore b/.gitignore index 780bbc08f..e6f194aa5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules +vendor # Generated by `npm run dev`, `npm run build`, etc. /.cache @@ -21,5 +22,8 @@ sam.yaml # Generated by Mac .DS_Store +# Generated by Python +__pycache__ + .env .eslintcache diff --git a/app.arc b/app.arc index 45c4223e7..cf7c426c2 100644 --- a/app.arc +++ b/app.arc @@ -6,6 +6,10 @@ remix-gcn method any src build/server +/labs/api/* + method any + src python + @email-incoming circulars src build/email-incoming/circulars @@ -111,6 +115,7 @@ region us-east-1 architecture arm64 memory 256 timeout 30 +hydrate false @search instanceType t3.small.search diff --git a/lint-staged.config.js b/lint-staged.config.js index a1732b12f..32c3a324b 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -35,4 +35,5 @@ export default { if (!files) return [] return `prettier --write ${filteredFiles}` }, + '*.py': 'black', } diff --git a/package-lock.json b/package-lock.json index dacf3f57b..fafc09524 100644 --- a/package-lock.json +++ b/package-lock.json @@ -181,6 +181,74 @@ "node": ">=14" } }, + "node_modules/@architect/architect/node_modules/@architect/sandbox": { + "version": "5.8.2", + "resolved": "git+ssh://git@github.com/lpsinger/sandbox.git#7fc5aa7b31c5848524021660c1ed436a5ecdd01a", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@architect/asap": "~6.0.3", + "@architect/create": "~4.2.3", + "@architect/hydrate": "~3.3.0", + "@architect/inventory": "~3.6.1", + "@architect/utils": "~3.1.9", + "@aws-sdk/client-apigatewaymanagementapi": "^3.316.0", + "@aws-sdk/client-dynamodb": "^3.316.0", + "@aws-sdk/client-s3": "^3.316.0", + "@aws-sdk/client-sns": "^3.316.0", + "@aws-sdk/client-sqs": "^3.316.0", + "@aws-sdk/client-ssm": "^3.316.0", + "@aws-sdk/lib-dynamodb": "^3.316.0", + "@aws-sdk/node-http-handler": "^3.360.0", + "@begin/hashid": "~1.0.0", + "aws-sdk": "^2.1363.0", + "chalk": "4.1.2", + "chokidar": "~3.5.3", + "depstatus": "~1.1.1", + "dynalite": "~3.2.2", + "finalhandler": "~1.2.0", + "glob": "~10.3.3", + "http-proxy": "~1.18.1", + "lambda-runtimes": "~1.1.4", + "minimist": "~1.2.8", + "router": "~1.3.8", + "run-parallel": "~1.2.0", + "run-series": "~1.1.9", + "send": "~0.18.0", + "server-destroy": "~1.0.1", + "tmp": "~0.2.1", + "tree-kill": "~1.2.2", + "update-notifier-cjs": "~5.1.6", + "ws": "~8.13.0" + }, + "bin": { + "sandbox": "src/cli/cli.js" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/@architect/architect/node_modules/ws": { + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz", + "integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==", + "dev": true, + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/@architect/asap": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/@architect/asap/-/asap-6.0.3.tgz", @@ -325,9 +393,9 @@ }, "node_modules/@architect/hydrate": { "version": "3.4.1", - "resolved": "https://registry.npmjs.org/@architect/hydrate/-/hydrate-3.4.1.tgz", - "integrity": "sha512-PHTFRfceWHkbJwdGWr+pg2Ruk/LdXC7H569Bc5lJLd3h/JY/cco6LSyP5EQCUdnxrPz8b7H3rny1wGRCh4rmPA==", + "resolved": "git+ssh://git@github.com/lpsinger/hydrate.git#33ef2a1849afada434734f7519532d06ce6323d7", "dev": true, + "license": "Apache-2.0", "dependencies": { "@architect/inventory": "~3.6.2", "@architect/utils": "~3.1.9", @@ -420,53 +488,6 @@ "node": ">=14.17.0" } }, - "node_modules/@architect/sandbox": { - "version": "5.8.5", - "resolved": "https://registry.npmjs.org/@architect/sandbox/-/sandbox-5.8.5.tgz", - "integrity": "sha512-Po7SDJxgPtGu2WBaEMb7GZKpt3VsmW8zpsGxLze307XWKPSazqYPXxoLBJqQQqHlMr75CWe7GZWoGPonXzHUEQ==", - "dev": true, - "dependencies": { - "@architect/asap": "~6.0.3", - "@architect/create": "~4.2.3", - "@architect/hydrate": "~3.4.1", - "@architect/inventory": "~3.6.2", - "@architect/utils": "~3.1.9", - "@aws-sdk/client-apigatewaymanagementapi": "^3.316.0", - "@aws-sdk/client-dynamodb": "^3.316.0", - "@aws-sdk/client-s3": "^3.316.0", - "@aws-sdk/client-sns": "^3.316.0", - "@aws-sdk/client-sqs": "^3.316.0", - "@aws-sdk/client-ssm": "^3.316.0", - "@aws-sdk/lib-dynamodb": "^3.316.0", - "@aws-sdk/node-http-handler": "^3.360.0", - "@begin/hashid": "~1.0.0", - "aws-sdk": "^2.1363.0", - "chalk": "4.1.2", - "chokidar": "~3.5.3", - "depstatus": "~1.1.1", - "dynalite": "~3.2.2", - "finalhandler": "~1.2.0", - "glob": "~10.3.10", - "http-proxy": "~1.18.1", - "lambda-runtimes": "~1.1.5", - "minimist": "~1.2.8", - "router": "~1.3.8", - "run-parallel": "~1.2.0", - "run-series": "~1.1.9", - "send": "~0.18.0", - "server-destroy": "~1.0.1", - "tmp": "~0.2.1", - "tree-kill": "~1.2.2", - "update-notifier-cjs": "~5.1.6", - "ws": "~8.14.2" - }, - "bin": { - "sandbox": "src/cli/cli.js" - }, - "engines": { - "node": ">=14" - } - }, "node_modules/@architect/utils": { "version": "3.1.9", "resolved": "https://registry.npmjs.org/@architect/utils/-/utils-3.1.9.tgz", diff --git a/package.json b/package.json index 6b8e5c325..c25bebe93 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "dev:esbuild": "node esbuild.js --dev", "dev": "run-p \"dev:*\"", "prepare": "husky install", - "deploy": "arc deploy --no-hydrate --prune --production", + "deploy": "arc deploy --prune --production", "clean": "rimraf --glob build/static app/css \"build/**/index.*\" \"build/**/metafile.*\" \"build/**/version.txt\" \"app/**/*.css\" \"app/**/*.css.map\" sam.json sam.yaml .cache", "test": "jest", "test-coverage": "jest --coverage", @@ -135,6 +135,10 @@ "ts-jest": "^29.1.0", "typescript": "^5.2.2" }, + "overrides": { + "@architect/hydrate": "github:lpsinger/hydrate#hydrate-per-function-config", + "@architect/sandbox": "github:lpsinger/sandbox#x-forwarded-port-string" + }, "engines": { "node": ">=18" }, diff --git a/python/config.arc b/python/config.arc new file mode 100644 index 000000000..3c6cc7073 --- /dev/null +++ b/python/config.arc @@ -0,0 +1,7 @@ +@aws +runtime python3.11 +memory 2048 +timeout 30 + +@arc +hydrate true diff --git a/python/lambda.py b/python/lambda.py new file mode 100644 index 000000000..8ee3f9714 --- /dev/null +++ b/python/lambda.py @@ -0,0 +1,17 @@ +# Copyright © 2023 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. + + +from fastapi import FastAPI +from mangum import Mangum + +app = FastAPI() + + +@app.get("/") +async def example(): + return {"greeting": "Hello, world!"} + + +handler = Mangum(app, api_gateway_base_path="/labs/api", lifespan="off") diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..6926c8b28 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +astropy +black +fastapi +mangum