Skip to content

CodeNow/api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js-standard-style lol Travis CI

Table of Contents generated with DocToc

Application Components

Express

/lib/express-app.js

Routes

/lib/routes/**/*.js

Mongo

  • Models: /lib/models/mongo/*.js
  • Schemas: /lib/models/mongo/schemas/*.js

Tests

  • Behavioral tests (BDD): /test
  • Unit Tests: /unit
  • Lab (testing framework): hapijs/lab

Logs

Shrinkwrap

A quick informational blurb about shrinkwrap.

In order to keep our tests running and consistently installing the same thing for everyone, we are going to be using shrinkwrap. If you are not changing dependencies, you will not need to do anything in particular; npm install will follow the rules in npm-shrinkwrap.json and everyone will be happy.

If you are interested in changing dependencies, you can do so pretty easily.

When you are adding a dependency, do your npm install --save(-dev) as you normally would. Then, when everything is confirmed to be working, run npm shrinkwrap to generate a new npm-shrinkwrap.json. This will shrinkwrap all your dependencies and dev dependencies, updating npm-shrinkwrap.json.

Commit the new npm-shrinkwrap.json along with your changes. You may want to run some tests locally after doing a clean npm install to verify it's validity.

Running Tests

Prerequisites

  • mongo
    • brew install mongodb
    • default configuration (listening on 127.0.0.1:27017)
    • mongod
  • redis
    • brew install redis
    • default configuration (listening on 127.0.0.1:6379)
    • redis-server
  • ulimit
    • ulimit -n 10240 (at minimum)

Tests

Run all tests: npm test

Granular:

  • BDD: npm run bdd
    • Pass additional arguments to BDD: npm run bdd -- -d
    • BDD one file: npm run bdd -- test/path/to/file.js
    • BDD one test (optional file): npm run bdd -- -i 3 [test/path/to/file.js]
    • BDD range of tests (optional file): npm run bdd -- -i 3-10 [test/path/to/file.js]
    • BDD Watch: npm run bdd-watch
    • BDD Watch w/ one test file: npm run bdd-watch -- test/path/to/file.js
  • Unit: npm run unit
    • (similar options exist to run individual and ranges of tests as BDD)

Formatting

This repository is formatted using the Standard JS rules.

js-standard-style

Some helpful tips:

  • npm run lint runs the standard linter, and will not format your code
  • npm run format will run the standard formatter, attempting to fix various issues that are found
  • standard's README has some good information about various text editor plugins as well, to make your life easier

Opinions

Restful resource urls

Create - POST - /resources Read - GET - /resources/:id Update - PATCH - /resources/:id *PATCH is a partial update, PUT is a full resource update Delete - DELETE - /resources/:id

Middleware Patterns

Request Data validation and Middleware Flow Control - tjmehta/dat-middleware Middleware Flow Control - tjmehta/middleware-flow Middlewares of models are autogenerated for you Mongoose Models tjmehta/mongooseware Sharing the request object as a common context between middlewares allows us to make asynchronous code look synchronous and avoid "callback hell"

Boom for Http Errors

Nice Http Error library - hapijs/boom

Resource Overview

Mongo Schemas - /lib/models/mongo/schemas/*.js

Context Versions - a snapshot of infrastructure code version and application code version

  • Dockerfile v0.1.0 and api-server v0.1.0
  • Can be built on unbuilt

Infrastructure Code Versions - build file versions. Ex: [email protected]

Builds - groupings of built components component versions

  • [frontend v0.1.0, api-server v0.1.0, redis v1.0.0, mongodb v2.7.0]
  • Remember component versions are snapshots of BOTH infra and app code.
  • This is a grouping of built docker images.

Instances - Running build which consists of running containers for each project component

  • This is a grouping on running docker containers for a build's docker images.

Migration

Runs during the start command

  • Need to rerun the migrations?
  • SSH into mongo
  • connect
  • db.getCollection("_migrations").remove({})
  • rerun api start

Help and Tips

Problems npm installing?

This may be because you're getting access denied from npm. Which is trying to clone a private repo (runnable-api-client). Make sure you set up a ssh key with github and ssh-add it. (ssh-add ~/.ssh/github_rsa) Your github ssh keys

Models

  • A context represents a project context (like redis)

  • A version is a version of a particular context (build files, github commitHash)

    • can be built or unbuilt - built means it has docker image
  • A build is a grouping built versions (for all contexts of a project)

  • Instances (running builds)

  • containers (subdoc)

  • Pages

  • see client/config/routes.js of runnable-angular repository

  • Build List Page - /project/anandkumar/filibuster/master

  • has a listing of builds for an environment

  • Instance Page - /project/anandkumar/filibuster/master/build/:id (just like our current container pages except supports multiple containers (full instance))

  • create an instance from a build (create containers for all build images (versions))