Skip to content

Commit 306e1d2

Browse files
authored
Merge pull request #64 from CodeForBaltimore/revjtanton/issue-63
Revjtanton/issue 63 Nobody around for PR approval.
2 parents 8677eb4 + 9ce416c commit 306e1d2

File tree

7 files changed

+50
-89
lines changed

7 files changed

+50
-89
lines changed

.travis.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ script:
1717
after_script:
1818
- nyc --reporter=text-lcov npm test > coverage.lcov
1919
- codecov
20-
- >
21-
if [ "$TRAVIS_BRANCH" == "master" ] && [ "TRAVIS_PULL_REQUEST" == "false" ]; then
22-
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
23-
docker build -t codeforbaltimore/bmore-responsive .
24-
docker push codeforbaltimore/bmore-responsive
25-
else
26-
echo "Will not deploy to Dockerhub"
27-
fi
2820
notifications:
2921
slack:
3022
secure: U4+tEb6IRX5XHNoX/cCBr0jxEbCINpWbhX3D4kHf2YOPEKtdGeZFZh/hqAwXSRRdQIXiEvmrRTD42IEZwWK4HgZ6ZTeLF2C17afg7o0kvxHbVhp+1PS9/BFUx0+5KrYB8Ew4US8f/qq6myCx7gtI9dZImH2m5EpgmTHTumEWkGK5PHJBbwL/0GYsO551eT2QimaBvUvAIe++rB5fK0MveCaT2T1ZmprQTQWLRY2tLXbKyBTpiIgC73lbXWCadO2MbBCx7dFSIJVfFWWa86E7dXBfK1Nk4EClMYaAdnqM+mFLx01NINOrpYuzXt8RQivP9OAitTdDpqwIqJcmn+uE3r48w6Hf9onojZfqbytOMIvybgPlLPOhZGwRFFa9xZWUG4JT6X747t/RcrEQXl8wbbm7QaRKLk60zgLH0ysvUFLr6cl+CCzZqTmRbWgGh5NiNS1U6XrjiQR4GVZkKPwLjx9+1ZgaayPkzaFReOETgc72X1WJClkm108R2lLfqvn9iF4C19EmuQpLehzXFXIDN5kHHvKFhbG4jiZwYwMQH0R1OqYhrwB3QWO1Scco6Z7zUcrN9S0KDu4p46sUoLsrk6+DP8VbHDMpiPt0wPOJnvzSeoqYgSYYMuCITr/VMvz6VS7E65swNHMJEWsz+SDsLUnamhUHanMPJzGrk7zmnBY=

Dockerfile

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,6 @@ FROM node:12.11.0-alpine
55
RUN mkdir -p /usr/src
66
WORKDIR /usr/src
77

8-
# Arguments
9-
ARG node_env=development
10-
ARG port=3000
11-
ARG database=postgres
12-
ARG database_user=postgres
13-
ARG database_password=postgres
14-
ARG database_schema=public
15-
ARG jwt_key=abc_123
16-
17-
# Environment variables
18-
ENV NODE_ENV $node_env
19-
ENV PORT $port
20-
ENV DATABASE $database
21-
ENV DATABASE_USER $database_user
22-
ENV DATABASE_PASSWORD $database_password
23-
ENV DATABASE_SCHEMA $database_schema
24-
ENV JWT_KEY $jwt_key
25-
268
# Install app dependencies
279
COPY ./package*.json ./
2810
RUN npm install

