Skip to content

Commit

Permalink
Merge entire oam-uploader-api-repo with history
Browse files Browse the repository at this point in the history
Just resolves conflicts
  • Loading branch information
tombh committed Jun 2, 2017
2 parents 902a7ab + 366533c commit ec16f28
Show file tree
Hide file tree
Showing 46 changed files with 2,280 additions and 88 deletions.
8 changes: 8 additions & 0 deletions .build_scripts/deploy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[stage]
host 52.11.15.48
user ubuntu
repo https://github.com/hotosm/oam-uploader-api.git
path /home/ubuntu/oam-uploader-api
ref origin/develop
needs_tty yes
post-deploy .build_scripts/post-deploy.sh
54 changes: 54 additions & 0 deletions .build_scripts/docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# This script runs the docker container for this application, by:
# - passing in the environment variables defined in local.env, if it exists
# - overriding the above with any relevant variables in the current environment
# (see config.js)
# - exposing the $PORT (default: 3000), on which the app listens
# - setting the container to use the host OS's networking stack (better
# performance, worse isolation)
# - mounting the current directory--which should be the project root--as
# `/local`.
#
# The intent of the last item is that the app can be setup (npm install) and
# run directly from its location on the host OS, but using the container as its
# environment to make dependency management trivial.

if [ -f local.env ] ; then
ENVFILE="--env-file local.env"
else
ENVFILE=""
fi

if [[ -t 0 || -p /dev/stdin ]] ; then
echo "Running in tty mode."
MODE=-it
else
MODE=
fi

PORT=${PORT:-3000}

