|
| 1 | +# Monkeytype Self Hosting |
| 2 | + |
| 3 | +<!-- TOC ignore:true --> |
| 4 | + |
| 5 | +## Table of contents |
| 6 | + |
| 7 | +<!-- TOC --> |
| 8 | + |
| 9 | +- [Monkeytype Self Hosting](#monkeytype-self-hosting) |
| 10 | + - [Table of contents](#table-of-contents) |
| 11 | + - [Prerequisites](#prerequisites) |
| 12 | + - [Quickstart](#quickstart) |
| 13 | + - [Account System](#account-system) |
| 14 | + - [Setup Firebase](#setup-firebase) |
| 15 | + - [Update backend configuration](#update-backend-configuration) |
| 16 | + - [Setup Recaptcha](#setup-recaptcha) |
| 17 | + - [Enable daily leaderboards](#enable-daily-leaderboards) |
| 18 | + - [Configuration files](#configuration-files) |
| 19 | + - [env file](#env-file) |
| 20 | + - [serviceAccountKey.json](#serviceaccountkeyjson) |
| 21 | + - [backend-configuration.json](#backend-configurationjson) |
| 22 | + |
| 23 | +<!-- /TOC --> |
| 24 | + |
| 25 | + |
| 26 | +## Prerequisites |
| 27 | +- you need `docker` and `docker-compose-plugin` installed. Follow the [docker documentation](https://docs.docker.com/compose/install/) on how to do this. |
| 28 | + |
| 29 | +## Quickstart |
| 30 | + |
| 31 | +- create a new directory, e.g. `monkeytype` and open it. |
| 32 | +- download the [docker-compose.yml](https://github.com/monkeytypegame/monkeytype/tree/master/docker/docker-compose.yml) |
| 33 | +- create an `.env` file, you can copy the content from the [example.env](https://github.com/monkeytypegame/monkeytype/tree/master/docker/example.env). |
| 34 | +- create an `serviceAccountKey.json` file. you can copy the content from the [serviceAccountKey-example.json](https://github.com/monkeytypegame/monkeytype/tree/master/docker/serviceAccountKey-example.json). |
| 35 | +- download the [backend-configuration.json](https://github.com/monkeytypegame/monkeytype/tree/master/docker/backend-configuration.json) |
| 36 | +- run `docker compose up -d` |
| 37 | +- After the command exits successfully you can access [http://localhost:8080](http://localhost:8080) |
| 38 | + |
| 39 | + |
| 40 | +## Account System |
| 41 | + |
| 42 | +User signup/login is disabled by default. To allow users to signup you'll need to setup a Firebase project. |
| 43 | + |
| 44 | +### Setup Firebase |
| 45 | + |
| 46 | +- create a [Firebase](https://firebase.google.com/) account |
| 47 | +- create a [new Firebase project](https://console.firebase.google.com/u/0/). |
| 48 | + - name "monkeytype" |
| 49 | + - uncheck "enable google analytics" |
| 50 | +- enable authentication |
| 51 | + - open the [firebase console](https://console.firebase.google.com/) and open your project |
| 52 | + - go to `Authentication > Sign-in method` |
| 53 | + - enable `Email/Password` and save |
| 54 | +- generate service account |
| 55 | + - open the project settings by clicking the `⚙` icon on the sidebar and `Project settings` |
| 56 | + - go to `Service accounts` |
| 57 | + - click `Generate new private key`. This will download a `.json` file. |
| 58 | + - store the `.json` file as `serviceAccountKey.json` |
| 59 | + |
| 60 | +- update the `.env` file |
| 61 | + - open the [firebase console](https://console.firebase.google.com/) and open your project |
| 62 | + - open the project settings by clicking the `⚙` icon on the sidebar and `Project settings` |
| 63 | + - If there is no app in your project create a new web-app `</>` |
| 64 | + - nickname `monkeytype` |
| 65 | + - uncheck `set up firebase hosting` |
| 66 | + - click `Register app` |
| 67 | + - select your app and select `Config` for `SDK setup and configuration` |
| 68 | + - it will display sth like this: |
| 69 | + ``` |
| 70 | + const firebaseConfig = { |
| 71 | + apiKey: "AAAAAAAA", |
| 72 | + authDomain: "monkeytype-00000.firebaseapp.com", |
| 73 | + projectId: "monkeytype-00000", |
| 74 | + storageBucket: "monkeytype-00000.appspot.com", |
| 75 | + messagingSenderId: "90000000000", |
| 76 | + appId: "1:90000000000:web:000000000000" |
| 77 | + }; |
| 78 | + ``` |
| 79 | + - update the `.env` file with the values above: |
| 80 | + ``` |
| 81 | + FIREBASE_APIKEY="AAAAAAAA" |
| 82 | + FIREBASE_AUTHDOMAIN="monkeytype-00000.firebaseapp.com" |
| 83 | + FIREBASE_PROJECTID="monkeytype-00000" |
| 84 | + FIREBASE_STORAGEBUCKET="monkeytype-00000.appspot.com" |
| 85 | + FIREBASE_MESSAGINGSENDERID="90000000000" |
| 86 | + FIREBASE_APPID="1:90000000000:web:000000000000" |
| 87 | + ``` |
| 88 | + |
| 89 | +### Update backend configuration |
| 90 | + |
| 91 | +- update the `backend-configuration.json` file and add/modify |
| 92 | + ```json |
| 93 | + { |
| 94 | + "users": { |
| 95 | + "signUp": true, |
| 96 | + "profiles": { |
| 97 | + "enabled": true |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + ``` |
| 102 | + |
| 103 | +### Setup Recaptcha |
| 104 | + |
| 105 | +- [create](https://www.google.com/recaptcha/admin/create) a new recaptcha token |
| 106 | + - label: monkeytype |
| 107 | + - type: v2 |
| 108 | + - domain: the domain of the frontend |
| 109 | +- update the `.env` file with the site key from the previous step |
| 110 | + ``` |
| 111 | + RECAPTCHA_SITE_KEY="your site key" |
| 112 | + RECAPTCHA_SECRET="your secret key" |
| 113 | + ``` |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | +## Enable daily leaderboards |
| 118 | + |
| 119 | +To enable daily leaderboards update the `backend-configuration.json` file and add/modify |
| 120 | +```json |
| 121 | +{ |
| 122 | + "dailyLeaderboards": { |
| 123 | + "enabled": true, |
| 124 | + "maxResults": 250, |
| 125 | + "leaderboardExpirationTimeInDays": 1, |
| 126 | + "validModeRules": [ |
| 127 | + { |
| 128 | + "language": "english", |
| 129 | + "mode": "time", |
| 130 | + "mode2": "15" |
| 131 | + }, |
| 132 | + { |
| 133 | + "language": "english", |
| 134 | + "mode": "time", |
| 135 | + "mode2": "60" |
| 136 | + } |
| 137 | + ] |
| 138 | + } |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +- language is one of the supported language |
| 143 | +- mode can be `time` or `words` |
| 144 | +- mode2 can be `15`,`30`,`60` or `120` if you picked `mode=time` or `10`,`25`,`50` or `100` if you picked `mode=words`. |
| 145 | + |
| 146 | +## Configuration files |
| 147 | + |
| 148 | +### env file |
| 149 | + |
| 150 | +All settings are described in the [example.env](https://github.com/monkeytypegame/monkeytype/tree/master/docker/example.env) file. |
| 151 | + |
| 152 | +### serviceAccountKey.json |
| 153 | + |
| 154 | +Contains your firebase config, only needed if you want to allow users to signup. |
| 155 | + |
| 156 | +### backend-configuration.json |
| 157 | + |
| 158 | +Configuration of the backend. |
| 159 | + |
| 160 | +If you don't want to update this file manually you can |
| 161 | + |
| 162 | +- open the backend url in your browser, e.g. `http://localhost:5005/configure/` |
| 163 | +- adjust the settings and click `Save Changes` |
| 164 | +- open the configuration in your browser, e.g. `http://localhost:5005/configuration` |
| 165 | +- copy everything from `data` into the `backend-configuration.json` file. |
| 166 | + |
| 167 | +Example output from `http://localhost:5005/configuration`: |
| 168 | +```json |
| 169 | +{ |
| 170 | + "message": "Configuration retrieved", |
| 171 | + "data": |
| 172 | + { |
| 173 | + "maintenance": false, |
| 174 | + "results": {}, |
| 175 | + .... |
| 176 | + } |
| 177 | +} |
| 178 | +``` |
| 179 | + |
| 180 | +Example content from `backend-configuration.json`: |
| 181 | +``` |
| 182 | +{ |
| 183 | + "maintenance": false, |
| 184 | + "results": {}, |
| 185 | + .... |
| 186 | +} |
| 187 | +``` |
| 188 | + |
| 189 | +If you have the `curl` and `jq` installed you can also run `curl -wO- http://localhost:5005/configuration | jq ".data" > backend-configuration.json` to update the configuration file. |
| 190 | + |
| 191 | + |
| 192 | +_Note:_ The configuration is applied on container startup only. You have to restart the container for your changes to become active. |
0 commit comments