Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(IN PROGRESS) Dockerize + Updating a few dependencies #290

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .env.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
NODE_ENV=development
PORT=3000
CRYPTO_KEY=k3yb0ardc4t

DB_USERNAME=user
DB_PASSWORD=pass
DB_DATABASE=smokealarm_development
DB_HOST=db
DB_DIALECT=postgres

MAILGUN_API_KEY=__INSERT_API_KEY_KERE__
MAIL_DOMAIN=
MAIL_FROM_ADDR=

TWILIO_ACCOUNT_SID=__INSERT_ACCOUNT_SID_HERE__
TWILIO_AUTH_TOKEN=__INSERT_AUTH_TOKEN_HERE__

GOOGLE_MAPS_API_KEY=__INSERT_API_KEY_HERE__

LOGGING=0
SERVER_ROOT=

COMPANY_NAME="Acme, Inc"
PROJECT_NAME="New Horizons Ansible Retrofit Project"
SYSTEM_EMAIL="jrandom@example.com"

SIGNUP_ENABLED=0
REQUIRE_ACCOUNT_VERIFICATION=0

ALLOWED_LOGIN_ATTEMPTS_IP=50
ALLOWED_LOGIN_ATTEMPTS_USER=7
LOG_EXPIRATION="20m"

SMTP_FROM_NAME=
SMTP_FROM_ADDRESS=
SMTP_USERNAME=
SMTP_PASSWORD=
SMTP_HOST=

OAUTH_TWITTER_KEY=
OAUTH_TWITTER_SECRET=
OAUTH_FACEBOOK_KEY=
OAUTH_FACEBOOK_SECRET=
OAUTH_GITHUB_KEY=
OAUTH_GITHUB_SECRET=
OAUTH_GOOGLE_KEY=
OAUTH_GOOGLE_SECRET=
OAUTH_TUMBLR_KEY=
OAUTH_TUMBLR_SECRET=
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ node_modules
npm-debug.log
err.log
out.log
config.js
*.idea
.env
YaxelPerez marked this conversation as resolved.
Show resolved Hide resolved
config/recipients.sql

# OSX
.DS_Store
5 changes: 5 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const path = require('path');

module.exports = {
'config': path.resolve('config', 'config.js')
};
6 changes: 5 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
This file contains an overview of how to do development on this
application, as well as HOWTOs for specific tasks.

## Testing

`$ make test`

## Architecture Overview

TBD: Explain the various locations in the code tree that we most commonly find ourselves editing to accomplish tasks.
Expand Down Expand Up @@ -208,4 +212,4 @@ are candidates for removal later.
* Status - Part of Drywall package, but not used for this application.
* StatusLog - Part of Drywall package, but not used for this application.
* UsAddress - Used in this application.
* User - Used by Drywall for user management.
* User - Used by Drywall for user management.
162 changes: 79 additions & 83 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,78 @@
# Installing smoke-alarm-portal

These installation instructions assume a Debian GNU/Linux 'testing'
distribution operating system, but they should be portable without
much difficulty to most other Unix-like operating systems.
$ git clone https://github.com/redcross/smoke-alarm-portal.git
$ cd smoke-alarm-portal

## Configuring

1. Download the code.
$ cp .env.tmpl .env

$ git clone https://github.com/OpenTechStrategies/smoke-alarm-portal.git
$ cd smoke-alarm-portal
For development/production, fill in the following values in `.env`:

1. Install [Node](https://nodejs.org/download/) and npm (a package manager).
On Debian, run:
* COMPANY_NAME
* PROJECT_NAME
* SYSTEM_EMAIL
* CRYPTO_KEY
* MAILGUN_API_KEY
* MAIL_DOMAIN
* MAIL_FROM_ADDR
* GOOGLE_MAPS_API_KEY

Non-docker only:

$ sudo apt-get install nodejs
$ sudo apt-get install npm
* DB_USERNAME
* DB_PASSWORD
* DB_DATABASE
* DB_HOST

On Max OSX, use the Macintosh installer which can be downloaded
from https://nodejs.org/download/, to install both node and
npm. In Terminal, run:
## Installing with Docker

$ sudo npm install npm -g
Make sure you have [Docker](https://docs.docker.com/install/) and [Docker
Compose](https://docs.docker.com/compose/install/) installed.

1. Install PostgreSQL, at least version 9.2 (to support `JSON` column type).
$ make build
$ make run

On Debian:
## Installing Locally

$ sudo apt-get install postgresql-9.4 # for example
These installation instructions assume a Debian GNU/Linux 'testing'
distribution operating system, but they should be portable without
much difficulty to most other Unix-like operating systems.

(This may result in your having multiple versions of PostgreSQL
installed, which in turn can lead to mysterious errors in the
coming import step. If you encounter such errors, see the
appropriate part of the "Troubleshooting" section later on.)
1. Install dependencies

On Mac OS X:
**Debian:**

Install PostgreSQL via Brew (http://exponential.io/blog/2015/02/21/install-postgresql-on-mac-os-x-via-brew/).
Installation instructions for brew can be found on the [Homebrew website](http://brew.sh).
$ sudo apt-get install nodejs npm postgresql-9.4

$ brew update
$ brew install postgres
(This may result in your having multiple versions of PostgreSQL installed,
which in turn can lead to mysterious errors in the coming import step. If
you encounter such errors, see the appropriate part of the "Troubleshooting"
section later on.)

1. OPTIONAL: PostgreSQL probably created a `postgres` user, but if it
didn't, you might want to add one:
**MacOS:**

$ adduser postgres
Use the Macintosh installer which can be downloaded from
https://nodejs.org/download/, to install both node and npm and run:

1. Set up the live config files. Note that there are multiple files to
be edited here.

1. Do `cp config.js.tmpl config.js`. For dev, move on to step 2. For non-dev, edit the `config.js` file:

* Update `exports.companyName`,
`exports.projectName`, `exports.signupEnabled`,`exports.systemEmail`, and
`exports.cryptoKey`.
$ sudo npm install npm -g

1. Do `cp config/config.json.tmpl config/config.json`. For dev, move on to step 3. For non-dev, edit the `config/config.json`:
Install PostgreSQL via Homebrew
(http://exponential.io/blog/2015/02/21/install-postgresql-on-mac-os-x-via-brew/).
Installation instructions for brew can be found on the [Homebrew website](http://brew.sh).

* Fill in database usernames and passwords, and
the Mailgun.com API key and sender information that the app will use to send out email notifications.
You can modify one of the existing top-level environments listed in `config.json`
or set up a whole new environment, e.g., "demo" (e.g., based on the "test" example).
$ brew update
$ brew install postgres

To enable Geocoding of entered addresses, make sure to configure your
Google Maps geocoding API key: `googleMapsApiKey`
2. OPTIONAL: PostgreSQL probably created a `postgres` user, but if it didn't,
you might want to add one:

(Don't worry if you don't know how to set up a database
username / password; that will be explained in a later step.)
$ adduser postgres

1. Do `cp config/recipients.sql.tmpl config/recipients.sql`, edit the `config/recipients.sql` file:
3. Do `cp config/recipients.sql.tmpl config/recipients.sql`, edit the `config/recipients.sql` file:

* Fill in appropriate contact names and email
addresses.
* For dev, either leave the placeholders intact (if you didn't set up Mailgun and don't want to test the email-sending functionality) or replace the placeholders with your name and email address (so that when you submit test requests to your local instance, all the emails generated come to you).
* Fill in appropriate contact names and email addresses.
* For dev, either leave the placeholders intact (if you didn't set up Mailgun and don't want to test the email-sending functionality) or replace the placeholders with your name and email address (so that when you submit test requests to your local instance, all the emails generated come to you).

1. Get other required node modules.

Expand Down Expand Up @@ -159,40 +160,34 @@ be edited here.

$ ./node_modules/.bin/forever -da start --watchDirectory . -l forever.log -o out.log -e err.log ./bin/www

1. See if it's working, by visiting http://localhost:3000/

TBD: Need instructions for changing to port 80 and eventually 443
for demo and production.
## Creating an admin user

1. Create an admin user.
To create the admin user, you must first temporarily re-enable signups, which
are disabled by default.

To create the admin user, you must first temporarily re-enable
signups, which are disabled by default.
1. In `.env`, change `SIGNUP_ENABLED` from `0` to `1`.

1. In `config.js`, change `exports.signupEnabled` from `false` to `true`.
2. Visit http://localhost:3000/signup in your browser

1. Visit http://localhost:3000/signup in your browser
3. Create a user named `admin` there (remember the password you choose)

1. Create a user named `admin` there (remember the password you choose)

1. In `config.js`, change `exports.signupEnabled` back to `false`.
4. In `.env`, change `SIGNUP_ENABLED` back to `0`.
(If you don't do this step, anyone who can figure out the URL can
create a user account with administrative privileges, which would
obviously be bad.)

1. Grant your new admin user permission to view requests from all
regions, using this file:
5. Grant your new admin user permission to view requests from all regions,
using this file:
[migrations/20151208-admin-access.sql.tmpl](migrations/20151208-admin-access.sql.tmpl).
Following the instructions in the file, copy it to
`migrations/20151208-admin-access.sql` and replace the
`__USER_ID__` with the id of your new admin user (if the admin
user was the first user you created, then this will probably be
`1`). Once you've done that, run the following commands:

```
$ psql smokealarm_development
smokealarm_development=# \i migrations/20151208-admin-access.sql
```
migrations/20151208-admin-access.sql` and replace the __USER_ID__` with
the id of your new admin user (if the admin user was the first user you
created, then this will probably be 1).

6. Once you've done that, run the following commands:

Docker: `docker-compose run db psql -d smokealarm_development -f migrations/20151208-admin-access.sql`
Local: `psql -d smokealarm_development -f migrations/20151208-admin-access.sql`

Now you can visit http://localhost:3000/login/ at any time, log in
as `admin`, and from there click on "Smoke Alarm Installation Requests"
Expand All @@ -204,19 +199,20 @@ be edited here.
page (http://localhost:3000/) before any requests would be listed
on the /admin/requests page.)

1. Sign up for [Twilio](https://www.twilio.com): Set up a number that
## Signing up for [Twilio](https://www.twilio.com)

* Create account, or use the OTS account (if part of OTS)
* Get a new phone number (in Manage Phone Numbers)
* Update `config/config.json` twilio parameters to the account SID/Auth Token
in your settings on twilio
* Setup the phone number in twilio messaging section to be
* Webhook -> `http://<yourtestsite>/sms`, using `HTTP GET`
* Create account, or use the OTS account (if part of OTS)
* Get a new phone number (in Manage Phone Numbers)
* Update `config/config.json` twilio parameters to the account SID/Auth Token in your settings on twilio
* Setup the phone number in twilio messaging section to be
* Webhook -> `http://<yourtestsite>/sms`, using `HTTP GET`

Then when you start your server up, you should be able to text the number you
set up to test the system.
Then when you start your server up, you should be able to text the number you
set up to test the system.

## Testing

1. Manually perform tests listed in [TESTING.md](docs/TESTING.md).
See testing instructions at [TESTING.md](docs/TESTING.md).

Appendix A: Setting up Apache->Node ProxyPass with https://
-----------------------------------------------------------
Expand Down
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
run:
docker-compose up
YaxelPerez marked this conversation as resolved.
Show resolved Hide resolved

test:
docker-compose -f docker-compose.testing.yml run --rm test
build: setup migrate
setup:
cp -f config/recipients.sql.tmpl config/recipients.sql

docker volume create smokealarm_nodemodules
docker volume create smokealarm_postgres
docker-compose -f docker-compose.builder.yml run --rm npm_install

migrate:
docker-compose -f docker-compose.builder.yml run --rm migrate

clean:
rm -f config/recipients.sql
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should rm -f .env be added here too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided makefile shouldn't mess with .env since it's deploy-specific

rm -rf node_modules

docker-compose rm -f
docker volume rm -f smokealarm_nodemodules
docker volume rm -f smokealarm_postgres
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

'use strict';

require('dotenv').config();

var config = require('./config'),
express = require('express'),
cookieParser = require('cookie-parser'),
Expand Down
2 changes: 1 addition & 1 deletion bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var server = http.createServer(app);
* Listen on provided port, on all network interfaces.
*/

server.listen(port, 'localhost');
server.listen(port, '0.0.0.0');
server.on('error', onError);
server.on('listening', onListening);

Expand Down
Loading