0.1.0 • Published 5 years ago
salt-account-service v0.1.0
Account Service
Build Setup
UPDATE CONFIG DEFAULTS, TYPES, AND TEMPLATE when making config changes
Local App Setup
- cp ./config/config-defaults.ts ./config/config.ts
- cp ./config/certificates/private-key-test.pem ./config/certificates/private-key.pem
- cp -r ./config/certificates/public-keys-test/ ./config/certificates/public-keys/
- cp ./config/certificates/public-keys-test/borrower-api.pem ./config/certificates/googleSheets.pem
- Create the local database: in the command line enter the psql console (
psql
) and create the database (CREATE DATABASE <db name>;
) and quit (\q
) - Run
npm install
||npm i
, which will acquire all the dependencies specified in package.json - Run
tsc
to compile your files into typescript npm run compile
runs tsc and excludes node_module errors- Start redis server in background:
redis-server
- To start the server in dev mode:
npm run dev
- To start the api server in prod mode:
npm start
- To run internal tests:
npm test
||npm t
- To run external tests:
npm run extTest
- To find TODO items:
npm run todo
- To reset the database:
npm run reset
- To populate a user in the database:
npm run populate
- To gen a token,
console.log
the response fromgetToken
in./test/helpers/util.ts
and pass as Bearer Token in postman. Parameterclaims
={ iss: 'microservice' }
Profiling
- Run
npm run inspect
- Open
about:inspect
in Chrome - Click Open dedicated DevTools for Node - a new window that looks like DevTools will pop up
- Navigate to the Profiler tab and start recording
- Make API requests that require profiling
- View the new profile created under CPU Profiles on left sidebar
- Another option is to run a memory profile under the Memory tab (eg. record allication, heap snapshot) while running tests
Other Options (still need GUI analysis) WIP (do not use yet)
- Start server with additional profiling and garbage collecting data
node --prof --track_gc_object_stats --trace_gc_verbose --log_timer_events scripts/api
- Create profiling log
node --prof scripts/api
- Get analysis on profile log
node --prof-process isolate-0x102801e00-v8.log
Generating Database Migrations
- Restore a fresh db from
./src/models/entities/migrations/last-schema.sql
psql -d [db_name] < ./src/models/entities/migrations/last-schema.sql
- Ensure you have the same version of typeorm as listed in package.json installed globally
- Create or edit ormconfig.json:
- Make sure the migrations cli points to path/to/models/entities/migrations
- Make sure db connection options match the fresh db you just created
npm run compile
typeorm migration:generate -n [MigrationName]
- Edit
./src/models/entities/migrations/[timestamp]-[MigrationName].ts
to make sure the querys are correct and not dropping columns that should be renamed etc. npm run compile
typeorm migration:run
- Ensure this is successful
pg_dump -d [db_name] -oO > ./src/models/entities/migrations/last-schema.sql
Application Startup Flow
This blurb attempts to walk through the application startup in fargate.
- The run time docker holds the initial start up command.
CMD pm2-runtime ecosystem.config.js --env $Environment
- ecosystem.config.js in this repo has this line
script: './scripts/api.js',
- api.ts has this line (the .ts is made into a .js at compile time?)
import { runApplication } from '../src/api-setup'
- api-setup.ts has the application listening on http.
- deployImageBG lambda kicks off this chain of events by running boto3 ecs.update_service and when it redeploys it picks up the new container in ecr with the tag.
- Images are created in the Build-Image step of CodePipeline
- deployImageDevlopment step of CodePipeline then kicks off deployImageBG
Integration Test setup (Local)
- Clone the salt-sts repo and follow the setup steps https://github.com/SALTLending/salt-sts
- When logging into aws-cli via salt-sts, select SaltDevAWSDevOps_profile. You will need write access to our dev environment.
- Update the config/config.ts file to point to development for both aws cognito and postgres
- Run
npm run test:integration
- You can pass
TEST_ENV=stage npm run test:integration
to run the framework against stage. Note that your config.ts file will need to be updated to point to the stage aws/db instances. If no TEST_ENV param is passed, we default to dev.
Test user creation script
- Follow steps to setup integration tests
- Run
npm run create -- --help
to show cli options TEST_ENV=stage npm run create -- -a personal -l -w doge
would create a personal user, with a loan request and a doge wallet on stage.npm run create -- -i 10
would create 10 users with personal accounts and output a csv file of the accounts totest/integration/scripts
Updating and generating new JWT key pairs
To simply update if new keys were committed to ./config.certificates/public-keys-test
rm ./config/certificates/private-key.pem
rm ./config/certificates/public-keys/*.pem
- run through steps 2 and 3 in local app setup section above
To generate a new pair and update:
rm ./config/certificates/private-key.pem
rm ./config/certificates/public-keys/*.pem
openssl ecparam -name prime256v1 -genkey -noout -out ./config/certificates/private-key-test.pem
openssl ec -in ./config/certificates/private-key-test.pem -pubout -out ./config/certificates/public-keys-test/microservice.pem
- copy
microservice.pem
into other key files in./config/certificates/public-keys-test
ie.cp ./config/certificates/public-keys-test/microservice.pem ./config/certificates/public-keys-test/borrower-api.pem
- run through steps 2 and 3 in local app setup section above
- connecting microservice keys should be updated with same set
0.1.0
5 years ago