ARGS_LENGTH=$(($#-1))
ARGS=${@:1:$ARGS_LENGTH}
COMMAND=${@:$((ARGS_LENGTH+1)):1}

exec docker run $MODE --rm \
-p $PORT \
$ENVFILE \
-e OAM_TEST \
-e PORT \
-e HOST \
-e OIN_BUCKET \
-e DBURI \
-e DBURI_TEST \
-e MAX_WORKERS \
-e ADMIN_PASSWORD \
-e ADMIN_USERNAME \
-e AWS_SECRET_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-e AWS_REGION \
--net=\"host\" \
-v $(pwd):/app \
$ARGS \
oam-uploader-api $COMMAND
5 changes: 5 additions & 0 deletions .build_scripts/docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# Run the server inside docker.

npm start
5 changes: 5 additions & 0 deletions .build_scripts/docker/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# Run the tests inside docker.

npm test
5 changes: 5 additions & 0 deletions .build_scripts/post-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

.build_scripts/docker/run.sh /install.sh
sudo stop oam-uploader-api
sudo start oam-uploader-api
45 changes: 45 additions & 0 deletions .build_scripts/reset-db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env node
'use strict';
var readline = require('readline');
var MongoClient = require('mongodb').MongoClient;
var dbUri = require('../config').dbUri;

var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

rl.question("Type 'yes' if you really want to clear the database: ", function (answer) {
if (answer === 'yes') {
console.log('Okay, doing it!');
MongoClient.connect(dbUri, function (err, connection) {
if (err) throw err;
console.log('Connected to db.');
console.log('Dropping workers');
connection.dropCollection('workers')
.then(function () {
console.log('Dropping uploads');
return connection.dropCollection('uploads');
})
.then(function () {
console.log('Dropping tokens');
return connection.dropCollection('tokens');
})
.then(function () {
console.log('Dropping images');
return connection.dropCollection('images');
})
.then(function () {
console.log('Done.');
connection.close();
})
.catch(function (err) {
console.error(err);
connection.close();
});
});
} else {
console.log('Abort! Whew!');
}
rl.close();
});
30 changes: 30 additions & 0 deletions .build_scripts/upstart.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!upstart
description "oam-uploader-api server"
author "anand"

start on filesystem and started docker
stop on runlevel [!2345]

env USER=ubuntu
env OAM_UPLOADER_DIR=/home/ubuntu/oam-uploader-api/current

script
echo $$ > /var/run/oam-uploader-api.pid
cd $OAM_UPLOADER_DIR
exec sudo -u $USER $OAM_UPLOADER_DIR/.build_scripts/docker/run.sh --name=oam-uploader-api /start.sh >> /var/log/oam-uploader-api.sys.log 2>&1
end script

pre-start script
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/oam-uploader-api.sys.log
end script

pre-stop script
rm /var/run/oam-uploader-api.pid
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/oam-uploader-api.sys.log
docker stop oam-uploader-api
end script

post-stop script
rm /var/run/oam-uploader-api.pid
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopped" >> /var/log/oam-uploader-api.sys.log
end script
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ node_modules
newrelic_agent.log
npm-debug.log
.travis.yml
.build_scripts
.build_scripts
.env
.git
local.env
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": ["standard"],
"extends": ["standard", "standard-react"],
"env": {
"es6": true
},
Expand All @@ -8,4 +8,4 @@
"no-extra-semi": 2,
"semi-spacing": [2, { "before": false, "after": true }]
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ tmp
scratch.js
docs
local.env

66 changes: 0 additions & 66 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.5.0
4.5.0
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sudo: required
language: node_js

node_js:
Expand All @@ -12,6 +13,20 @@ env:
services: mongodb

before_install:
- echo "Installing libvips..."
- sudo add-apt-repository -y ppa:lovell/precise-backport-vips
- sudo apt-get update
- sudo apt-get install -y libvips-dev
- echo "Completed libvips installation."
- echo "Installing latest mongodb"
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
- echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
- sudo apt-get update && sudo apt-get install -y mongodb-org
- sudo service mongod restart
- echo "Completed installing mongodb"
- echo "Installing gdal-bin"
- sudo apt-get install gdal-bin
- echo "Completed installing gdal-bin"
- chmod +x ./.build_scripts/docs.sh

after_success:
Expand Down
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
brew 'mongodb'
19 changes: 18 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:4
FROM quay.io/hotosm/oam-dynamic-tiler-tools
ENV NPM_CONFIG_LOGLEVEL warn

# Install app dependencies
Expand All @@ -12,6 +12,23 @@ WORKDIR /usr/src/app
# Bundle app source
ADD . /usr/src/app

# Go ahead and install nodemon for convenience while developing
RUN \
npm install -g nodemon \
&& rm -rf /root/.npm

# Set TMPDIR environment variable
ENV TMPDIR /tmp

COPY . /app

WORKDIR /app

RUN \
npm install \
&& rm -rf /root/.npm

EXPOSE 4000

CMD [ "node", "index.js" ]

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2016, Development Seed
Copyright (c) 2016, Humanitarian Open Street Map Team
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ The worker process runs on a schedule (every 5 minutes by default) and checks fo
- `SECRET_TOKEN` - The token used for post requests to `/tms` endpoint
- `NEW_RELIC_LICENSE_KEY` - Your New Relic API monitoring license key

- `NODE_ENV` - Node environment. When in production should be set to `production`, otherwise can be ignored.
- `PORT` - The port to listen on (Default to 4000).
- `HOST` - The hostname or ip address (Default to 0.0.0.0).
- `COOKIE_PASSWORD` - Password used for cookie encoding. Should be at least 32 characters long. IMPORTANT to change the default one for production.
- `AWS_ACCESS_KEY_ID` - AWS secret key id for reading `OIN_BUCKET`.
- `AWS_SECRET_ACCESS_KEY` - AWS secret access key for reading `OIN_BUCKET`.
- `AWS_REGION` - AWS region of `OIN_BUCKET` (Default to us-west-2).
- `SENDGRID_API_KEY` - Sendgrid API key, for sending notification emails.
- `SENDGRID_FROM` - Email address from which to send notification emails (Default to [email protected]).
- `OIN_BUCKET` - The OIN bucket that will receive the uploads (Default to oam-uploader).
- `DBURI` - MongoDB connection url (Default to mongodb://localhost/oam-uploader)
- `DBURI_TEST` - MongoDB connection url for tests. Will be loaded when `NODE_ENV` is `test`. It's not needed for production. (Default to mongodb://localhost/oam-uploader-test)
- `ADMIN_USERNAME` - Username to access the [Token Management](https://github.com/hotosm/oam-uploader-admin) panel.
- `ADMIN_PASSWORD` - Password to access the [Token Management](https://github.com/hotosm/oam-uploader-admin) panel.
- `GDRIVE_KEY` - Google Api key. Needed to use the upload from google drive functionality.
- `GDAL_TRANSLATE_BIN` - Full path to the gdal bin (Default to /usr/bin/gdal_translate)
- `MAX_WORKERS` - Max number of workers used to process the uploads (Default to 1)
- `NEW_RELIC_LICENSE_KEY` - New relic license key.
- `TILER_BASE_URL` - Base URL for dynamic TMS/WMTS endpoints. Defaults to `http://tiles.openaerialmap.org`.

If you are running a local OAM bucket, here are additional environment variables you can configure (more information in the Docker > Local Indexing section)
- `HOST_PREFIX`: - Used by the localoam service to construct URIs that point to the images (default: `http://localoam`)
- `LOCAL_OAM_BUCKET`: - Used by the localoam service as the location of the HTTP server (default is a docker context service name: `http://localoam:4999`)
Expand Down
Loading

0 comments on commit ec16f28

Please sign in to comment.