diff --git a/.awsbox.json b/.awsbox.json index 058780c..8cb674d 100644 --- a/.awsbox.json +++ b/.awsbox.json @@ -3,6 +3,9 @@ "index.js" ], "env": { - "CONFIG_FILES": "$HOME/code/config/aws.json,$HOME/kvstore.json,$HOME/config.json" + "CONFIG_FILES": "$HOME/code/config/aws.json,$HOME/config.json" + }, + "remote_hooks": { + "postcreate": "scripts/aws/post_create.sh" } } diff --git a/config/aws.json b/config/aws.json index ed58a0d..fccd0a8 100644 --- a/config/aws.json +++ b/config/aws.json @@ -1,5 +1,8 @@ { "kvstore": { - "backend": "couchbase" + "backend": "mysql" + }, + "mysql": { + "database": "picl" } } diff --git a/lib/config.js b/lib/config.js index 80e1e9e..a7952d6 100644 --- a/lib/config.js +++ b/lib/config.js @@ -4,7 +4,7 @@ var convict = require('convict'); -const AVAILABLE_BACKENDS = ["memory", "couchbase"]; +const AVAILABLE_BACKENDS = ["memory", "mysql"]; var conf = module.exports = convict({ @@ -23,6 +23,12 @@ var conf = module.exports = convict({ doc: "The audience we expect incoming assertions to use", default: "https://firefox.com" }, + persona_url: { + doc: "Persona service", + format: "url", + default: "https://picl.personatest.org", + env: 'PERSONA_URL' + }, public_url: { format: "url", // the real url is set by awsbox @@ -45,20 +51,42 @@ var conf = module.exports = convict({ default: AVAILABLE_BACKENDS } }, - couchbase: { + mysql: { user: { - default: 'Administrator', - env: 'KVSTORE_USERNAME' + default: 'root', + env: 'MYSQL_USERNAME' }, password: { - default: 'password', - env: 'KVSTORE_PASSWORD' + default: '', + env: 'MYSQL_PASSWORD' }, - bucket: { + database: { default: 'picl', - env: 'KVSTORE_BUCKET' + env: 'MYSQL_DATABASE' }, - hosts: [ "localhost:8091" ] + host: { + default: '127.0.0.1', + env: 'MYSQL_HOST' + }, + port: { + default: '3306', + env: 'MYSQL_PORT' + }, + create_schema: { + default: true, + env: 'CREATE_MYSQL_SCHEMA' + }, + max_query_time_ms: { + doc: "The maximum amount of time we'll allow a query to run before considering the database to be sick", + default: 5000, + format: 'duration', + env: 'MAX_QUERY_TIME_MS' + }, + max_reconnect_attempts: { + doc: "The maximum number of times we'll attempt to reconnect to the database before failing all outstanding queries", + default: 3, + format: 'nat' + } }, bind_to: { host: { @@ -85,8 +113,8 @@ if (process.env.CONFIG_FILES) { } if (conf.get('env') === 'test') { - if (conf.get('kvstore.backend') === 'couchbase') { - conf.set('couchbase.bucket', 'default'); + if (conf.get('kvstore.backend') === 'mysql') { + conf.set('mysql.database', 'test_keyserver'); } } diff --git a/package.json b/package.json index 7e13456..cf41161 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,6 @@ "async": "0.1.22", "node-uuid": "1.4.0" }, - "optionalDependencies": { - "couchbase": "0.0.11" - }, "devDependencies": { "mocha": "1.8.1" } diff --git a/scripts/aws/install_couchbase.js b/scripts/aws/install_couchbase.js deleted file mode 100644 index d0dbee1..0000000 --- a/scripts/aws/install_couchbase.js +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env node - -var fs = require('fs'); -var path = require('path'); -var child_process = require('child_process'); - -function uploadScript (host, cb) { - var args = ['-o', 'StrictHostKeyChecking=no', - path.join(__dirname, 'install_couchbase.sh'), - 'ec2-user@' + host + ':install_couchbase.sh' ]; - - var p = child_process.spawn('scp', args, {'stdio': 'inherit'}); - - p.on('exit', function(code, signal) { - var err = code || signal; - if (err && cb) return cb(err); - ssh('sh install_couchbase.sh'); - }); - - function ssh(cmd) { - var args = ['-o', 'StrictHostKeyChecking=no', - 'ec2-user@' + host, cmd]; - var p = child_process.spawn('ssh', args, {'stdio': 'inherit'}); - p.on('exit', function(code, signal) { - if (cb) cb(code || signal); - }); - } -} - -module.exports = uploadScript; - -if (require.main === module) - uploadScript(process.argv[2]); - diff --git a/scripts/aws/install_couchbase.sh b/scripts/aws/install_couchbase.sh deleted file mode 100644 index e2c0959..0000000 --- a/scripts/aws/install_couchbase.sh +++ /dev/null @@ -1,20 +0,0 @@ - -sudo wget -O/etc/yum.repos.d/couchbase.repo http://packages.couchbase.com/rpm/couchbase-centos62-x86_64.repo - -sudo yum check-update && sudo yum install -y libcouchbase-devel - -wget http://packages.couchbase.com/releases/2.0.0/couchbase-server-enterprise_x86_64_2.0.0.rpm - -sudo yum install -y couchbase-server-enterprise_x86_64_2.0.0.rpm - -sleep 15 - -PASS=`openssl rand -base64 16` -BUCKET=picl - -/opt/couchbase/bin/couchbase-cli cluster-init -c 127.0.0.1:8091 --cluster-init-username=Administrator --cluster-init-password=$PASS --cluster-init-port=8091 --cluster-init-ramsize=1024 - -/opt/couchbase/bin/couchbase-cli bucket-create -c 127.0.0.1:8091 --bucket=$BUCKET --bucket-type=couchbase --bucket-ramsize=1024 --bucket-replica=0 -u Administrator -p $PASS - -echo {\"couchbase\": {\"password\":\"${PASS}\", \"bucket\":\"${BUCKET}\"}} > kvstore.json -sudo mv kvstore.json /home/app/kvstore.json diff --git a/scripts/aws/post_create.sh b/scripts/aws/post_create.sh new file mode 100755 index 0000000..ffa132f --- /dev/null +++ b/scripts/aws/post_create.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +echo "Setting up mysql" + +sudo /sbin/chkconfig mysqld on +sudo /sbin/service mysqld start +echo "CREATE USER 'picl'@'localhost';" | mysql -u root +echo "CREATE DATABASE picl;" | mysql -u root +echo "GRANT ALL ON picl.* TO 'picl'@'localhost';" | mysql -u root