Skip to content

Commit

Permalink
feat(1590): allow configure RO_DB
Browse files Browse the repository at this point in the history
  • Loading branch information
d2lam committed Apr 17, 2019
1 parent 8cfc8c6 commit b15fdc6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
42 changes: 35 additions & 7 deletions bin/server
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ const multiBuildClusterEnabled = config.get('multiBuildCluster').enabled;
// Setup Datastore
const datastoreConfig = config.get('datastore');
const DatastorePlugin = require(`screwdriver-datastore-${datastoreConfig.plugin}`);

const datastorePluginConfig = datastoreConfig[datastoreConfig.plugin];

// Readonly Datastore
const datastoreROConfig = datastorePluginConfig.readOnly;
let datastoreRO;

if (datastoreROConfig && Object.keys(datastoreROConfig).length > 0) {
datastoreRO = new DatastorePlugin(hoek.applyToDefaults({ ecosystem }, datastoreROConfig));
}
delete datastorePluginConfig.readOnly;

// Default datastore
const datastore = new DatastorePlugin(hoek.applyToDefaults({ ecosystem },
(datastoreConfig[datastoreConfig.plugin] || {})));

Expand Down Expand Up @@ -86,28 +99,35 @@ const executor = new ExecutorPlugin(Object.assign(

// Setup Model Factories
const commandFactory = Models.CommandFactory.getInstance({
datastore
datastore,
datastoreRO
});
const commandTagFactory = Models.CommandTagFactory.getInstance({
datastore
datastore,
datastoreRO
});
const templateFactory = Models.TemplateFactory.getInstance({
datastore
datastore,
datastoreRO
});
const templateTagFactory = Models.TemplateTagFactory.getInstance({
datastore
datastore,
datastoreRO
});
const jobFactory = Models.JobFactory.getInstance({
datastore,
datastoreRO,
executor
});
const userFactory = Models.UserFactory.getInstance({
datastore,
datastoreRO,
scm,
password: authConfig.encryptionPassword
});
const buildFactory = Models.BuildFactory.getInstance({
datastore,
datastoreRO,
dockerRegistry: ecosystem.dockerRegistry,
scm,
executor,
Expand All @@ -116,32 +136,40 @@ const buildFactory = Models.BuildFactory.getInstance({
multiBuildClusterEnabled
});
const stepFactory = Models.StepFactory.getInstance({
datastore
datastore,
datastoreRO
});
const secretFactory = Models.SecretFactory.getInstance({
datastore,
datastoreRO,
password: authConfig.encryptionPassword
});
const tokenFactory = Models.TokenFactory.getInstance({
datastore,
datastoreRO,
password: authConfig.hashingPassword
});
const eventFactory = Models.EventFactory.getInstance({
datastore,
datastoreRO,
scm
});
const bannerFactory = Models.BannerFactory.getInstance({
datastore,
datastoreRO,
scm
});
const collectionFactory = Models.CollectionFactory.getInstance({
datastore
datastore,
datastoreRO
});
const triggerFactory = Models.TriggerFactory.getInstance({
datastore
datastore,
datastoreRO
});
const buildClusterFactory = Models.BuildClusterFactory.getInstance({
datastore,
datastoreRO,
scm
});

Expand Down
11 changes: 11 additions & 0 deletions config/custom-environment-variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ datastore:
__name: DATASTORE_SEQUELIZE_RETRY
__format: json
buildMetricsEnabled: DATASTORE_SEQUELIZE_CAPTURE_METRICS_ENABLED
readOnly:
__name: DATASTORE_SEQUELIZE_RO
__format: json
# dialect: sequelize
# database:
# username:
# password:
# host:
# port:
# More arguments here:
# http://docs.sequelizejs.com/en/latest/api/sequelize/

executor:
plugin: EXECUTOR_PLUGIN
Expand Down
2 changes: 2 additions & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ datastore:
pool: {}
retry: {}
buildMetricsEnabled: "false"
# readOnly datastore config
# readOnly: {}

executor:
# Default executor
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@
"screwdriver-command-validator": "^1.0.5",
"screwdriver-config-parser": "^4.11.1",
"screwdriver-coverage-bookend": "^1.0.2",
"screwdriver-coverage-sonar": "^1.0.16",
"screwdriver-coverage-sonar": "^1.0.17",
"screwdriver-data-schema": "^18.45.2",
"screwdriver-datastore-sequelize": "^5.7.1",
"screwdriver-executor-docker": "^4.2.0",
"screwdriver-executor-k8s": "^13.6.1",
"screwdriver-executor-k8s-vm": "^2.10.0",
"screwdriver-executor-queue": "^2.4.10",
"screwdriver-executor-queue": "^2.4.11",
"screwdriver-executor-router": "^1.0.11",
"screwdriver-models": "^27.31.9",
"screwdriver-models": "^27.31.17",
"screwdriver-notifications-email": "^1.1.9",
"screwdriver-notifications-slack": "^2.2.0",
"screwdriver-scm-github": "^9.1.2",
Expand Down Expand Up @@ -132,7 +132,7 @@
"node-plantuml": "^0.5.0",
"npm-auto-version": "^1.0.0",
"rewire": "^4.0.1",
"sinon": "^7.3.1",
"sinon": "^7.3.2",
"stream-to-promise": "^2.2.0"
}
}

0 comments on commit b15fdc6

Please sign in to comment.