init
This commit is contained in:
commit
78a95206a3
3
.arcconfig
Normal file
3
.arcconfig
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"phabricator.uri" : "http://10.0.10.242"
|
||||
}
|
10
.gitattributes
vendored
Normal file
10
.gitattributes
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
# All other files are subjected to the usual algorithm to determine
|
||||
# whether a file is a binary file or a text file, respecting
|
||||
# "core.eol" for all files detected as text files.
|
||||
# "core.autocrlf", if set, will force the conversion to/from CRLF
|
||||
# automatically as necessary for text files.
|
||||
* text=auto
|
||||
|
||||
# shell files are always linefeed
|
||||
*.sh eol=lf
|
||||
|
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
mongodb/devdump/
|
||||
mongodb/mongo/keys/
|
||||
nginx/nginx/
|
||||
nginx/conf/keys/
|
||||
mongodb/.vagrant/
|
||||
minio/.vagrant/
|
88
README.md
Normal file
88
README.md
Normal file
@ -0,0 +1,88 @@
|
||||
This repo contains tools to help run a local version of node_server.
|
||||
|
||||
This is ideal for development and local testing without interfering with
|
||||
any of the servers.
|
||||
|
||||
## To Use
|
||||
|
||||
1. For mongo and minio, install [Virtual Box](https://www.virtualbox.org/).
|
||||
2. For mongo and minio, install [Vagrant](https://www.vagrantup.com/).
|
||||
3. Follow the steps in `mongodb\README.md` to install and run a local mongodb
|
||||
4. Follow the steps in `nginx\README.md` to install and run a local nginx proxy
|
||||
5. Follow the steps in `minio\README.md` to install and run a local minio serverr
|
||||
6. Set the environment for the node server appropriately for the local setup (see below)
|
||||
7. Run your local dev server as (see below)
|
||||
|
||||
## Running local dev server
|
||||
|
||||
To run a local debug server you need to (after installing the support tools as above):
|
||||
|
||||
1. Install node.js 8.x
|
||||
2. Clone the https://bitbucket.org/comcarde/bridge-node-server repo
|
||||
3. Copy the compiled email templates into `node_server/email_templates/` from either
|
||||
* Get them from from Jenkins http://10.0.10.240:8080/job/Emails%20Build/lastSuccessfulBuild/artifact/bin/
|
||||
* Build locally by checking out https://bitbucket.org/comcarde/comcarde-server-emails and `gulp compile --production` then copying bin
|
||||
4. Run `npm install`
|
||||
5. Set the environment variables up as described below
|
||||
6. Run your server using node (e.g. through your prefered IDE)
|
||||
7. Use `gulp test-watcher --cwd node_server` to run unit tests automatically on each file modification
|
||||
|
||||
## REQUIRED Local Debug Server environment variable
|
||||
|
||||
You will need to set your environment for the local debug node server to match
|
||||
this local setup. All standard environment variables used in the server should
|
||||
be included, but the following values should be modified from the real servers.
|
||||
|
||||
| Setting | Value | Reason |
|
||||
|--------------------|----------------------|--------|
|
||||
| `loadbalancer_vip` | `localhost` | Used in `trust proxy` setting in express. Address of the nginx proxy. |
|
||||
| `webAddress` | `localhost` | The expected hostname for requests, for configuring CORS for the portal, etc.|
|
||||
| `mongoUser` | `mdbadmin` | As set in the mongodb VM |
|
||||
| `mongoPassword` | `abc123` | As set in the mongodb VM |
|
||||
| `mongoDBAddress` | `@172.16.0.20:27017` | As set in the mongodb VM |
|
||||
| `mongoUseSSL` | `true` | The mongodb VM uses SSL |
|
||||
| `mongoCACertBase64`| `<certpath>/mongodb.pem` | WARNING: This path is **relative to `node_server`**! Ignore the bad naming, this should point to a PEM file, not a Base64 value! The SSL is encryption only and the CA of the cert is not verified, so *any* pem file will do. The one from the MongoDB setup is a reasonable one to use for dev. Recommended location is `../../mongodb.pem` so it sits outside the git repo and doesn't have to be ignored every commit.|
|
||||
| `minioEndpoint` | "172.16.0.21" | Minio local IP |
|
||||
| `minioPort` | "9000" | Minio local Port |
|
||||
| `minioAccessKey` | "XXXXXXXXXXXXXXXXXXXX" | See /minio/README.md |
|
||||
| `minioSecretKey` | "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | See /minio/README.md |
|
||||
| `minioStorageBucket` | "dev" | Name of Minio bucket |
|
||||
|
||||
Other required fields will be notified at startup.
|
||||
|
||||
## OPTIONAL Debug Server environment
|
||||
|
||||
The following optional environment variables can be useful depending on what
|
||||
parts of the server you are wanting to debu
|
||||
|
||||
| Setting | Value | Reason |
|
||||
|--------------------|----------------------|--------|
|
||||
| `debug` | `core:*,ComServe:*` | Defines which `debug()` statements in the code to enable. See the [debug module on NPM](https://www.npmjs.com/package/debug) for details |
|
||||
|
||||
## Optional Code Modifications for local dev
|
||||
|
||||
The following code modifications can make it easier to do local development:
|
||||
|
||||
### Removing HMAC checks
|
||||
|
||||
When using Postman or similar to simulate a device and call the commands you want
|
||||
to test, it is easier to disable the HMAC checking (as HMACs are hard to calculate
|
||||
in Postman).
|
||||
|
||||
At the top of `ComServe/auth.js` -> `checkHMAC()`, add:
|
||||
```
|
||||
next(null);
|
||||
return;
|
||||
```
|
||||
to remove the checks.
|
||||
|
||||
### Debug the webconsole
|
||||
|
||||
If you are debugging the webconsole project, and it's running on http instead of
|
||||
https, you need to change the CORS config or the browser will block your requests.
|
||||
|
||||
At the top of `swagger_api\api_cors_middleware.js` change:
|
||||
|
||||
`const ORIGIN_PROTOCOL = 'https';`
|
||||
to:
|
||||
`const ORIGIN_PROTOCOL = 'http';`
|
70
minio/README.md
Normal file
70
minio/README.md
Normal file
@ -0,0 +1,70 @@
|
||||
# Summary
|
||||
This directory contains scripts for starting a VM running Minio - an open source object storage
|
||||
server with an Amazon S3 compatibl API.
|
||||
|
||||
The sections are:
|
||||
|
||||
* **Connection Information**: The connection details for the object store
|
||||
* **Setup**: Steps required for setup
|
||||
* **Maintenance**: How to bring minio up again if the VM wasn't suspended properly
|
||||
|
||||
Note, the information on connecting a local server to Minio is contained in the top-level README.md.
|
||||
|
||||
# Connection information:
|
||||
|
||||
* URL for web frontend: http://172.16.0.21:9000/
|
||||
* Access Key & Secret Key: Displayed on first run, or available from `/root/.minio/config.json`
|
||||
|
||||
* Environment variables for dev server:
|
||||
```
|
||||
"minioEndpoint": "172.16.0.21",
|
||||
"minioPort": "9000",
|
||||
"minioAccessKey": "XXXXXXXXXXXXXXXXXXXX",
|
||||
"minioSecretKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
||||
"minioStorageBucket": "dev"
|
||||
```
|
||||
|
||||
# Setup
|
||||
|
||||
## Pre-requisites
|
||||
|
||||
1. Install [Virtual Box](https://www.virtualbox.org/).
|
||||
2. Install [Vagrant](https://www.vagrantup.com/).
|
||||
|
||||
## To Start
|
||||
|
||||
1. `vagrant up` from the shell/console
|
||||
2. Go to http://172.16.0.21:9000/
|
||||
3. Log in with Access Key and Secret Key (displayed on first run or in `/root/.minio/config.json`)
|
||||
4. Click the *`+`* sign in the bottom right and choose *"Create Bucket"*
|
||||
5. Name the bucket *"dev"*
|
||||
|
||||
NOTE: Steps 2-5 are only needed on first start
|
||||
|
||||
The first time, This will create and start an entirely new VM, download and install all packages, etc.
|
||||
After that, this will only start up the suspended VM again.
|
||||
|
||||
NOTE: if the PC is rebooted without suspending the VM, the VM will be "powered down" and will not
|
||||
have minio running next time it is resumed with `mongo up`. See *Maintenance* section below for
|
||||
how to bring minio up again.
|
||||
|
||||
## To Stop
|
||||
|
||||
1. `vagrant suspend`
|
||||
|
||||
This will suspend the VM, retaining all data.
|
||||
|
||||
## To Reset
|
||||
|
||||
1. `vagrant destroy`
|
||||
2. `vagrant up`
|
||||
|
||||
This will entirely reset the VM, losing all previous data. You have been warned!
|
||||
|
||||
# Maintenance
|
||||
Login to the VM from the host and restart minio:
|
||||
|
||||
1. `vagrant ssh`
|
||||
2. `sudo killall minio` to kill any running minio
|
||||
3. `cd minio`
|
||||
3. `sudo ./minio server ./data &` to start it again
|
41
minio/Vagrantfile
vendored
Normal file
41
minio/Vagrantfile
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# All Vagrant configuration is done below. The "2" in Vagrant.configure
|
||||
# configures the configuration version (we support older styles for
|
||||
# backwards compatibility). Please don't change it unless you know what
|
||||
# you're doing.
|
||||
Vagrant.configure(2) do |config|
|
||||
#
|
||||
# Mongo box definition
|
||||
#
|
||||
config.vm.define "minio" do |minio|
|
||||
# Every Vagrant development environment requires a box. You can search for
|
||||
# boxes at https://atlas.hashicorp.com/search.
|
||||
minio.vm.box = "ubuntu/xenial64"
|
||||
|
||||
config.vm.provider "virtualbox" do |v|
|
||||
v.memory = 2048
|
||||
v.cpus = 2
|
||||
end
|
||||
|
||||
# Create a private network, which allows host-only access to the machine
|
||||
minio.vm.network "private_network", ip: "172.16.0.21"
|
||||
|
||||
# Share an additional folder to the guest VM. The first argument is
|
||||
# the path on the host to the actual folder. The second argument is
|
||||
# the path on the guest to mount the folder. And the optional third
|
||||
# argument is a set of non-required options.
|
||||
# minio.vm.synced_folder "./data", "/vagrant_data"
|
||||
|
||||
# Enable provisioning with a shell script. Additional provisioners such as
|
||||
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
|
||||
# documentation for more information about their specific syntax and use.
|
||||
# config.vm.provision "shell", inline: <<-SHELL
|
||||
# sudo apt-get update
|
||||
# sudo apt-get install -y apache2
|
||||
# SHELL
|
||||
minio.vm.provision :shell, path: "bootstrap.sh"
|
||||
end
|
||||
|
||||
end
|
17
minio/bootstrap.sh
Normal file
17
minio/bootstrap.sh
Normal file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Make a directory for the minio binary
|
||||
#
|
||||
mkdir minio
|
||||
cd minio
|
||||
|
||||
#
|
||||
# Download and run the minio binary as specified at:
|
||||
# https://www.minio.io/downloads.html#download-server-linux-x64
|
||||
#
|
||||
wget https://dl.minio.io/server/minio/release/linux-amd64/minio
|
||||
|
||||
chmod +x minio
|
||||
|
||||
./minio server ./data &
|
1
mongodb
Submodule
1
mongodb
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 8f89fe12d7bb4f36494b80515bf76ef2ce4538b6
|
35
nginx/README.md
Normal file
35
nginx/README.md
Normal file
@ -0,0 +1,35 @@
|
||||
This uses Nginx as the SSL offload / proxy for your local debug server.
|
||||
|
||||
The nginx server will server `https://localhost` and will proxy that straight
|
||||
through to `http://localhost` (where your development server should be running).
|
||||
|
||||
|
||||
## Pre-requisites
|
||||
|
||||
1. Download nginx from http://nginx.org/en/download.html
|
||||
|
||||
2. Unzip to /nginx directory below this one.
|
||||
NOTE: the downloaded zip files like have a nested folder with the version
|
||||
number, e.g. nginx-1.11.9. You MUST rename and move folders such that
|
||||
you end up with nginx/nginx.exe being a valid exe.
|
||||
|
||||
3. Run "make-ssl-keys.bat" to create self-signed keys.
|
||||
WARNING: You will be asked questions.
|
||||
The important one is "Common Name"
|
||||
Set this to "localhost" or the IP address that you expect to connect
|
||||
to your local dev server on.
|
||||
|
||||
## To Start nginx
|
||||
|
||||
1. Run "start-nginx.exe"
|
||||
2. Look in the process list and see if nginx.exe is running.
|
||||
|
||||
If not, try just running nginx\nginx.exe from the command line to view any errors.
|
||||
|
||||
WARNING: you cannot stop nginx using Ctrl+C. See below for how to stop it.
|
||||
|
||||
## To Stop nginx
|
||||
|
||||
1. Run "stop-nginx.exe"
|
||||
|
||||
Alternatively, kill the nginx processes using task manager
|
62
nginx/conf/nginx.conf
Normal file
62
nginx/conf/nginx.conf
Normal file
@ -0,0 +1,62 @@
|
||||
|
||||
#user nobody;
|
||||
worker_processes 1;
|
||||
|
||||
#error_log logs/error.log;
|
||||
#error_log logs/error.log notice;
|
||||
error_log logs/error.log info;
|
||||
|
||||
#pid logs\nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
#include mime.types;
|
||||
#default_type application/octet-stream;
|
||||
|
||||
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
# '$status $body_bytes_sent "$http_referer" '
|
||||
# '"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
#access_log logs/access.log main;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
#keepalive_timeout 0;
|
||||
keepalive_timeout 65;
|
||||
|
||||
#gzip on;
|
||||
|
||||
# HTTPS server
|
||||
#
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name localhost;
|
||||
|
||||
ssl_certificate keys/nginx-selfsigned.crt;
|
||||
ssl_certificate_key keys/nginx-selfsigned.key;
|
||||
|
||||
ssl_session_cache shared:SSL:1m;
|
||||
ssl_session_timeout 5m;
|
||||
|
||||
ssl_ciphers HIGH:!aNULL:!MD5;
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
location / {
|
||||
proxy_pass http://localhost:8080;
|
||||
|
||||
# Headers as recommneded at https://www.nginx.com/resources/wiki/start/topics/examples/SSL-Offloader/
|
||||
proxy_set_header Accept-Encoding ""; # no backend compression
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Forwarded-By $server_addr:$server_port;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
1
nginx/logs/nginx.pid
Normal file
1
nginx/logs/nginx.pid
Normal file
@ -0,0 +1 @@
|
||||
18984
|
9
nginx/make-ssl-keys.bat
Normal file
9
nginx/make-ssl-keys.bat
Normal file
@ -0,0 +1,9 @@
|
||||
@echo off
|
||||
echo --------------------------------------------------------------------
|
||||
echo Making self-signed keys for the HTTPS proxy.
|
||||
echo You will be asked to answer some questions. The important one is:
|
||||
echo "Common Name"
|
||||
echo Set this to localhost, 127.0.0.1., or your machine's IP address
|
||||
echo --------------------------------------------------------------------
|
||||
mkdir conf/keys
|
||||
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout conf/keys/nginx-selfsigned.key -out conf/keys/nginx-selfsigned.crt
|
10
nginx/make-ssl-keys.sh
Executable file
10
nginx/make-ssl-keys.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
echo "-------------------------------------------------------------------"-
|
||||
echo "Making self-signed keys for the HTTPS proxy."
|
||||
echo "You will be asked to answer some questions. The important one is:"
|
||||
echo "'Common Name'"
|
||||
echo "Set this to localhost, 127.0.0.1., or your machine's IP address"
|
||||
echo "--------------------------------------------------------------------"
|
||||
mkdir conf/keys
|
||||
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout conf/keys/nginx-selfsigned.key -out conf/keys/nginx-selfsigned.crt
|
||||
|
1
nginx/reload-nginx.bat
Normal file
1
nginx/reload-nginx.bat
Normal file
@ -0,0 +1 @@
|
||||
nginx\nginx.exe -s reload
|
12
nginx/reload-nginx.sh
Executable file
12
nginx/reload-nginx.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
echo "Stopping nginx..."
|
||||
if [[ `uname` == 'Darwin' ]]; then
|
||||
echo "Mac"
|
||||
nginx -s reload
|
||||
# /usr/local/Cellar/nginx/1.12.0/bin/nginx -s reload
|
||||
else
|
||||
echo Linux
|
||||
nginx -s reload
|
||||
fi
|
||||
|
||||
nginx\nginx.exe -s quit
|
6
nginx/start-nginx.bat
Normal file
6
nginx/start-nginx.bat
Normal file
@ -0,0 +1,6 @@
|
||||
@echo off
|
||||
echo Making sure directories already exist...
|
||||
mkdir logs
|
||||
mkdir temp
|
||||
echo Starting nginx...
|
||||
START /B nginx\nginx.exe
|
9
nginx/start-nginx.sh
Executable file
9
nginx/start-nginx.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
echo "Making sure directories already exist..."
|
||||
echo -n "Starting nginx "
|
||||
|
||||
mkdir -p /usr/local/var/log/nginx/
|
||||
mkdir -p /usr/local/var/run/nginx/
|
||||
|
||||
nginx -c ${PWD}/conf/nginx.conf
|
||||
echo "nginx configured."
|
1
nginx/stop-nginx.bat
Normal file
1
nginx/stop-nginx.bat
Normal file
@ -0,0 +1 @@
|
||||
nginx\nginx.exe -s quit
|
6
nginx/stop-nginx.sh
Executable file
6
nginx/stop-nginx.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
echo "Stopping nginx..."
|
||||
|
||||
nginx -s quit
|
||||
|
||||
# nginx\nginx.exe -s quit
|
Loading…
Reference in New Issue
Block a user