Server deployment stuff

This commit is contained in:
John Lyon-Smith
2018-03-19 15:04:10 -07:00
parent 59c11d791d
commit faf99108e9
12 changed files with 164 additions and 33 deletions

6
server/.rsync-exclude Normal file
View File

@@ -0,0 +1,6 @@
.*
package-lock.json
src/
scratch/
node_modules/
local-*

View File

@@ -1,7 +0,0 @@
{
awsConfig: {
accessKeyId: 'AKIAJUP6XRVYDAXNTUNA',
secretAccessKey: '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',
region: 'us-west-2'
}
}

View File

@@ -1,7 +1,7 @@
{
logDir: '/var/log/deighton-ar',
api: {
port: '3001',
port: '3005',
loginKey: '*',
uploadTimout: 120,
maxEmailTokenAgeInHours: 36,

View File

@@ -8,7 +8,7 @@ User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu/deighton-ar/server
Environment='NODE_ENV=production'
ExecStart=/usr/bin/node src/server.js
ExecStart=/usr/bin/node dist/server.js
Restart=on-abort
[Install]

View File

@@ -1,16 +1,16 @@
#!/bin/bash
script_dir=$(dirname $0)
script="${script_dir}/src/bin/$1"
script="${script_dir}/dist/bin/${1}.js"
if [[ -z "$1" ]]; then
echo "usage: $(basename $0) <command>"
echo ""
echo "Available scripts are"
ls -1 ${script_dir}/src/bin
echo "Available commands are"
echo ""
find ${script_dir}/dist/bin -name \*.js -exec basename {} .js \;
exit -1
fi
# For scripts that need config access
export NODE_CONFIG_DIR="${script_dir}/config"

View File

@@ -5,9 +5,9 @@
"main": "src/server.js",
"scripts": {
"start": "babel-node src/server.js",
"start:prod": "NODE_ENV=production npm start",
"build": "babel src -d dist -s",
"serve": "NODE_ENV=production node dist/server.js",
"start:prod": "NODE_ENV=production node dist/server.js",
"build": "rm -rf dist && babel src -d dist -s",
"deploy": "rsync -vr -e ssh --exclude-from .rsync-exclude * ubuntu@tmr:deighton-ar/server/",
"test": "jest",
"actor:api": "monzilla 'src/api/**/*.js:src/database/**/*.js' -- babel-node src/api/index.js",
"actor:api:debug": "babel-node --inspect-brk src/api/index.js",

View File

@@ -10,7 +10,7 @@ import util from 'util'
import autoBind from 'auto-bind2'
class SendMessageTool {
class AddUserTool {
constructor(toolName, log) {
autoBind(this)
this.toolName = toolName
@@ -20,7 +20,9 @@ class SendMessageTool {
async run() {
const mongoUri = config.get('uri.mongo')
new DB().connect(mongoUri).then((db) => {
try {
const db = await new DB().connect(mongoUri)
console.log(`Connected to MongoDB at ${mongoUri}`)
const User = db.User
@@ -33,18 +35,16 @@ class SendMessageTool {
let password = readlineSync.question('Password? ', {hideEchoBack: true})
let cr = credential()
util.promisify(cr.hash)(password).then((json) => {
user.passwordHash = JSON.parse(json)
const json = await util.promisify(cr.hash)(password)
return user.save()
}).then((savedUser) => {
console.log(`User is ${user}`)
process.exit(0)
}).catch((error) => {
console.log(`error: ${error.message}`)
process.exit(-1)
})
})
user.passwordHash = JSON.parse(json)
const savedUser = await user.save()
console.log(`User is ${user}`)
} catch(error) {
console.log(`error: ${error.message}`)
}
}
}
@@ -54,7 +54,7 @@ const log = {
warning: function() { console.error(chalk.yellow('warning:', [...arguments].join(' ')))}
}
const tool = new AddUserTool('add-user', log)
const tool = new AddUserTool('addUser', log)
tool.run(process.argv.slice(2)).then((exitCode) => {
process.exit(exitCode)

View File

@@ -110,7 +110,7 @@ const log = {
warning: function() { console.error(chalk.yellow('warning:', [...arguments].join(' ')))}
}
const tool = new SendMessageTool('send-message', log)
const tool = new SendMessageTool('sendMessage', log)
tool.run(process.argv.slice(2)).then((exitCode) => {
process.exit(exitCode)

View File

@@ -3,6 +3,8 @@ import { ServerTool } from './ServerTool'
import pino from 'pino'
import * as pinoExpress from 'pino-pretty-express'
import path from 'path'
import fs from 'fs'
import config from 'config'
const serviceName = 'dar-server'
const isProduction = (process.env.NODE_ENV == 'production')