...
 
Commits (2)
......@@ -18,8 +18,8 @@ class Install extends Cli\Controller implements Interfaces\CliControllerInterfac
{
$this->out('Configures web server and provisions and sets up databases for the minds application.');
$this->out('use-existing-settings: uses the existing settings in settings.php.');
$this->out('only=[keys|site|cassandra|cockroach] to set up individual components.');
$this->out('cleanCassandra cleanCockroach: deletes and recreates db.');
$this->out('only=[keys|site|cassandra|] to set up individual components.');
$this->out('cleanCassandra: deletes and recreates db.');
$this->out('graceful-storage-provision: causes installation to proceed past storage (db) failures.');
}
......@@ -52,7 +52,7 @@ class Install extends Cli\Controller implements Interfaces\CliControllerInterfac
$provisioner->checkOptions();
$this->out('OK');
// only=[keys|cassandra|cockroach|site]
// only=[keys|cassandra|site]
$installOnly = $this->getopt('only');
$installType = $installOnly ? $installOnly : "all";
......@@ -75,17 +75,6 @@ class Install extends Cli\Controller implements Interfaces\CliControllerInterfac
$this->out('Something BAD happened while provisioning Cassandra' . $ex->getMessage());
}
try {
if ($installType == "all" || $installType == "cockroach") {
$this->out('- Provisioning Cockroach:');
$isCleanCockroach = $this->getopt("cleanCockroach") != null;
$provisioner->provisionCockroach(null, $isCleanCockroach);
$this->out('OK');
}
} catch (Exception $ex) {
$this->out('Something BAD happened while provisioning Cockroach' . $ex->getMessage());
}
if (($installType == "all") || ($installType == "site")) {
$this->out('- Setting up site:', $this::OUTPUT_INLINE);
$provisioner->setupSite();
......
......@@ -228,11 +228,9 @@ class Installer
}
public function setupStorage(Provisioners\ProvisionerInterface $cassandraStorage = null,
Provisioners\ProvisionerInterface $cockroachProvisioner = null,
$cleanData = false)
{
$this->provisionCassandra($cassandraStorage, $cleanData);
$this->provisionCockroach($cockroachProvisioner, $cleanData);
}
public function provisionCassandra(Provisioners\ProvisionerInterface $cassandraStorage = null,
......@@ -242,13 +240,6 @@ class Installer
$cassandraStorage->provision($cleanData);
}
public function provisionCockroach(Provisioners\ProvisionerInterface $cockroachProvisioner = null,
$cleanData = false)
{
$cockroachProvisioner = $cockroachProvisioner ?: new Provisioners\CockroachProvisioner();
$cockroachProvisioner->provision($cleanData);
}
public function reloadStorage()
{
Core\Data\Pool::$pools = [];
......
<?php
namespace Minds\Core\Provisioner\Provisioners;
use Minds\Core\Di\Di;
use PDO;
class CockroachProvisioner implements ProvisionerInterface
{
protected $config;
public function provision(bool $cleanData)
{
$config = Di::_()->get('Config')->get('database');
$host = isset($config['host']) ? $config['host'] : 'cockroachdb';
$port = isset($config['port']) ? $config['port'] : 26257;
$dbName = isset($config['name']) ? $config['name'] : 'minds';
$sslMode = isset($config['sslmode']) ? $config['sslmode'] : 'disable';
$username = isset($config['username']) ? $config['username'] : 'php';
// Using root account because only superusers have permission to create databases.
$adminDb = new PDO("pgsql:host=$host;port=$port;dbname=$dbName;sslmode=$sslMode",
'root',
null,
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => true,
PDO::ATTR_PERSISTENT => true,
]);
$adminDb->prepare("CREATE USER IF NOT EXISTS $username")->execute();
if ($cleanData)
{
$adminDb->prepare("DROP DATABASE IF EXISTS $dbName")->execute();
}
$adminDb->prepare("CREATE DATABASE IF NOT EXISTS $dbName")->execute();
$adminDb->prepare("GRANT ALL ON DATABASE $dbName TO $username")->execute();
$schema = explode(';', file_get_contents(dirname(__FILE__) . '/cockroach-provision.sql'));
foreach ($schema as $query) {
if (trim($query) === '') {
continue;
}
try {
$statement = $adminDb->prepare($query);
$statement->execute();
} catch (\Exception $ex) {
error_log("Error running cockroach statement: " . $ex->getMessage());
}
}
}
}
CREATE TABLE minds.comments (
uuid UUID NOT NULL DEFAULT gen_random_uuid(),
legacy_guid INT NULL,
parent_uuid UUID NULL,
owner_guid INT NULL,
entity_guid INT NULL,
created_timestamp TIMESTAMP NULL DEFAULT now():::TIMESTAMP,
notification_type STRING(20) NULL,
data JSONB NULL,
CONSTRAINT "primary" PRIMARY KEY (uuid ASC),
INDEX legacy_guid_idx (legacy_guid ASC),
FAMILY "primary" (uuid, legacy_guid, parent_uuid, owner_guid, entity_guid, created_timestamp, notification_type, data)
);
CREATE TABLE minds.entities (
uuid UUID NOT NULL DEFAULT gen_random_uuid(),
legacy_guid INT NULL,
owner_guid INT NULL,
entity_guid INT NULL,
created_timestamp TIMESTAMP NULL DEFAULT now():::TIMESTAMP,
CONSTRAINT "primary" PRIMARY KEY (uuid ASC),
INDEX legacy_guid_idx (legacy_guid ASC),
FAMILY "primary" (uuid, legacy_guid, owner_guid, entity_guid, created_timestamp)
);
CREATE TABLE minds.entity_hashtags (
guid INT NOT NULL,
hashtag STRING NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (guid ASC, hashtag ASC),
INDEX entity_hashtags_hashtag_idx (hashtag ASC),
INDEX entity_hashtags_hashtag_guid_idx (hashtag ASC, guid ASC),
FAMILY "primary" (guid, hashtag)
);
CREATE TABLE minds.helpdesk_categories (
uuid UUID NOT NULL DEFAULT gen_random_uuid(),
title STRING(100) NOT NULL,
parent UUID NULL,
branch STRING NULL,
CONSTRAINT "primary" PRIMARY KEY (uuid ASC),
FAMILY "primary" (uuid, title, parent, branch)
);
CREATE TABLE minds.helpdesk_faq (
uuid UUID NOT NULL DEFAULT gen_random_uuid(),
question STRING NULL,
answer STRING NULL,
category_uuid UUID NULL,
CONSTRAINT "primary" PRIMARY KEY (uuid ASC),
CONSTRAINT fk_category_uuid_ref_helpdesk_categories FOREIGN KEY (category_uuid) REFERENCES helpdesk_categories (uuid),
INDEX helpdesk_faq_auto_index_fk_category_uuid_ref_helpdesk_categories (category_uuid ASC),
FAMILY "primary" (uuid, question, answer, category_uuid)
);
CREATE TABLE minds.helpdesk_votes (
question_uuid UUID NOT NULL,
user_guid STRING(18) NOT NULL,
direction STRING NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (question_uuid ASC, user_guid ASC, direction ASC),
FAMILY "primary" (question_uuid, user_guid, direction)
);
CREATE TABLE minds.hidden_hashtags (
hashtag STRING NOT NULL,
hidden_since TIMESTAMP NOT NULL DEFAULT now(),
admin_guid INT NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (hashtag ASC),
FAMILY "primary" (hashtag, hidden_since, admin_guid)
);
CREATE TABLE minds.notification_batches (
user_guid INT NOT NULL,
batch_id STRING NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (user_guid ASC, batch_id ASC),
INDEX notification_batches_batch_id_idx (batch_id ASC),
FAMILY "primary" (user_guid, batch_id)
);
CREATE TABLE minds.notifications (
uuid UUID NOT NULL DEFAULT gen_random_uuid(),
to_guid INT NOT NULL,
from_guid INT NULL,
created_timestamp TIMESTAMP NULL DEFAULT now():::TIMESTAMP,
read_timestamp TIMESTAMP NULL,
notification_type STRING NOT NULL,
data JSONB NULL,
entity_guid STRING NULL,
batch_id STRING NULL,
CONSTRAINT "primary" PRIMARY KEY (to_guid ASC, notification_type ASC, uuid DESC),
INDEX notifications_redux_created_timestamp_idx (created_timestamp DESC),
INDEX notifications_redux_batch_id_idx (batch_id ASC) STORING (from_guid, entity_guid, created_timestamp, read_timestamp, data),
FAMILY "primary" (uuid, to_guid, from_guid, created_timestamp, read_timestamp, notification_type, data, entity_guid, batch_id)
);
CREATE TABLE minds.suggested (
type STRING NOT NULL,
guid INT NOT NULL,
rating INT NULL,
score INT NULL,
lastsynced TIMESTAMP NULL,
CONSTRAINT "primary" PRIMARY KEY (type ASC, guid ASC),
INDEX suggested_lastsynced_score_rating_idx (lastsynced DESC, score DESC, rating DESC),
INDEX suggested_lastsynced_score_idx (lastsynced DESC, score DESC),
INDEX suggested_redux_rating_idx (rating DESC) STORING (lastsynced, score),
FAMILY "primary" (type, guid, rating, score, lastsynced)
);
CREATE TABLE minds.suggested_tags (
guid INT NOT NULL,
rating INT NULL,
type STRING NULL,
score INT NULL,
lastsynced TIMESTAMP NULL,
hashtags STRING[] NULL,
CONSTRAINT "primary" PRIMARY KEY (guid ASC),
FAMILY "primary" (guid, rating, type, score, lastsynced, hashtags)
);
......@@ -16,15 +16,8 @@ aws s3 cp $S3_BUCKET/var/secure/oauth-pub.key /var/secure/oauth-pub.key
aws s3 cp $S3_BUCKET/var/secure/sessions-priv.key /var/secure/sessions-priv.key
aws s3 cp $S3_BUCKET/var/secure/sessions-pub.key /var/secure/sessions-pub.key
# Cockroach
aws s3 cp $S3_BUCKET/var/secure/cockroachdb /var/secure/cockroachdb --recursive
chown -R www-data /var/secure/cockroachdb/
aws s3 cp $S3_BUCKET/var/secure/google.sheets.key.json /var/secure/google.sheets.key.json
chmod -xr /var/secure/
# Cockroachdb permissions
chmod -R 600 /var/secure/cockroachdb/
echo "PULLED SECRETS";
......@@ -17,13 +17,6 @@ aws s3 cp $S3_BUCKET/var/secure/oauth-pub.key /var/secure/oauth-pub.key
aws s3 cp $S3_BUCKET/var/secure/sessions-priv.key /var/secure/sessions-priv.key
aws s3 cp $S3_BUCKET/var/secure/sessions-pub.key /var/secure/sessions-pub.key
# Cockroach
aws s3 cp $S3_BUCKET/var/secure/cockroachdb /var/secure/cockroachdb --recursive
chown -R www-data /var/secure/cockroachdb/
chmod -xr /var/secure/
# Cockroachdb permissions
chmod -R 600 /var/secure/cockroachdb/
echo "PULLED SECRETS";
......@@ -14,12 +14,6 @@ $CONFIG->cassandra = (object) [
'password' => 'cassandra',
];
$CONFIG->database = [
'host' => 'cockroachdb',
'user' => 'php',
'sslmode' => 'disable',
];
$CONFIG->redis = [
'master' => 'redis',
'slave' => 'redis'
......@@ -474,7 +468,87 @@ $CONFIG->set('features', [
'es-feeds' => false,
'helpdesk' => true,
'top-feeds' => true,
'cassandra-notifications' => true,
'dark-mode' => true,
]);
$CONFIG->set('last_tos_update', 1);
\ No newline at end of file
$CONFIG->set('email', [
'smtp' => [
'host' => '',
'username' => '',
'password' => '',
'port' => 465
]
]);
$CONFIG->set('max_video_length', 900);
$CONFIG->set('max_video_length_plus', 1860);
$CONFIG->set('aws', [
'key' => '',
'secret' => '',
'useRoles' => false,
'bucket' => 'cinemr',
'staticStorage' => 'cinemr_dev',
'region' => 'us-east-1',
'account_id' => '324044571751',
'elastic_transcoder' => [
'pipeline_id' => '1401290942976-efm3xj',
'presets' => [
"360.mp4" => "1351620000001-000040",
"720.mp4" => "1351620000001-000010",
"360.webm" => "1404848610623-0blc5v",
"720.webm" => "1404852762051-zzvwfq"
],
'dir' => 'cinemr_dev'
],
'queue' => [
'namespace' => 'EmiDev',
'wait_seconds' => 3,
]
]);
$CONFIG->set('transcode', [
//'free_threshold' => 900, // 15 minutes
'free_threshold' => 2,
'hd_price' => 1, // tokens
'fhd_price' => 1.5, // tokens
]);
$CONFIG->set('transcoder', [
'threads' => 4,
'dir' => 'cinemr_dev',
'presets' => [
[
'width' => 640,
'height' => 360,
'bitrate' => 500,
'audio_bitrate' => 80,
'formats' => [ 'mp4', 'webm' ],
'charge' => false,
],
[
'width' => 1280,
'height' => 720,
'bitrate' => 2000,
'audio_bitrate' => 128,
'formats' => [ 'mp4', 'webm' ],
'charge' => false,
],
[
'width' => 1920,
'height' => 1080,
'bitrate' => 2000,
'audio_bitrate' => 128,
'formats' => [ 'mp4', 'webm' ],
'charge' => true,
],
]
]);
$CONFIG->cinemr_url = 'https://cinemr.s3.amazonaws.com/cinemr_dev/';
$CONFIG->mongodb_servers = ['minds_mongo_1'];
$CONFIG->set('last_tos_update', 1);