feat: AWS Lambda deployment script and fixes (#266)
* feat: add scripts to create lambda layers * chore: deploy the new version of the contract to mumbai. * feat: update environment variables used in the serverless config. * feat: add JSON_RPC env var. * feat: add deploy:dev command. * feat: functional deployment script, configuration changes. * feat: update config and the deploy script. * docs: add the serverless stack diagram * feat: move the ABI to the lib dir, update the build handler + some minor changes on the config files. --------- Co-authored-by: root <root@LAPTOP-UJU1VIVI>
This commit is contained in:
parent
bce1e0a34a
commit
3f78a1af43
Binary file not shown.
|
After Width: | Height: | Size: 7.7 MiB |
|
|
@ -8,7 +8,7 @@
|
||||||
"invoke:build": "yarn build && serverless invoke local --function submitBuildInfo",
|
"invoke:build": "yarn build && serverless invoke local --function submitBuildInfo",
|
||||||
"prisma:generate": "npx prisma generate",
|
"prisma:generate": "npx prisma generate",
|
||||||
"prisma:pull": "npx prisma db pull --force",
|
"prisma:pull": "npx prisma db pull --force",
|
||||||
"start": "serverless offline",
|
"start": "yarn build && serverless offline",
|
||||||
"generate:layers": "./scripts/prepare-prisma-client-lambda-layer.sh && ./scripts/prepare-libs-lambda-layer.sh && ./scripts/prepare-node-modules-lambda-layer.sh",
|
"generate:layers": "./scripts/prepare-prisma-client-lambda-layer.sh && ./scripts/prepare-libs-lambda-layer.sh && ./scripts/prepare-node-modules-lambda-layer.sh",
|
||||||
"deploy:dev": "yarn build && yarn generate:layers && yarn sls deploy --stage dev"
|
"deploy:dev": "yarn build && yarn generate:layers && yarn sls deploy --stage dev"
|
||||||
},
|
},
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
"esbuild": "^0.17.12",
|
"esbuild": "^0.17.12",
|
||||||
"json-schema-to-ts": "^2.7.2",
|
"json-schema-to-ts": "^2.7.2",
|
||||||
"serverless": "^3.28.1",
|
"serverless": "^3.28.1",
|
||||||
|
"serverless-dotenv-plugin": "^6.0.0",
|
||||||
"serverless-esbuild": "^1.42.0",
|
"serverless-esbuild": "^1.42.0",
|
||||||
"serverless-offline": "^12.0.4",
|
"serverless-offline": "^12.0.4",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
|
|
@ -35,7 +36,6 @@
|
||||||
"@prisma/client": "^4.13.0",
|
"@prisma/client": "^4.13.0",
|
||||||
"@types/node": "^18.15.11",
|
"@types/node": "^18.15.11",
|
||||||
"aws-sdk": "^2.1342.0",
|
"aws-sdk": "^2.1342.0",
|
||||||
"dotenv": "^16.0.3",
|
|
||||||
"prisma": "^4.13.0",
|
"prisma": "^4.13.0",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^5.0.4",
|
"typescript": "^5.0.4",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
generator client {
|
generator client {
|
||||||
provider = "prisma-client-js"
|
provider = "prisma-client-js"
|
||||||
|
binaryTargets = ["native", "rhel-openssl-1.0.x"]
|
||||||
}
|
}
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,87 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
bold=$(tput bold)
|
||||||
|
normal=$(tput sgr0)
|
||||||
|
|
||||||
|
source .env
|
||||||
|
|
||||||
|
echo "${bold}Starting the deployment process${normal}"
|
||||||
|
|
||||||
|
echo "${bold}Installing dependencies via Yarn${normal}"
|
||||||
|
|
||||||
|
yarn
|
||||||
|
|
||||||
|
if [[ -z "${DATABASE_URL}" ]]; then
|
||||||
|
printf "%s" "Enter the Mongo Database URL: "
|
||||||
|
read -r DB_URL
|
||||||
|
export DATABASE_URL=$DB_URL
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${JSON_RPC}" ]]; then
|
||||||
|
printf "%s" "Enter the JSON RPC endpoint: "
|
||||||
|
read -r JSON_RPC
|
||||||
|
export JSON_RPC=$JSON_RPC
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${CONTRACT_ADDRESS}" ]]; then
|
||||||
|
printf "%s" "Enter the contract address: "
|
||||||
|
read -r CONTRACT_ADDRESS
|
||||||
|
export CONTRACT_ADDRESS=$CONTRACT_ADDRESS
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${PRIVATE_KEY}" ]]; then
|
||||||
|
printf "%s" "Enter the private key: "
|
||||||
|
read -r PRIVATE_KEY
|
||||||
|
export PRIVATE_KEY=$PRIVATE_KEY
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${AWS_ACCESS_KEY_ID}" ]]; then
|
||||||
|
printf "%s" "Enter the AWS access key ID: "
|
||||||
|
read -r AWS_ACCESS_KEY_ID
|
||||||
|
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${AWS_SECRET_ACCESS_KEY}" ]]; then
|
||||||
|
printf "%s" "Enter the AWS secret access key: "
|
||||||
|
read -r AWS_SECRET_ACCESS_KEY
|
||||||
|
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${bold}Copying the Prisma schema file to function directories${normal}"
|
||||||
|
cp prisma/schema.prisma dist/serverless/src/functions/builds/
|
||||||
|
cp prisma/schema.prisma dist/serverless/src/functions/mints/
|
||||||
|
|
||||||
|
echo "${bold}Running the build command${normal}"
|
||||||
|
yarn build
|
||||||
|
|
||||||
|
echo "${bold}Copying the rhel openssl engine to dist/${normal}"
|
||||||
|
cp node_modules/.prisma/client/libquery_engine-rhel-openssl-1.0.x.so.node dist/serverless/src/functions/mints
|
||||||
|
cp node_modules/.prisma/client/libquery_engine-rhel-openssl-1.0.x.so.node dist/serverless/src/functions/builds
|
||||||
|
|
||||||
|
echo "${bold}Copying the .env file to dist/${normal}"
|
||||||
|
cp .env src/
|
||||||
|
|
||||||
|
echo "${bold}Copying the Prisma schema file to function directories${normal}"
|
||||||
|
cp prisma/schema.prisma dist/serverless/src/functions/builds/
|
||||||
|
cp prisma/schema.prisma dist/serverless/src/functions/mints/
|
||||||
|
|
||||||
|
echo "${bold}Generating Prisma Client${normal}"
|
||||||
|
yarn prisma:generate
|
||||||
|
|
||||||
|
echo "${bold}Creating layer zip files${normal}"
|
||||||
|
/bin/bash ./scripts/prepare-libs-lambda-layer.sh
|
||||||
|
/bin/bash ./scripts/prepare-prisma-client-lambda-layer.sh
|
||||||
|
/bin/bash ./scripts/prepare-node-modules-lambda-layer.sh
|
||||||
|
|
||||||
|
echo "${bold}Deploying to AWS lambda${normal}"
|
||||||
|
yarn sls deploy --stage dev --verbose
|
||||||
|
|
||||||
|
# step 0 -> run yarn
|
||||||
|
# step 1 -> take params (env variables)
|
||||||
|
# step 2 -> build tsc files with yarn build
|
||||||
|
# step 3 -> run yarn generate:prisma
|
||||||
|
# step 4 -> run the other shell scripts for layer generation
|
||||||
|
# step 5 -> run the deployment command to aws
|
||||||
|
|
||||||
|
# TODO the .env file needs to move to the inside of the serverless dir in dist (zip file)
|
||||||
|
# TODO Prisma.schema files aren't being packaged with the functions in the nfa-serverless.zip file in .serverless.
|
||||||
|
|
@ -6,6 +6,7 @@ plugins:
|
||||||
- serverless-offline
|
- serverless-offline
|
||||||
|
|
||||||
provider:
|
provider:
|
||||||
|
timeout: 150
|
||||||
name: aws
|
name: aws
|
||||||
runtime: nodejs18.x
|
runtime: nodejs18.x
|
||||||
stage: ${opt:stage, 'prd'}
|
stage: ${opt:stage, 'prd'}
|
||||||
|
|
@ -26,6 +27,10 @@ layers:
|
||||||
TopicPrismaAwsPrismaClient:
|
TopicPrismaAwsPrismaClient:
|
||||||
path: lambda-layers-prisma-client
|
path: lambda-layers-prisma-client
|
||||||
|
|
||||||
|
package: {
|
||||||
|
patterns: ["dist/**/*.prisma", "**/libquery_engine-rhel-openssl-1.0.x.so.node", "dist/serverless/.env", '!node_modules/**'],
|
||||||
|
}
|
||||||
|
|
||||||
custom:
|
custom:
|
||||||
esbuild:
|
esbuild:
|
||||||
bundle: true
|
bundle: true
|
||||||
|
|
@ -40,46 +45,42 @@ custom:
|
||||||
functions:
|
functions:
|
||||||
|
|
||||||
submitBuildInfo:
|
submitBuildInfo:
|
||||||
handler: src/functions/builds/handler.submitBuildInfo # Change `src` to `dist` for deployment
|
# Deployment:
|
||||||
|
handler: ./dist/serverless/src/functions/builds/handler.submitBuildInfo # TODO This will not work, need to change to nfa-serverless/dist/serverless/src/functions/builds/handler.submitBuildInfo
|
||||||
|
# Local development:
|
||||||
|
# handler: ./src/functions/builds/handler.submitBuildInfo
|
||||||
events:
|
events:
|
||||||
- http:
|
- http:
|
||||||
path: build
|
path: build
|
||||||
method: post
|
method: post
|
||||||
cors: true
|
cors: true
|
||||||
request:
|
environment: # TODO They won't be loaded from the shell environment, need to find a way to pass them from the deployment script
|
||||||
parameters:
|
|
||||||
querystrings:
|
|
||||||
githubOrg: true
|
|
||||||
githubRepo: true
|
|
||||||
commitHash: true
|
|
||||||
author: true
|
|
||||||
timestamp: true
|
|
||||||
ipfsHash: true
|
|
||||||
tokenId: true
|
|
||||||
environment:
|
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
DATABASE_URL: ${env:DATABASE_URL}
|
# DATABASE_URL: ${env:DATABASE_URL}
|
||||||
CONTRACT_ADDRESS: ${env:CONTRACT_ADDRESS}
|
# CONTRACT_ADDRESS: ${env:CONTRACT_ADDRESS}
|
||||||
PRIVATE_KEY: ${env:PRIVATE_KEY}
|
# PRIVATE_KEY: ${env:PRIVATE_KEY}
|
||||||
JSON_RPC: ${env:JSON_RPC}
|
# JSON_RPC: ${env:JSON_RPC}
|
||||||
layers:
|
layers:
|
||||||
- { Ref: TopicAwsNodeModulesLambdaLayer }
|
- { Ref: TopicAwsNodeModulesLambdaLayer }
|
||||||
- { Ref: TopicAwsLibsLambdaLayer }
|
- { Ref: TopicAwsLibsLambdaLayer }
|
||||||
- { Ref: TopicPrismaAwsPrismaClientLambdaLayer }
|
- { Ref: TopicPrismaAwsPrismaClientLambdaLayer }
|
||||||
|
|
||||||
submitMintInfo:
|
submitMintInfo:
|
||||||
handler: src/functions/mints/handler.submitMintInfo
|
# Deployment:
|
||||||
|
handler: ./dist/serverless/src/functions/mints/handler.submitMintInfo # TODO This will not work, need to change to nfa-serverless/dist/serverless/src/functions/mints/handler.submitMintInfo
|
||||||
|
# Local development:
|
||||||
|
# handler: ./src/functions/mints/handler.submitMintInfo
|
||||||
events:
|
events:
|
||||||
- http:
|
- http:
|
||||||
path: mint
|
path: mint
|
||||||
method: post
|
method: post
|
||||||
cors: true
|
cors: true
|
||||||
environment:
|
environment: # TODO They won't be loaded from the shell environment, need to find a way to pass them from the deployment script
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
DATABASE_URL: ${env:DATABASE_URL}
|
# DATABASE_URL: ${env:DATABASE_URL}
|
||||||
CONTRACT_ADDRESS: ${env:CONTRACT_ADDRESS}
|
# CONTRACT_ADDRESS: ${env:CONTRACT_ADDRESS}
|
||||||
PRIVATE_KEY: ${env:PRIVATE_KEY}
|
# PRIVATE_KEY: ${env:PRIVATE_KEY}
|
||||||
JSON_RPC: ${env:JSON_RPC}
|
# JSON_RPC: ${env:JSON_RPC}
|
||||||
layers:
|
layers:
|
||||||
- { Ref: TopicAwsNodeModulesLambdaLayer }
|
- { Ref: TopicAwsNodeModulesLambdaLayer }
|
||||||
- { Ref: TopicAwsLibsLambdaLayer }
|
- { Ref: TopicAwsLibsLambdaLayer }
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ export const submitBuildInfo = async (
|
||||||
ipfsHash: data.ipfsHash,
|
ipfsHash: data.ipfsHash,
|
||||||
domain: data.domain,
|
domain: data.domain,
|
||||||
};
|
};
|
||||||
|
console.log(buildInfo);
|
||||||
|
|
||||||
// Add build record to the database, if it's not already added
|
// Add build record to the database, if it's not already added
|
||||||
const buildRecord = await prisma.builds.findMany({
|
const buildRecord = await prisma.builds.findMany({
|
||||||
|
|
@ -37,8 +38,12 @@ export const submitBuildInfo = async (
|
||||||
domain: buildInfo.domain,
|
domain: buildInfo.domain,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
console.log(buildRecord);
|
||||||
|
|
||||||
|
|
||||||
if (buildRecord.length == 0) {
|
if (buildRecord.length == 0) {
|
||||||
|
console.log('here i am');
|
||||||
|
|
||||||
await prisma.builds.create({
|
await prisma.builds.create({
|
||||||
data: {
|
data: {
|
||||||
githubRepository: buildInfo.githubRepository,
|
githubRepository: buildInfo.githubRepository,
|
||||||
|
|
|
||||||
|
|
@ -14,22 +14,20 @@ export const submitMintInfo = async (
|
||||||
///context: APIGatewayEventRequestContext
|
///context: APIGatewayEventRequestContext
|
||||||
): Promise<APIGatewayProxyResult> => {
|
): Promise<APIGatewayProxyResult> => {
|
||||||
try {
|
try {
|
||||||
if (event.body === null) {
|
if (event.body === null || event.body === undefined) {
|
||||||
return formatJSONResponse({
|
return formatJSONResponse({
|
||||||
status: 422,
|
status: 422,
|
||||||
message: 'Required parameters were not passed.',
|
message: 'Required parameters were not passed.',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const id = v4();
|
const id = v4();
|
||||||
|
|
||||||
/**if (!verifyAlchemySig(event.headers.xalchemywork)) {
|
/**if (!verifyAlchemySig(event.headers.xalchemywork)) {
|
||||||
throw new Error('Invalid sig');
|
throw new Error('Invalid sig');
|
||||||
}**/
|
}**/
|
||||||
|
|
||||||
const eventBody = JSON.parse(event.body);
|
const eventBody = JSON.parse(event.body);
|
||||||
const topics = eventBody.event.data.block.logs[1].slice(1, 3);
|
const topics = eventBody.event.data.block.logs[1].topics.slice(1, 4);
|
||||||
const hexCalldata = eventBody.event.data.block.logs[1].data;
|
const hexCalldata = eventBody.event.data.block.logs[1].data;
|
||||||
|
|
||||||
const decodedLogs = web3.eth.abi.decodeLog(
|
const decodedLogs = web3.eth.abi.decodeLog(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,8 +1,5 @@
|
||||||
import Web3 from 'web3';
|
import Web3 from 'web3';
|
||||||
import * as abiFile from '../../../contracts/deployments/goerli/FleekERC721.json';
|
import * as abiFile from './FleekERC721.json';
|
||||||
import * as dotenv from 'dotenv';
|
|
||||||
|
|
||||||
dotenv.config();
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
process.env.PRIVATE_KEY === undefined ||
|
process.env.PRIVATE_KEY === undefined ||
|
||||||
|
|
@ -15,7 +12,6 @@ const contract_address = abiFile.address;
|
||||||
export const abi = abiFile.abi as any;
|
export const abi = abiFile.abi as any;
|
||||||
|
|
||||||
export const web3 = new Web3(process.env.JSON_RPC);
|
export const web3 = new Web3(process.env.JSON_RPC);
|
||||||
|
export const account = web3.eth.accounts.wallet.add(process.env.PRIVATE_KEY);
|
||||||
|
web3.eth.setProvider(Web3.givenProvider);
|
||||||
export const nfaContract = new web3.eth.Contract(abi, contract_address);
|
export const nfaContract = new web3.eth.Contract(abi, contract_address);
|
||||||
export const account = web3.eth.accounts.privateKeyToAccount(
|
|
||||||
process.env.PRIVATE_KEY
|
|
||||||
);
|
|
||||||
|
|
|
||||||
|
|
@ -2765,6 +2765,11 @@ dom-walk@^0.1.0:
|
||||||
resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.2.tgz#0c548bef048f4d1f2a97249002236060daa3fd84"
|
resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.2.tgz#0c548bef048f4d1f2a97249002236060daa3fd84"
|
||||||
integrity sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w==
|
integrity sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w==
|
||||||
|
|
||||||
|
dotenv-expand@^10.0.0:
|
||||||
|
version "10.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
|
||||||
|
integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==
|
||||||
|
|
||||||
dotenv-expand@^9.0.0:
|
dotenv-expand@^9.0.0:
|
||||||
version "9.0.0"
|
version "9.0.0"
|
||||||
resolved "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-9.0.0.tgz"
|
resolved "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-9.0.0.tgz"
|
||||||
|
|
@ -5580,6 +5585,15 @@ serve-static@1.15.0:
|
||||||
parseurl "~1.3.3"
|
parseurl "~1.3.3"
|
||||||
send "0.18.0"
|
send "0.18.0"
|
||||||
|
|
||||||
|
serverless-dotenv-plugin@^6.0.0:
|
||||||
|
version "6.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/serverless-dotenv-plugin/-/serverless-dotenv-plugin-6.0.0.tgz#c3e0c2e7fb79641433497085eecc30fe150b5ca0"
|
||||||
|
integrity sha512-8tLVNwHfDO0sBz6+m+DLTZquRk0AZq9rzqk3kphm1iIWKfan9R7RKt4hdq3eQ0kmDoqzudjPYBEXAJ5bUNKeGQ==
|
||||||
|
dependencies:
|
||||||
|
chalk "^4.1.2"
|
||||||
|
dotenv "^16.0.3"
|
||||||
|
dotenv-expand "^10.0.0"
|
||||||
|
|
||||||
serverless-esbuild@^1.42.0:
|
serverless-esbuild@^1.42.0:
|
||||||
version "1.42.0"
|
version "1.42.0"
|
||||||
resolved "https://registry.npmjs.org/serverless-esbuild/-/serverless-esbuild-1.42.0.tgz"
|
resolved "https://registry.npmjs.org/serverless-esbuild/-/serverless-esbuild-1.42.0.tgz"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue