Skip to content
This repository has been archived by the owner on Feb 1, 2019. It is now read-only.

Merge develop into master #419

Merged
merged 5 commits into from
Sep 21, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
44 changes: 44 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Logs
logs

# sass cache
.sass-cache

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
.build

# windows garbage
Thumbs.db
desktop.ini

# mac garbage
*DS_Store

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

app
config
docs
test
scripts
*.md
*.yml
LICENSE
build-docker-container.sh
run-docker-container.sh
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sudo: false
language: node_js
node_js:
- '0.10'
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM alpine:3.2

ADD ./dist /var/www/hmda-pilot
COPY ./docker-files /tmp/scripts

# Use a custom build script instead of messy chained together RUN
# or multiple RUN statements that add bloat to the image
RUN /tmp/scripts/run.sh

EXPOSE 80 443
ENTRYPOINT ["/entrypoint.sh"]
CMD ["nginx"]
13 changes: 13 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,19 @@ module.exports = function (grunt) {
dest: '<%= yeoman.app %>/scripts/modules/'
}]
},
docker: {
options: {
patterns: [{
json: grunt.file.readJSON('./config/environments/docker.json')
}]
},
files: [{
expand: true,
flatten: true,
src: ['./config/config.js'],
dest: '<%= yeoman.app %>/scripts/modules/'
}]
},
production: {
options: {
patterns: [{
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Technologies used include [AngularJS](http://angularjs.org), [Browserify](http:/
```shell
$ grunt test
```
1. Download or clone the HMDA Edit Check API and following the instructions for [running the API locally](https://github.com/cfpb/hmda-edit-check-api#running-locally)
1. Download or clone the HMDA Edit Check API and following the instructions for [running the API locally](https://github.com/cfpb/hmda-edit-check-api#running-locally) or for using the Docker container.

### Running locally

Expand Down Expand Up @@ -79,6 +79,27 @@ $ grunt zip

This task produces `dist/hmda-pilot.zip`, which can then be deployed by your continuous integration platform, or manually deployed into your server environment.

### Using Docker

You can also deploy using a Docker container. You can simply run the `build-docker-container.sh` script to build the container image, or, use the following steps:

```shell
$ grunt build:docker
$ docker build -t hmda-pilot .
```

Now that you have a container image, you have to run it. This requires setting some environment variables for the container:
- `HMDA_PILOT_API_HOST`
- `HMDA_PILOT_API_PORT`
These environment variables configure the proxy configuration in `nginx` to point to the proper API to alleviate issues with CORS (Cross-Origin Resource Sharing) requests, so that the API is accessible via the same URL as the pilot.

An example of using these variables in your run looks like:
```
docker run -d --name hmda-pilot -p 80:80 -e "HMDA_PILOT_API_HOST=my.api.server" -e "HMDA_PILOT_API_PORT=8000" hmda-pilot
```

You can also use the `run-docker-container.sh` script, which will use Docker `--link` to run the API and the pilot on the same machine and automatically configures the envrironment variables for you.

#### Per-Environment Configuration

The HMDA Pilot is currently configured to build and deploy to a Development and Production instance. The config files are written in JSON notation and are located in `config/environments`. Currently, the most important feature of the configuration files is the `apiUrl` which specifies the URL where the HMDA Edit Check API is currently running. This information is required by the application to avoid [CORS](http://enable-cors.org/) errors when the UI tries to talk to the API.
Expand Down
7 changes: 7 additions & 0 deletions build-docker-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
# Create the dist package for docker
grunt build:docker
# Remove any previous instance of the api image
docker rmi -f hmda-pilot
# Build the api image as defined in the Dockerfile in the current dir
docker build -t hmda-pilot .
4 changes: 4 additions & 0 deletions config/environments/docker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"apiUrl": "/api",
"confirmSessionReset": true
}
6 changes: 6 additions & 0 deletions docker-files/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

if [ "$1" = 'nginx' ]; then
/etc/nginx/update-nginx-config.sh
fi
exec $@
32 changes: 32 additions & 0 deletions docker-files/hmda-pilot.conf.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
server {

root /var/www/hmda-pilot;
index index.html;

access_log off;

location / {
try_files $uri $uri/ /index.html;
}

location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 30d;
}

location /api {
proxy_redirect off;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 100 128k;
proxy_buffer_size 8k;
proxy_http_version 1.1;

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://__HOST__:__PORT__;
}
}
33 changes: 33 additions & 0 deletions docker-files/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
user nginx;
worker_processes 2;
worker_rlimit_nofile 40000;
daemon off;

events {
worker_connections 1024;
multi_accept on;
use epoll;
}

http {
include mime.types;
default_type application/octect-stream;

sendfile on;
keepalive_timeout 65;
server_tokens off;
tcp_nodelay on;
types_hash_max_size 1024;
types_hash_bucket_size 512;
server_names_hash_bucket_size 64;
server_names_hash_max_size 512;

client_max_body_size 10m;
client_body_buffer_size 128k;

gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

include /etc/nginx/conf.d/*.conf;
}
14 changes: 14 additions & 0 deletions docker-files/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

##### add dependencies
apk --update add nginx sed
chown -R nginx:nginx /var/www

##### Move some things into place
cp -f /tmp/scripts/nginx.conf /etc/nginx
cp -f /tmp/scripts/hmda-pilot.conf.tmpl /etc/nginx
cp -f /tmp/scripts/entrypoint.sh /
cp -f /tmp/scripts/update-nginx-config.sh /etc/nginx

##### Clean up
rm -rf /var/cache/apk/* /tmp/scripts
19 changes: 19 additions & 0 deletions docker-files/update-nginx-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

# Try to use the manually set variables
# Sets a default via the := syntax if blank or not set
API_HOST=${HMDA_PILOT_API_HOST:=hmda-pilot-api}
API_PORT=${HMDA_PILOT_API_PORT:=8000}

# If the docker --link variables are set, use those
if [ ${HMDA_PILOT_API_PORT_8000_TCP_ADDR:-} ]; then
API_HOST=$HMDA_PILOT_API_PORT_8000_TCP_ADDR
fi
if [ ${HMDA_PILOT_API_PORT_8000_TCP_PORT:-} ]; then
API_PORT=$HMDA_PILOT_API_PORT_8000_TCP_PORT
fi

cat /etc/nginx/hmda-pilot.conf.tmpl \
| sed -e "s/__HOST__/$API_HOST/" \
| sed -e "s/__PORT__/$API_PORT/" \
> /etc/nginx/conf.d/hmda-pilot.conf
5 changes: 5 additions & 0 deletions run-docker-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
# Remove any current container for the UI
docker rm -f hmda-pilot
# Run the UI container, linking in the api container
docker run -d --link hmda-pilot-api --name hmda-pilot -p 80:80 hmda-pilot