Merge branch 'hotfix/21.56.9' into master
[gitter.git] / README.md
blobfe190b32775e152d41974c83026b82a20bb14efa
1 # Gitter webapp
3 [Gitter](https://gitter.im) is a community for software developers. This project is the main monolith web application.
5 This codebase even covers a lot of the mobile and desktop applications which embed a web frame.
7 If you are just interested in the Gitter API, see https://developer.gitter.im/
9  - Security issue boards
10     - https://gitlab.com/groups/gitterHQ/-/boards/1084052?&label_name[]=security
11     - [Responsible disclosure](https://matrix.org/security-disclosure-policy/)
12  - [Epics list](https://gitlab.com/groups/gitterHQ/-/epics)
14 ![](https://i.imgur.com/wT0bSy2.png)
17 ## Background
19 Development of Gitter can be done in any environment that supports Node.js and bash and can run Redis and MongoDB, but for simplicity we use Docker Compose to provide a pre-canned environment which contains:
21  1. Mongodb (persistent storage)
22  1. Elasticsearch (search)
23  1. Redis (caching and some persistent storage)
24  1. Neo4j (suggestions)
26 ## Prerequisites
28 Follow these instructions to setup an environment to hack on Gitter.
30  1. [Install Docker Compose](https://docs.docker.com/compose/install/)
31     * On Linux, follow the instructions over at  https://docs.docker.com/compose/install/
32     * On Mac, use [Docker for Mac](https://docs.docker.com/docker-for-mac/install/)
33     * On Windows, get [Docker for Windows](https://docs.docker.com/docker-for-windows/install/)
34  1. Install **Node 14.x (LTS)** [manually](https://nodejs.org/dist/latest-v14.x/) or using a tool like [nvm](https://github.com/creationix/nvm)
35     * If you are on Windows, you can use [nvm-windows](https://github.com/coreybutler/nvm-windows)
36  1. Install **npm 6.x**
37     * Node **10.x** already comes with **npm 6.x**. Otherwise, you can install manually with `npm install npm@^6.x -g`
38  1. Clone this repo: `git clone https://gitlab.com/gitterHQ/webapp.git`
39  1. Run `npm install`
40     * Go and make a cup of tea, because this will take a rather long time.
43 ## Starting Gitter
45 TL;DR
47 ```
48 docker-compose up -d --no-recreate
49 npm run create-seed-data
50 npm start
51 ```
53  * If you run into `Error: Cannot find module './build/Release/cld'`, delete the `node_modules` directory and run `npm install` again
56 ### Start dependent services
58 Start Gitter's dependent services:
60 ```shell
61 docker-compose up -d --no-recreate
62 ```
64 If you run into the following error, you may need to re-run the same command with `sudo`.
65 ```
66 ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?
68 If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
69 ```
71 This process will fetch Docker images from Docker Hub. You might want to make another cup of tea and have a biscuit at this point. You can also continue to the next section at this point to kill some time.
73 ### Running Gitter without OAuth
75 The simplest way to run Gitter `webapp` is to start it without [OAuth configuration](#configure-oauth-and-service-secrets). To do that, make sure [the dependent services are running](#start-dependent-services) and then run `npm run create-seed-data` which will create a room and two users in the database. You can run the `create-seed-data` script as many times as you want. It will always create new room and users. After that you can start the app with `npm start` and follow the seed data links to login to the `webapp`.
77 *Warning: This simplistic version of Gitter doesn't support signing in with GitLab, GitHub or Twitter and doesn't support integration with GitLab or GitHub.*
79 *Warning: When you delete the containers (by running `docker-compose down` or `docker-compose up` without `--no-recreate`) you'll have to generate new seed data.*
81 *If you are interested in improving this process, please visit https://gitlab.com/gitterHQ/webapp/issues/2463*
83 ### Configure OAuth and service secrets
85 <a id="configure-service-secrets"></id>
87 This is an optional step. If you don't want the sign in with GitLab, GitHub, Twitter features, then you can just use the test accounts that the `npm run create-seed-data` will log out (from the [step above](#running-gitter-without-oauth)).
89 Gitter connects to third party APIs. In order to do this, you will need to generate API tokens and add them to your configuration.
91 You only need to collect the secrets once. But you need to export the environment variables in any new terminal session.
93 In the future, we hope to streamline this process and skip OAuth providers. You can track https://gitlab.com/gitterHQ/webapp/issues/1973
95 #### Mac
97 To do this automatically, run the following command which will create a `.env` file (this only needs to be done once):
98 ```shell
99 ./obtain-secrets
102 Export the environment variables with (this needs to be done in any new terminal session):
104 ```bash
105 source .env
108 #### Windows
110 The `./obtain-secrets` script doesn't support Windows yet.
112 Create `.env` in the project root and follow the `REM` comments in the snippet below (this only needs to be done once):
114 `.env`
116 SET web__sessionSecret=xxx
117 SET ws__superClientPassword=xxx
118 SET web__messageSecret=xxx
119 SET email__unsubscribeNotificationsSecret=xxx
120 SET integrations__secret=xxx
121 SET github__statePassphrase=xxx
123 REM Visit https://developer.twitter.com/en/apps/create, name: Gitter Twitter YOURTWITTERUSERNAME, callback url: http://localhost:5000/login/twitter/callback
124 REM After creation, click "keys and tokens" to get your Consumer API Keys
125 SET twitteroauth__consumer_key=xxx
126 SET twitteroauth__consumer_secret=xxx
128 REM Visit https://gitlab.com/profile/applications, name: Gitter User Dev, redirect URI: http://localhost:5000/login/gitlab/callback, scopes: api, read_user
129 SET gitlaboauth__client_id=xxx
130 SET gitlaboauth__client_secret=xxx
131 REM Visit https://github.com/settings/applications/new, name: Gitter Private Dev, authorization callback url: http://localhost:5000/login/callback
132 SET github__client_id=xxx
133 SET github__client_secret=xxx
134 REM Visit https://github.com/settings/applications/new, name: Gitter User Dev, authorization callback url: http://localhost:5000/login/callback
135 SET github__user_client_id=xxx
136 SET github__user_client_secret=xxx
137 REM Same as github__user_client_id
138 SET github__anonymous_app__client_id=xxx
140 REM Same as github__user_client_secret
141 SET github__anonymous_app__client_secret=xxx
143 REM This can be some random string
144 SET tokens__anonymousPassword=xxx
146 REM These can be some random string
147 SET matrix__bridge__id=xxx
148 SET matrix__bridge__hsToken=xxx
149 SET matrix__bridge__asToken=xxx
152 Export the environment variables with (this needs to be done in any new terminal session):
154 ```powershell
155 @FOR /f "tokens=*" %i IN ('cat .env') DO @%i
158 #### Remote machines
160 If you've got an access to Gitter beta and production environments, you can [follow the infrastructure instructions](https://gitlab.com/gitlab-com/gl-infra/gitter-infrastructure/-/blob/master/docs/diagnostics.md#configure-secrets) to set up the secrets.
163 ### Start Gitter services
165 Only proceed once [dependent services](#start-dependent-services) (Docker containers) have started.
167 Gitter is executed through Gulp with the following command:
169 ```shell
170 npm start
173 Visit [http://localhost:5000](http://localhost:5000)
175 #### Inspecting the Node.js instance
177 You can inspect the Node.js instance with Chrome devtools by adding the `--inspect-node` flag.
178 This allows you to use things like breakpoints, `debugger`, and step through the code.
180 ```sh
181 npm start -- --inspect-node
184 You can also install the [Node.js inspector Manager (NiM)](https://chrome.google.com/webstore/detail/gnhhdgbaldcilmgcpfddgdbkhjohddkj)
185 browser extension to automatically keep your devtools up to date when
186 Nodemon restarts the Node.js process.
188 ### Clearing the local MongoDB
190 Local MongoDB uses a `gitter-mongodb` docker volume to persist the DB state even after shutting down the container. You can remove this volume by running `docker volume rm gitter-mongodb` (you might need to remove containers that use the volume or use `-f` option). Docker compose will create a new volume next time you start MongoDB container.
192 ### Browsing local MongoDB (GUI)
194 The Docker compose command we ran above starts a [`mongo-express`](https://github.com/mongo-express/mongo-express) container. You can use it to view content/data in your local MongoDB, see [http://localhost:8081/](http://localhost:8081/).
196 ### Shutting down Docker Compose
198 You can stop the docker containers with:
200 ```shell
201 docker-compose stop
204 If you want to remove your containers, use
206 ```shell
207 docker-compose rm -f
210 ### Going further
212 We also have some other docs which give a [overview/walkthrough of the codebase](https://gitlab.com/gitterHQ/webapp/blob/develop/docs/code-overview.md)
213 and [some notes on touching production](https://gitlab.com/gl-infra/gitter-infrastructure/blob/master/README.md).
216 ### Submitting a merge request
218 #### Code style/formatting (lint)
220 This project uses [Prettier](https://prettier.io/docs/en/install.html) for opinionated automatic formatting.
221 You can run the following commands to check and fix the formatting before submitting your merge request.
223 Checking is done in the `validate` CI job and this should pass regardless of your what project secrets you setup
226 npm run prettier -- --check "**/*.{js,vue}"
228 npm run prettier -- --write "**/*.{js,vue}"
231 There are also [Prettier plugins/integrations for your editor](https://prettier.io/docs/en/editors.html) if you prefer to have it built in and format on save.
234 #### Getting the GitLab CI tests green :white\_check\_mark:
236 Just add all of the variables from your `.env` file to your forked projects [**Settings** -> **CI/CD** -> **Environment variables**](https://docs.gitlab.com/ee/ci/variables/#variables) section
238 After adding the variables, just retry the pipeline.
240 You can look at the [issues labeled with ~"test"](https://gitlab.com/gitterHQ/webapp/issues?scope=all&utf8=%E2%9C%93&state=opened&label_name[]=test) for any known problems.
243 ### Testing
245 All unit tests etc can be run with `npm test`
248 #### Run individual tests
250 Anything after the `--` is an argument to Mocha itself, see https://mochajs.org/#command-line-usage
253 npm run mocha -- test/some-test.js
255 npm run mocha -- test/some-test.js --grep "specific test"
258 #### End-to-end(e2e) tests
260 Start the `webapp` with the fixtures endpoint and GitHub API stubbed
262 macOS/Linux:
263 ```shell
264 DISABLE_GITHUB_API=1 ENABLE_FIXTURE_ENDPOINTS=1 npm start
267 Windows:
268 ```shell
269 set DISABLE_GITHUB_API=1&&set ENABLE_FIXTURE_ENDPOINTS=1&&npm start
272 Start the e2e tests
274 ```shell
275 # Run with GUI (in Chrome)
276 npm run test-e2e-open
278 # Run headless without any GUI (in Electron)
279 npm run test-e2e-run
283 # Contributing
285 We use [git-flow](https://danielkummer.github.io/git-flow-cheatsheet/). Merge requests should be made against `develop` not `master`.
287 Please join us in [gitter/contributing](https://gitter.im/gitter/contributing) for questions or to get in touch.