1.0.0 • Published 10 months ago

synt_backend v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

SYNT Backend

Nodejs API Backend service for Synt, access through Synt API or Syntbeheer Author: Adriaan De Bolle - adriaandebolle.com

SETUP

  • Requirements

npm

mysql

$ npm install
  • Database
$ cd mysql
$ npx sequelize-cli db:migrate && npx sequelize-cli db:seed:all

ONLY for local development, reinit database

$ npx sequelize-cli db:seed:undo:all && npx sequelize-cli db:migrate:undo:all && npx sequelize-cli db:migrate && npx sequelize-cli db:seed:all

NODE_ENV=production npx sequelize-cli db:seed:undo:all && NODE_ENV=production npx sequelize-cli db:migrate:undo:all && NODE_ENV=production npx sequelize-cli db:migrate && NODE_ENV=production npx sequelize-cli db:seed:all

NODE_ENV=production npx sequelize-cli db:seed --seed 20210118103211-notification-settings.js NODE_ENV=production npx sequelize-cli db:seed --seed 20210728100151-associate-notification-settings.js NODE_ENV=production npx sequelize-cli db:seed:undo --seed 20210728100151-associate-notification-settings.js

Create model (model + migration)

$ npx sequelize-cli model:generate --name Yeas --attributes type:enum,version:integer,consent_given_at:date

Create association (migration)

$ npx sequelize-cli migration:create --name example

RUN

Use babel-node before node starts index

  • start app
$ npm run start:dev

Server

  • check running process
$ forever list
  • stop process
$ forever stop [pid]

Coding Extra

More info: Private Git packages

Install CodeDeploy Agent on EC2(image)

Verify all EC2 setup config

TODO / Improvements

Get rid off relative path by using typescript Use npm run build to precompile babel in production: info

Background information

ERD Diagram - Synt

The fix when 'No space left on device @ dir_s_mkdir - /opt/codedeploy-agent/deployment-root/..' occurs

  • ssh to ssh -i ~/.ssh/synt-key-pair.pem ubuntu@34.242.114.0
  • change :max_revisions: 1 in /etc/codedeploy-agent/conf/codedeployagent.yml
  • clean up the folder sudo rm -rf /opt/codedeploy-agent/deployment-root/ca203350-bc6e-40a1-b01f-d4ca17fcdff7/*
  • restart the service sudo service codedeploy-agent stop and then sudo service codedeploy-agent start

Start database with docker

  • docker-compose -f docker-compose.yml up --build

  • docker-compose -f docker-compose.yml up db

  • docker-compose up --build

Start production backend with docker

  • docker build -t synt-backend .

  • docker run -p 8000:8000 --network synt_backend_my-network synt-backend:latest

aws ecr --profile synt get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 635199656487.dkr.ecr.eu-west-1.amazonaws.com

docker tag synt-backend:latest 635199656487.dkr.ecr.eu-west-1.amazonaws.com/synt-backend:latest

docker push 635199656487.dkr.ecr.eu-west-1.amazonaws.com/synt-backend:latest