README.md

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
[![Build Status](https://travis-ci.org/CodeForBaltimore/Bmore-Responsive.svg?branch=master)](https://travis-ci.org/CodeForBaltimore/Bmore-Responsive) [![codecov](https://codecov.io/gh/CodeForBaltimore/Bmore-Responsive/branch/master/graph/badge.svg)](https://codecov.io/gh/CodeForBaltimore/Bmore-Responsive) [![Known Vulnerabilities](https://snyk.io/test/github/CodeForBaltimore/Bmore-Responsive/badge.svg)](https://snyk.io/test/github/CodeForBaltimore/Bmore-Responsive)
2-
3-
# Bmore Responsive
2+
<!-- TOC -->
3+
- [1. Bmore Responsive](#1-bmore-responsive)
4+
- [1.1. Documentation](#11-documentation)
5+
- [1.1.1. API Spec](#111-api-spec)
6+
- [1.1.2. Database Documentation](#112-database-documentation)
7+
- [2. Setup](#2-setup)
8+
- [2.1. Node and Express setup](#21-node-and-express-setup)
9+
- [2.2. Environment variables](#22-environment-variables)
10+
- [2.3. PostgreSQL](#23-postgresql)
11+
- [2.3.1. Sequelize](#231-sequelize)
12+
- [2.4. Docker](#24-docker)
13+
- [3. Using this product](#3-using-this-product)
14+
- [3.1. Testing](#31-testing)
15+
- [4. Sources and Links](#4-sources-and-links)
16+
<!-- /TOC -->
17+
# 1. Bmore Responsive
418
An API to drive disaster and emergency response systems.
519

6-
## Documentation
20+
## 1.1. Documentation
721
We've included a `docs` folder with a template [Tech Spec](/docs/Tech_Spec.md) and [Best Practices](/docs/Best_Practices.md) document, though using Github's Wiki capabilities is also a good idea. This will get you started with documenting your project. Other documents and relevant information that has no other place can live in the `docs` folder. Replace this paragraph with a brief breakdown of what you've included in your `docs` folder.
822

9-
### API Spec
23+
### 1.1.1. API Spec
1024
Our API spec is on Swagger. You can view it here https://app.swaggerhub.com/apis/codeforbaltimore/bmoreResponsive/1.0.0#/ or you can find the `swagger.json` file in our `docs` folder.
1125

12-
### Database Documentation
26+
### 1.1.2. Database Documentation
1327
Our database documentation can be found in our `docs` folder under `database.csv`. This documentation was created using SchemaSpy. Instructions for use can be found here https://github.com/bcgov/schemaspy
1428

15-
## Setup
29+
# 2. Setup
1630
A `Dockerfile` and `docker-compose` file have been included for convenience, however this may not be the best local setup for this project. For more information on how to use Docker with this project, please see the [docker section](#docker).
1731

1832
To work on this project you should have:
@@ -21,38 +35,31 @@ To work on this project you should have:
2135
- Docker (optional)
2236
Once you have the prerequisite software installed you can proceed to setup this application.
2337

24-
### Node and Express setup
38+
## 2.1. Node and Express setup
2539
This application is designed to work as an API driven by Express. To setup your environment first you must install all required dependencies by running the following command from the root of your project directory:
2640
```
2741
npm install
2842
```
2943
Once all dependencies are installed you will need to setup some environment variables to interact with your database and application.
3044

31-
### Environment variables
45+
## 2.2. Environment variables
3246
You will need to set some local environment variables to run this application. This is true even if you're using Docker.
3347
```
3448
touch .env
3549
echo 'NODE_ENV=local
3650
PORT=<your port>
37-
DATABASE_HOST=<your database host>
38-
DATABASE=<your database name>
39-
DATABASE_USER=<your database user>
40-
DATABASE_PASSWORD=<your database password>
4151
DATABASE_SCHEMA=<your database schema>
4252
JWT_KEY=<your secret JWT seed phrase or key>
4353
DATABASE_URL_DEV=<your connection string based on above variables>
4454
' >> ./.env
4555
```
4656

47-
And example of the `DATABASE_URL_DEV` would be `DATABASE_URL_DEV=postgres://postgres:.@localhost:5432/postgres`
57+
And example of the `DATABASE_URL` would be `DATABASE_URL=postgres://user:pass@example.com:5432/dbname`
4858

4959
The various variables are defined as follows:
5060
- `NODE_ENV` = The label for your environment.
5161
- `PORT` = The local port you wish to run on. Defaults to `3000`.
52-
- `DATABASE_HOST` = The hostname of your db. _Probably_ `localhost` but if you're using our `docker-compose.yml` set it to `db`.
53-
- `DATABASE` = Your database name. Postgres default is `postgres`.
54-
- `DATABASE_USER` = Your local database login username. Postgres default is `postgres`.
55-
- `DATABASE_PASSWORD` = Your local database login password. Postgres default is `postgres`.
62+
- `DATABASE_URL` = The URL string for your db connection. For example: `postgres://user:pass@example.com:5432/dbname`
5663
- `DATABASE_SCHEMA` = Your local database schema. Postgres default is `public`.
5764
- `JWT_KEY` = A secret value to generate JWT's locally.
5865
- `BYPASS_LOGIN` = _optional_ Allows you to hit the endpoints locally without having to login. If you wish to bypass the login process during local dev, set this to `true`.
@@ -63,53 +70,56 @@ _We do not recommend using the default options for PostgreSQL. The above values
6370
- `DATABASE_HOST`: The IP address Docker is running on. You can find this by running `docker-machine ip` but it's usually `192.168.99.100` instead of `localhost`
6471
- `DATABASE_URL_DEV`: This will need to be adjusted as well, for example `DATABASE_URL_DEV=postgres://postgres:.@localhost:5432/postgres` would become `DATABASE_URL_DEV=postgres://postgres:.@192.168.99.100:5432/postgres`
6572

66-
### PostgreSQL
73+
## 2.3. PostgreSQL
6774
***You will need a PostgreSQL database running locally to run this application locally.*** You may setup PostgreSQL however you wish, however we recommend using Docker using the instructions found here: https://hub.docker.com/_/postgres
6875

6976
If you are using the Docker method you may spin up your database layer by running this command:
7077
```
71-
docker run -d -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 postgres
78+
docker run -d -e POSTGRES_PASSWORD=<your chosen password> -p 5432:5432 postgres
7279
```
7380

74-
_Note that POSTGRES_HOST_AUTH_METHOD=trust is insecure and will allow anything to connect to that db! Only use for testing and/or local dev!_
75-
7681
If you're running a database in another way then we trust you can sort it out on your own because you're awesome :sunglasses:
7782

78-
### Sequelize _<optional>_
79-
You can run the application without doing anything and it will create the tables needed to operate automatically. It will not, however, create users. If you would like to seed your database with users you will need to follow a few steps.
80-
1. You may create your database tables without running the application by running `npm run db-create`.
81-
2. You can now seed your database by running `npm run db-seed`.
83+
### 2.3.1. Sequelize
84+
To properly start the application the database needs to be built by Sequlize ahead of time. To do that run the following commands
85+
1. You must create your database tables without running the application by running `npm run db-create` first.
86+
2. _optional_ You can now seed your database if you wish by running `npm run db-seed`.
8287

8388
Example `/migrations` and `/seeders` scripts have been supplied. You can rollback your all seeded data at any time by running `npm run db-unseed` and delete all created tables with `npm run db-delete`.
8489

8590
To create new models, migrations, and seeders you _must_ use the Sequelize CLI commands. Full documentation is here https://sequelize.org/master/manual/migrations.html but here are a few useful commands:
8691
- `npx sequelize-cli model:generate --name User --attributes firstName:string,lastName:string,email:string` - Creates a model under `/src/models` and a migration script.
8792
- `npx sequelize-cli seed:generate --name demo-user` - Creates a seeder for the `User` model and migration previously setup.
8893

89-
### Docker
94+
## 2.4. Docker
9095
To use the `docker-compose.yml` file included you will first need to set [environment variables](#environment-variables). You **MUST** set your `DATABASE_HOST` to `db` to use the `docker-compose` solution.
9196

92-
If you are running your own database, but want to use the `Dockerfile` you will need to run that this way on a Mac:
97+
If you are running your own database, but want to use the `Dockerfile` you will need to run that this way:
9398
```
9499
docker build -t bmoreres .
95-
docker run -d -p 3000:3000 -e DATABASE_HOST=docker.for.mac.host.internal bmoreres
100+
docker run -d -p 3000:3000 --env-file=.env bmoreres
96101
```
97-
On Windows you would run:
102+
Note that `DATABASE_URL` host location will be different depending on what OS you're using. On Mac it is `docker.for.mac.host.internal` and on Windows it is `docker.for.win.host.internal` if using `docker-compose` it will be `db`
103+
104+
You can manually set the environment variables and not use a `.env` file by setting the following vars:
98105
```
99-
docker build -t bmoreres .
100-
docker run -d -p 3000:3000 -e DATABASE_HOST=docker.for.win.host.internal bmoreres
106+
-e NODE_ENV=development
107+
-e PORT=3000
108+
-e DATABASE_DATABASE_SCHEMA=<your database schema>
109+
-e JWT_KEY=<your JWT phrase>
110+
-e DATABASE_URL=<your connection string>
101111
```
102112

103-
## Using this product
113+
# 3. Using this product
104114
You may use this product to create and manage users for your front-end. More to come!
105115
To run the application--after the above steps are completed--run `npm start`.
106116

107-
## Testing
117+
## 3.1. Testing
108118
To test your code you may write test cases to `./index.spec.js` and then run the tests with `npm test`.
109119

110120
To check your linting you may run `npm run lint` and to format and automatically fix your formatting run `npm run format`.
111121

112-
## Sources and Links
122+
# 4. Sources and Links
113123
We are also building a front-end application called [Healthcare Rollcall](https://github.com/CodeForBaltimore/Healthcare-Rollcall) to interact with this backend API. To view that project, or to contribute to it, please visit the repo here: https://github.com/CodeForBaltimore/Healthcare-Rollcall
114124

115125
We will be including multi-repo build processes with the front-end that will reference this project.

docker-compose.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
version: '3'
22
services:
33
api:
4-
build: .
4+
image: bmoreres
55
depends_on:
66
- db
77
links:
88
- "db: database"
99
ports:
1010
- '3000:3000'
11-
command: npm start
11+
command: >
12+
sh -c "npm run db-create &&
13+
npm start"
1214
volumes:
1315
- .:/app/
1416
- /app/node_modules

scripts/dockerrun.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

sequelize/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require('dotenv').config();
22
module.exports = {
33
development: {
4-
use_env_variable: 'DATABASE_URL_DEV',
4+
use_env_variable: 'DATABASE_URL',
55
dialect: 'postgres',
66
}
77
};

src/models/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import _ from 'lodash';
55

66
// Initializes the database.
77
const sequelize = new Sequelize(
8-
process.env.DATABASE,
9-
process.env.DATABASE_USER,
10-
process.env.DATABASE_PASSWORD,
8+
process.env.DATABASE_URL,
119
{
12-
host: process.env.DATABASE_HOST,
1310
dialect: 'postgres'
1411
}
1512
);

0 commit comments

Comments
 (0)