Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit 5ee1597

Browse files
committed
support for mongodb host config
1 parent 138739c commit 5ee1597

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1155
-460
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.DS_Store
2+
.sandbox-config.sh
3+
log/

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 100,
3+
"singleQuote": true,
4+
"trailingComma": "es5",
5+
"useTabs": true
6+
}

README.md

+92-63
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,100 @@
11
# CodeStream Backend Services
22

3-
On the backend, CodeStream requires several services to provide all the
4-
functionality needed for the clients. Different configurations are supported
5-
most natably the use of the broadcaster and rabbitMQ for On-Prem vs. PubNub and
6-
AWS SQS for CodeStream Cloud. This repo contains all the code for these
7-
services.
3+
On the backend (aka. the server-side), CodeStream runs a number of services to
4+
provide all the functionality needed for the clients. The default development
5+
environment will use the codestream broadcaster and rabbitMQ. Mail services
6+
are disabled by default.
7+
## Development Setup
88

9-
## Installation & Setup Using dev_tools
10-
11-
Installation for development on the CodeStream network.
9+
_Note: CodeStream employees may prefer to use the dev_tools sandbox as it will
10+
provide most of the ancillary resources you'll need. [Details
11+
here](docs/codestream-sandbox-setup.md)._
1212

1313
### Prerequisites
14-
1. Install the dev_tools tookkit
15-
[here](https://github.com/teamcodestream/dev_tools).
16-
1. Install mongo - this is available as a dev_tools sandbox or you can install
17-
any version. Instructions for the mongo sandbox are
18-
[here](https://github.com/teamcodestream/mongodb_tools).
19-
1. Make sure you can access the CodeStream network via the VPN.
20-
1. Review how we manage our [server configurations](api_server/README.unified-cfg-file.md).
21-
If you have any custom alterations to the standard configuration, you will
22-
need to be familiar with the procedures in this document.
14+
15+
1. Mac or Linux computer using zsh or bash.
16+
17+
1. Official CodeStream builds (CI) use Nodejs 12.14.1 with npm 6.13.4
18+
19+
1. [Docker Desktop](https://www.docker.com/products/docker-desktop) which we'll
20+
use to provide MongoDB and a pre-configured RabbitMQ.
21+
22+
If you do not wish to use docker, you'll need to provide both of these services:
23+
24+
1. MongoDB 3.4.9 with `mongodb://localhost/codestream` providing full access to
25+
create collections and indexes in the `codestream` database. If you're
26+
willing to run docker, the instructions below will show you how to install a
27+
MongoDB docker container.
28+
29+
1. RabbitMQ 3.7.x with the delayed message exchange plugin. You'll also need to
30+
create a codestream user with access. [Notes here](api_server/docs/rabbitmq.md).
2331

2432
### Installation
25-
1. If you're using dev_tools on your own computer, bring it up to date
26-
(`dt-selfupdate -y`). You don't need to do this if you're using a managed EC2
27-
instance.
28-
1. Update your secrets (`dt-update-secrets -y`).
29-
1. Select a codestream configuration to use (details documented
30-
[here](README.unified-cfg-file.md)). To get up and running quickly, this
31-
command will select out-of-the-box 'codestream-cloud' as your configuration.
32-
```
33-
$ echo codestream-cloud > ~/.codestream/config/codestream-cfg-default.local
34-
```
35-
1. Open a new terminal window
36-
1. Load your dev_tools mongo sandbox into your shell if you're using one and
37-
start the mongo service.
38-
```
39-
$ dt-load mongo
40-
$ mdb-service start
41-
```
42-
If using your own mongo installation, make sure it's running and accessible
43-
without credentials on **localhost** (the default mongo connect url assumes
44-
`mongodb://localhost/codestream`).
45-
1. Install the codestream-server repo (only specify `-I` if you are *not* using
46-
or have not loaded a dev_tools mongo sandbox). Select a name for your backend
47-
sandbox (we'll use `csbe`):
48-
```
49-
dt-sb-new-sandbox -yCD -t cs_server -n csbe
50-
```
51-
1. Load your codestream backend sandbox:
52-
```
53-
$ dt-load csbe
54-
```
55-
1. Create a playground for setting up future terminals with your mongo + csbe
56-
sandboxes. This will create a playground with a default name of `csbe` (not
57-
to be confused with the **csbe** sandbox).
58-
```
59-
$ dt-sb-create-playground -t $CSBE_TOP/sandbox/playgrounds/default.template
60-
```
61-
62-
You are ready to go. From this point forward use the following command to setup
63-
new shells for codestream backend development:
64-
```
65-
$ dt-load-playground csbe
66-
```
67-
68-
## Installation & Setup without dev_tools
69-
70-
To be written
7133

34+
1. Fork the
35+
[codestream-server](https://github.com/teamcodestream/codestream-server) repo
36+
and clone it.
37+
38+
1. Setup your shell's environment
39+
```
40+
cd codestream-server
41+
source dev-env.sh # custom settings go in .sandbox-config.sh
42+
```
43+
44+
1. Install all the node modules
45+
```
46+
npm run install:all
47+
```
48+
49+
1. Install the rabbitmq docker container pre-configured for codestream (the
50+
container name will be csrabbitmq)
51+
```
52+
npm run run:docker:csrabbitmq
53+
```
54+
55+
1. Create a docker volume for mongo and launch the mongodb docker container.
56+
The docker volume will ensure the data persists beyond the lifespan of the
57+
container.
58+
```
59+
npm run run:docker:csmongo
60+
```
61+
62+
1. In a separate shell, source in the `dev-env.sh` environment and start up the
63+
api service. It will repeatedly try to connect to the broadcaster. That's ok.
64+
Move on once you've started it.
65+
```
66+
source dev-env.sh
67+
npm run start:api
68+
```
69+
70+
1. In a another separate shell, source in the `dev-env.sh` environment and start
71+
up the broadcaster service.
72+
```
73+
source dev-env.sh
74+
npm run start:broadcaster
75+
```
76+
77+
1. If you want to use or work on the onprem admin UI, that will need two more
78+
shells. This first one will run webpack and rebuild the bundle file as your
79+
files change.
80+
```
81+
source dev-env.sh
82+
npm run start:opadm
83+
```
84+
85+
1. The inbound email service is disabled in the default config.
86+
```
87+
source dev-env.sh
88+
npm run start:mailin
89+
```
90+
91+
1. The outbound email service is also disabled in the default config.
92+
```
93+
source dev-env.sh
94+
npm run start:mailout
95+
```
96+
97+
Point your CodeStream extension to http://localhost:12000. You should be able to
98+
register and create codemarks. The onprem admin console is at http://localhost:12002
99+
100+
Develop to your heart's content!!!! We _love_ pull-requests.

api_server/bin/api_server.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
'use strict';
88

9+
const UUID = require('uuid').v4;
10+
911
// load configurations
1012
const ApiConfig = require(process.env.CSSVC_BACKEND_ROOT + '/api_server/config/config');
1113
const ModuleDirectory = process.env.CSSVC_BACKEND_ROOT + '/api_server/modules';
@@ -14,6 +16,7 @@ const ClusterWrapper = require(process.env.CSSVC_BACKEND_ROOT + '/shared/server_
1416
const StringifySortReplacer = require(process.env.CSSVC_BACKEND_ROOT + '/shared/server_utils/stringify_sort_replacer');
1517
const ServerClass = require(process.env.CSSVC_BACKEND_ROOT + '/api_server/lib/api_server/api_server');
1618
const getOnPremSupportData = require(process.env.CSSVC_BACKEND_ROOT + '/shared/server_utils/get_onprem_support_data');
19+
const customSchemaMigrationMatrix = require(process.env.CSSVC_BACKEND_ROOT + '/shared/server_utils/custom_schema_migration');
1720

1821
// establish our data collections
1922
const DataCollections = {
@@ -49,15 +52,30 @@ const MongoCollections = Object.keys(DataCollections).concat([
4952
]);
5053

5154
(async function() {
55+
if (ApiConfig.configIsMongo()) {
56+
// set option so structured config will perform a schema version migration if needed upon initial load
57+
ApiConfig.performMigrationUsing(customSchemaMigrationMatrix);
58+
// set option to create a new config using the supplied default in the event no configs exist (empty database)
59+
ApiConfig.loadDefaultConfigIfNoneFrom(
60+
process.env.CS_API_DEFAULT_CFG_FILE ||
61+
process.env.CSSVC_BACKEND_ROOT + '/api_server/etc/configs/default.json',
62+
// generate installation id for first time start-up
63+
(cfg) => {
64+
if (!cfg.sharedGeneral.installationId) cfg.sharedGeneral.installationId = UUID();
65+
}
66+
);
67+
}
68+
5269
// changes to Config will be available globally via the /config/writeable.js module
53-
const Config = await ApiConfig.loadPreferredConfig();
70+
const Config = await ApiConfig.loadPreferredConfig({ wait: true });
5471

5572
// establish our logger
5673
const Logger = new SimpleFileLogger(Config.apiServer.logger);
74+
ApiConfig.logger = Logger;
5775

5876
// onprem support data (service versions, docker registry info, on-prem version)
5977
let onPremSupportData;
60-
if (!Config.adminServer.adminServerDisabled) {
78+
if (Config.isOnPrem) {
6179
onPremSupportData = await getOnPremSupportData(Logger);
6280
console.info('OnPrem Config:', JSON.stringify(onPremSupportData, StringifySortReplacer, 8));
6381
}

api_server/bin/ensure-indexes.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ function WaitUntilFinished() {
9898
(async function() {
9999
let mongoClient, db;
100100
try {
101-
const config = await ApiConfig.loadPreferredConfig();
102-
mongoClient = await MongoClient.connect(config.storage.mongo.url, { useNewUrlParser: true });
101+
const mongoUrl = ApiConfig.configIsMongo()
102+
? ApiConfig.options.mongoUrl
103+
: await ApiConfig.loadPreferredConfig().storage.mongo.url;
104+
mongoClient = await MongoClient.connect(mongoUrl, { useNewUrlParser: true });
103105
db = mongoClient.db();
104106
}
105107
catch (error) {

api_server/config/config.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ const customConfigFunc = require(process.env.CSSVC_BACKEND_ROOT + '/shared/serve
1818
// function customRestartFunc(priorConfig, currentConfig) {
1919
// }
2020

21-
module.exports = StructuredConfigFactory.create({
21+
var Config;
22+
23+
Config = Config || StructuredConfigFactory.create({
2224
configFile: process.env.CS_API_CFG_FILE || process.env.CSSVC_CFG_FILE,
2325
mongoUrl: process.env.CSSVC_CFG_URL,
2426
showConfigProperty: 'apiServer.showConfig',
2527
// customRestartFunc,
2628
customConfigFunc
2729
});
30+
31+
module.exports = Config;

0 commit comments

Comments
 (0)