Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactor conf

  • Loading branch information...
commit 9118d63f4a1a0ce2b4f7e415d56a614f62525cee 1 parent f16f3ca
@Filirom1 Filirom1 authored
View
2  .gitignore
@@ -1,3 +1,5 @@
node_modules/
local.env
+.env
certs/
+npm-debug.log
View
2  Procfile
@@ -1 +1 @@
-web: apiserver/bin/apiserver
+apiserver: apiserver/bin/apiserver
View
41 README.md
@@ -72,32 +72,29 @@ make certs
## Environment Variables
-Other environment variables could be configured but the following ones are required.
+apiserver/bin/apiserver will check for the presence of several environment variables,
+these must be configured as part of the process start - e.g. configured in
+supervisord or as part of boot script see ./apiserver/conf.js
+
+* PG_USER - Your login name, unless you set something else.
+* S3_KEY - You need an Amazon S3 account to store repos and slug archive
+* S3_SECRET - You need an Amazon S3 account to store repos and slug archive
+* S3_BUCKET - You need an Amazon S3 account to store repos and slug archive
+
+## Launch
-Edit your ~/.bashrc and add the following lines:
-```
-export API_SERVER_KEY=$WHAT_WAS_WRITTEN_AT_THE_END_OF_POSTGRES_SETUP
-export PGUSER=$YOUR_LOGIN_NAME
-export S3_KEY=$YOUR_AMAZON_S3_KEY
-export S3_SECRET=$YOUR_AMAZON_S3_SECRET
-export S3_BUCKET=$YOUR_AMAZON_S3_BUCKET
```
+$ cat > .env << EOF
+PG_USER=$YOUR_LOGIN_NAME
+S3_KEY=$YOUR_AMAZON_S3_KEY
+S3_SECRET=$YOUR_AMAZON_S3_SECRET
+S3_BUCKET=$YOUR_AMAZON_S3_BUCKET
+EOF
+foreman start
+```
-apiserver/bin/apiserver will check for the presence of several environment variables,
-these must be configured as part of the process start - e.g. configured in
-supervisord or as part of boot script see ./debug.launch for example
-
-* BASE_HOST - base host of the API server (e.g. localhost:5000)
-* BASE_PROTOCOL- base protocl of the API server (e.g. http)
-* PORT - TCP port to bind server to (<1024 require superuser privileges)
-* PRIVATE_KEY - Path to private key in pem format (can be relative to project root)
-* PUBLIC_KEY - Path to public key in pem format (can be relative to project root)
-* S3_KEY - Your AWS S3 key for the repo and slug bucket
-* S3_SECRET - Your AWS S3 secret for the repo and slug bucket
-* S3_BUCKET - Name of S3 bucket to store slugs and repos
-
-## Help and Todo
+## Help and Todo
Loads to do on this part, not limited to:
View
7 apiserver/api/internal.js
@@ -5,6 +5,7 @@ var db = require('../apidb');
var dbfacade= require('../dbfacade')(db);
var async = require('async');
var yaml = require('js-yaml');
+var conf = require('../conf');
module.exports = {
lookupUserByPublicKey: {
@@ -93,6 +94,8 @@ module.exports = {
method: 'POST',
okayCode: 200
},
+
+ // TODO is it used ?
getAppMetadata: {
routePath : '/internal/:appName/metadata',
payloadSource: 'query',
@@ -106,8 +109,8 @@ module.exports = {
var realResponse = this.responsePayload = {};
- var repoSigner = s3url.createSigner(process.env['S3_REPOS_BUCKET']);
- var slugSigner = s3url.createSigner(process.env['S3_SLUGS_BUCKET']);
+ var repoSigner = s3url.createSigner(conf.s3.reposBucket);
+ var slugSigner = s3url.createSigner(conf.s3.slugsBucket);
realResponse.slug_put_url = slugSigner(dbResponse.app_id + uuid.v4() + '.tgz');
realResponse.repo_put_url = repoSigner(dbResponse.app_id + '.tgz');
View
7 apiserver/api/logs.js
@@ -1,4 +1,7 @@
var request = require('request');
+var conf = require('../conf');
+var logplexBaseUrl = 'http://' + conf.logplex.hostname + ':' + conf.logplex.udpPort + '/';
+
module.exports = {
loggingSession: {
payloadSource : 'query',
@@ -13,7 +16,7 @@ module.exports = {
tokens: map
};
- var logplexUrl = process.env['LOGPLEX_BASE_URL'] + 'sessions';
+ var logplexUrl = logplexBaseUrl + 'sessions';
var appName = this.requestPayload.appName;
console.log("Setting up log session for app " + appName);
@@ -27,7 +30,7 @@ module.exports = {
cb({ error: 'unable to connect to log server', friendly: true})
return;
}
- var url = process.env['LOGPLEX_BASE_URL'] + 'sessions/' + result.body.id;
+ var url = logplexBaseUrl + 'sessions/' + result.body.id;
self.responsePayload = url;
cb();
});
View
10 apiserver/apidb.js
@@ -1,12 +1,6 @@
var pg = require('pg');
+var conf = require('./conf');
-var pgConfig = {
- 'database' : process.env['PGDATABASE'] || 'openruko',
- 'host' : process.env['PGHOST'] || 'localhost',
- 'user' : process.env['PGUSER'] || 'openruko',
- 'password' : process.env['PGPASSWORD']
-};
-
-var pgClient = new pg.Client(pgConfig);
+var pgClient = new pg.Client(conf.pg);
pgClient.connect();
module.exports = pgClient;
View
9 apiserver/bin/apiserver
@@ -2,15 +2,16 @@
var server = require('../apiserver');
var manifest = require('../../package.json');
+var conf = require('../conf')
var fs = require('fs');
var path = require('path');
-var port = process.env.PORT || 10000;
-var serverOptions = {
+var port = conf.apiserver.port;
+var serverOptions = {
port: port,
- s3key: process.env['S3_KEY'],
- s3secret: process.env['S3_SECRET']
+ s3key: conf.s3.key,
+ s3secret: conf.s3.secret
};
console.log("Starting openruko v" + manifest.version + " on port " + port);
View
34 apiserver/conf.js
@@ -0,0 +1,34 @@
+var env = process.env;
+
+['S3_KEY', 'S3_SECRET', 'S3_BUCKET'].forEach(function(envKey) {
+ if(env[envKey] === undefined) {
+ throw new Error('Environment variables ' + envKey + ' must be defined.');
+ }
+});
+
+module.exports = {
+ s3: {
+ key: env.S3_KEY,
+ secret: env.S3_SECRET,
+ bucket: env.S3_BUCKET,
+ // Is it used ?
+ //reposBucket: env.S3_REPOS_BUCKET || 'openruko_repos',
+ //slugsBucket: env.S3_SLUGS_BUCKET || 'openruko_slugs'
+ },
+ apiserver: {
+ protocol: env.APISERVER_PROTOCOL || 'http',
+ hostname: env.APISERVER_HOST || 'localhost',
+ port: env.APISERVER_PORT || 5000
+ },
+ pg: {
+ database: env.PG_DATABASE || 'openruko',
+ hostname: env.PG_HOST || 'localhost',
+ user: env.PG_USER || 'openruko',
+ password: env.PG_PASSWORD || 'openruko',
+ schema: env.PG_SCHEMA || 'openruko_api'
+ },
+ logplex: {
+ hostname: env.LOGPLEX_HOST || 'localhost',
+ udpPort: env.LOGPLEX_UDP_PORT || 9996
+ },
+}
View
9 apiserver/jobgiver.js
@@ -5,6 +5,7 @@ var async = require('async');
var hstore = require('node-postgres-hstore');
var slugSigner = require('./s3url');
var _ = require('underscore');
+var conf = require('./conf');
tasks = {};
@@ -69,15 +70,15 @@ module.exports = function(app, options) {
};
-var signer = slugSigner.createSigner(process.env.S3_BUCKET);
+var signer = slugSigner.createSigner(conf.s3.bucket);
var s3regex = new RegExp("^s3([a-z]*)://([a-zA-Z0-9-]*)(/([a-zA-Z0-9.-_]*))+$",'i');
var processMount = function(mountUrl) {
- mountUrl = mountUrl.replace('{{S3_BUCKET}}', process.env.S3_BUCKET);
- mountUrl = mountUrl.replace('{{BASE_PROTOCOL}}', process.env.BASE_PROTOCOL);
- mountUrl = mountUrl.replace('{{BASE_HOST}}', process.env.BASE_HOST);
+ mountUrl = mountUrl.replace('{{S3_BUCKET}}', conf.s3.bucket);
+ mountUrl = mountUrl.replace('{{BASE_PROTOCOL}}', conf.apiserver.protocol);
+ mountUrl = mountUrl.replace('{{BASE_HOST}}', conf.apiserver.hostname + ':' + conf.apiserver.port);
var s3match = mountUrl.match(s3regex);
View
3  apiserver/s3url.js
@@ -1,9 +1,10 @@
var as3 = require('amazon-s3-url-signer');
+var conf = require('./conf');
module.exports = {
createSigner: function(bucket) {
- var slugClient = as3.urlSigner(process.env.S3_KEY, process.env.S3_SECRET );
+ var slugClient = as3.urlSigner(conf.s3.key, conf.s3.secret);
return function(method, filename) {
return slugClient.getUrl(method.toUpperCase(),
View
26 debug.launch
@@ -1,26 +0,0 @@
-#!/bin/bash
-
-set -e
-
-# put overriding env vars in local.env - do not save in git
-if [ -f local.env ]; then
- source local.env
-fi
-# example boot script
-
-export S3_KEY=${S3_KEY-:AAAAAAAAAA}
-export S3_SECRET=${S3_SECRET-:BBBBBBBBBB}
-
-export PGHOST=${PGHOST:-localhost}
-export PGDATABASE=${PGDATABASE:-openruko}
-export PGUSER=${PGUSER:-openruko}
-export PGPASSWORD=${PGPASSWORD:-openruko}
-export OPENRUKO_PGSCHEMA=openruko_api
-
-export PORT=${PORT:-5000}
-export BASE_HOST=${BASE_HOST:-localhost:5000}
-export BASE_PROTOCOL=${BASE_PROTOCOL:-http}
-export S3_BUCKET=${S3_BUCKET:-openrukorepos}
-export LOGPLEX_BASE_URL=${LOGPLEX_BASE_URL:-http://localhost:9996/}
-
-exec apiserver/bin/apiserver
View
4 package.json
@@ -23,7 +23,9 @@
"js-yaml": "~1.0.2",
"node-uuid": "~1.3.3"
},
- "scripts": { },
+ "scripts": {
+ "start": "./apiserver/bin/apiserver"
+ },
"license": "MIT",
"devDependencies": {},
"optionalDependencies": {},
Please sign in to comment.
Something went wrong with that request. Please try again.