Skip to content

Commit

Permalink
Feat/cb2-11225 Update cvs-svc-defects backend repo to use serverless-…
Browse files Browse the repository at this point in the history
…dynamodb (#193)
  • Loading branch information
JunYanBJSS authored Mar 21, 2024
1 parent 7b780be commit 50a1a00
Show file tree
Hide file tree
Showing 9 changed files with 6,800 additions and 6,661 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ on:

jobs:
build-test:
runs-on: ubuntu-latest
runs-on: X64

strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
Expand All @@ -30,6 +30,7 @@ jobs:
- name: Setup local dynamo
run: npm run tools-setup
- name: Build and test
timeout-minutes: 20
run: npm run prepush
env:
AWS_ACCESS_KEY_ID: foo
Expand Down
13,376 changes: 6,767 additions & 6,609 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"url": "https://github.com/dvsa/cvs-svc-defects.git"
},
"scripts": {
"start": "BRANCH=local SLS_DEBUG=* serverless offline start",
"start": "BRANCH=local SLS_DEBUG=* serverless offline start --noPrependStageInUrl",
"tools-setup": "sls dynamodb install",
"test": "npm run test:unit:coverage",
"test:unit": "BRANCH=local SLS_DEBUG=* jest --testMatch=\"**/*.unitTest.ts\"",
"test:unit:coverage": "npm run test:unit -- --coverage --runInBand",
"test:integration": "BRANCH=local jest --testMatch=\"**/*.intTest.ts\"",
"test:integration": "BRANCH=local jest --testMatch=\"**/*.intTest.ts\" --detectOpenHandles",
"test-i": "AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE=1 npm run test:integration -- --runInBand --globalSetup='./scripts/setUp.ts' --globalTeardown='./scripts/tearDown.ts'",
"build": "node_modules/typescript/bin/tsc --rootDir ./ --outDir .build --sourceMap false && npm run build:copy",
"build:copy": "find src -type f \\( -name \"*.yml\" -or -name \"*.json\" \\) | cpio -pdm .build && find tests -type f \\( -name \"*.yml\" -or -name \"*.json\" \\) | cpio -pdm .build",
Expand All @@ -29,7 +29,6 @@
"audit": "npm audit --prod",
"predeploy": "npm install && npm run prepush",
"package": "mkdir ${ZIP_NAME} && cp package.json package-lock.json ${ZIP_NAME}/ && cp -r .build/src/* ${ZIP_NAME}/ && cd ${ZIP_NAME} && npm ci --omit=dev --ignore-scripts && rm package.json package-lock.json && zip -qr ../${ZIP_NAME}.zip .",
"postinstall": "patch-package",
"precommit": "npm run security-checks && npm run audit && npm run lint && npm run format",
"commit-msg": "commitlint --edit $1",
"prepare": "husky install"
Expand Down Expand Up @@ -57,10 +56,8 @@
"jest-sonar-reporter": "^2.0.0",
"lambda-tester": "^4.0.1",
"lodash": "^4.17.21",
"patch-package": "^6.5.1",
"prettier": "3.0.3",
"serverless": "^2.43.1",
"serverless-dynamodb-local": "0.2.40",
"serverless-offline": "^5.12.0",
"serverless-plugin-tracing": "^2.0.0",
"serverless-plugin-typescript": "^2.1.4",
Expand All @@ -80,7 +77,8 @@
"js-yaml": "3.14.1",
"node-yaml": "4.0.1",
"path-parser": "^6.1.0",
"reflect-metadata": "^0.1.13"
"reflect-metadata": "^0.1.13",
"serverless-dynamodb": "0.2.50"
},
"jestSonar": {
"reportPath": ".reports",
Expand Down
34 changes: 0 additions & 34 deletions patches/dynamodb-localhost+0.0.9.patch

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/getDBPid.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lsof -i:8003 | awk '{print $2}' | grep -v '^PID'
lsof -i:8003 | awk '{print $2}' | tail -1
8 changes: 6 additions & 2 deletions scripts/setUp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawn } from "child_process";
import { exec } from "child_process";

// We hook to serverless offline when firing its process
const SERVER_OK = `Offline [HTTP] listening on http://localhost:3001`;
Expand Down Expand Up @@ -33,7 +33,11 @@ const setupServer = (process: any) => {
});
};

const server = spawn("npm", ["run", "start"], {});
const server = exec("npm run start &", (error) => {
if (error) {
console.error(`error starting server: ${error}`);
}
});

module.exports = async () => {
console.log(`\nSetting up Integration tests...\n\n`);
Expand Down
6 changes: 3 additions & 3 deletions scripts/tearDown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { killTestSetup } from "./destroyServices";

module.exports = async () => {
console.log(`
Integration tests ✅
...Tearing down tests...
`);
Integration tests ✅
...Tearing down tests...
`);
// Serverless runs containers and pid's are not managed the same way in the CI/CD pipeline
// We are not using the pid of our instance to kill the task
// instead created sh commands to manually kill the webserver and dynamoDB instances which work equally in the pipeline
Expand Down
10 changes: 8 additions & 2 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ service: cvs-svc-defect
# from 3.0 warnings will be thrown as errors
configValidationMode: warn
plugins:
- serverless-dynamodb-local
- serverless-dynamodb
- serverless-plugin-typescript
- serverless-plugin-tracing
- serverless-offline
Expand All @@ -13,6 +13,8 @@ provider:
runtime: nodejs18.x
tracing:
apiGateway: true
region: eu-west-1
stage: dev
iam:
role:
statements:
Expand All @@ -25,12 +27,16 @@ provider:

functions:
getDefects:
environment:
BRANCH: local
handler: src/handler.handler
events:
- http:
path: defects
method: get
getRequiredStandards:
environment:
BRANCH: local
handler: src/handler.handler
events:
- http:
Expand All @@ -40,7 +46,7 @@ functions:
custom:
serverless-offline:
port: 3001
dynamodb:
serverless-dynamodb:
stages:
- dev
- test
Expand Down
8 changes: 7 additions & 1 deletion src/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ functions:
proxy: null
function: getRequiredStandards
event: apigateway

invoke:
local:
params:
Expand Down Expand Up @@ -63,3 +62,10 @@ dynamodb:
serverless:
basePath: /${BRANCH}
port: 3001
Resources:
Schedule:
Type: AWS::Scheduler::Schedule
Properties:
ScheduleExpression: rate(1 minute)
FlexibleTimeWindow:
Mode: "OFF"

0 comments on commit 50a1a00

Please sign in to comment.