Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Tighten infra documentation

Manav Rathi9e0ab7c94c41
diff --git a/infra/README.md b/infra/README.md
index 87934d2a4a..308127603f 100644
--- a/infra/README.md
+++ b/infra/README.md
@@ -1,5 +1,3 @@
# Infra
-Various knick-knacks that we use when hosting our servers.
-
-These are not needed for running Ente's server or for self-hosting, these are just additional services we run to make our infrastructure more robust. As such, it's unlikely that you'll find the pieces here directly useful for your needs, but feel free to have a look around if you're curious!
+Additional services and tools used to operate Ente's hosted infrastructure. They are not required to run or self-host Ente.
diff --git a/infra/copycat-db/README.md b/infra/copycat-db/README.md
index d93a54f57c..2535200329 100644
--- a/infra/copycat-db/README.md
+++ b/infra/copycat-db/README.md
@@ -22,10 +22,6 @@ View logs locally (they'll also be available on Grafana):
sudo tail /root/var/logs/copycat-db.log
```
-## Name
-
-The name copycat-db is a riff on "copycat", which is what we call our museum instance that does the object replication. This one replicates the DB, so, copycat-db.
-
## Backup Mode
Copycat DB requires an explicit `BACKUP_MODE`:
@@ -59,7 +55,7 @@ If needed, this config file can be generated by running the following commands o
##### SCW_RDB_INSTANCE_ID
-The UUID of the Scalway RDB instance that we wish to backup.
+The UUID of the Scaleway RDB instance to back up.
##### SCW_PRIVATE_NETWORK_ID
@@ -71,15 +67,13 @@ The compute instance running copycat-db must also be attached to this Private Ne
##### PGUSER, PGPASSWORD, PGHOST, PGPORT
-Not needed in production when taking a backup (since we use the Scaleway CLI to take backups in production).
-
-`PGUSER` and `PGPASSWORD` are used when taking a `snapshot-pgdump` backup, and when restoring backups.
+`PGUSER` and `PGPASSWORD` are required for `snapshot-pgdump` backups and restores.
For `snapshot-pgdump` backups, the host and port are resolved by the script. For restores, provide `PGHOST` and `PGPORT`.
##### RCLONE_CONFIG
-Location of the config file, that contains the destination bucket where you want to use to save the backups, and the credentials to to access it.
+Location of the config file containing the destination bucket and its credentials.
Specifically, the config file contains two remotes:
@@ -104,16 +98,16 @@ Name of the (crypt) remote to which the dump should be saved. Example: `db-backu
Note that this will not include the bucket - the bucket name will be part of the remote that the crypt remote wraps.
-##### Logging
+## Logging
-The service logs to its standard out/error. The systemd unit is configured to route these to `/var/logs/copycat-db.log`.
+The service logs to standard output and standard error. The systemd unit writes these to `/root/var/logs/copycat-db.log`.
## Local testing
The provided `test.sh` script can be used to do a smoke test for building and running the image. For example,
```sh
-./test.sh bin/bash
+./test.sh sh
```
gives us a shell prompt inside the built and running container.
@@ -122,7 +116,7 @@ For more thorough testing, run this service as part of a local test-cluster.
## Restoring
-The service also knows how to restore the latest backup into a Postgres instance. This functionality by a separate service (Phoenix) to periodically verify that the backups are restorable.
+The service can also restore the latest backup into a Postgres instance. Phoenix periodically uses this to verify that backups are restorable.
To invoke this, use "./restore.sh" as the command when running the container (e.g. `./test.sh ./restore.sh`). This will restore the latest backup into the Postgres instance whose credentials are provided via the various `PG*` environment variables.
@@ -134,7 +128,7 @@ The database dumps are stored in a bucket that has object lock enabled (complian
Ensure that promtail is running, and is configured to scrape `/root/var/logs/copycat-db.log`.
-Create that the config and log destination directories
+Create the configuration and log directories.
```sh
sudo mkdir -p /root/var/config/scw
@@ -142,7 +136,7 @@ sudo mkdir -p /root/var/config/rclone
sudo mkdir -p /root/var/logs
```
-Create the env, scw and rclone configuration files
+Create the environment, Scaleway, and rclone configuration files.
```sh
sudo tee /root/copycat-db.env
@@ -150,7 +144,7 @@ sudo tee /root/var/config/scw/copycat-db-config.yaml
sudo tee /root/var/config/rclone/copycat-db-rclone.conf
```
-Add the service definition, and start the service
+Install the service and timer definitions.
```bash
scp copycat-db.{service,timer} instance:
@@ -165,7 +159,7 @@ To start the cron job
sudo systemctl start copycat-db.timer
```
-The timer will trigger the service on the specified schedule. In addition, if you wish to force the job to service immediately
+The timer triggers the service on its schedule. To run the job immediately:
```sh
sudo systemctl start copycat-db.service
@@ -173,7 +167,7 @@ sudo systemctl start copycat-db.service
## Updating
-To update, run the [GitHub workflow](../../.github/workflows/copycat-db-release.yaml) to build and push the latest image to our Docker Registry, then restart the systemd service on the instance
+To update, run the [GitHub workflow](../../.github/workflows/copycat-db-release.yml) to build and push the latest image to our Docker registry, then restart the systemd service on the instance.
```sh
sudo systemctl restart copycat-db
diff --git a/infra/ml/test/README.md b/infra/ml/test/README.md
index b4f96b44dc..af2632e7fc 100644
--- a/infra/ml/test/README.md
+++ b/infra/ml/test/README.md
@@ -1,6 +1,8 @@
# ML Indexing Parity Test Suite
-This directory contains the ML indexing parity framework for desktop, Android, iOS, and Python ground truth. (The desktop runner is a smoke test of the desktop-specific addon path β€” the napi bindings and the pinned ONNX Runtime library β€” since deep validation of the shared Rust pipeline itself lives in the `ente-photos` crate's `ml_indexing` integration test.)
+This directory contains the ML indexing parity framework for desktop, Android, iOS, and Python ground truth.
+
+The desktop runner smoke-tests the desktop-specific N-API bindings and pinned ONNX Runtime library. Deep validation of the shared Rust pipeline lives in the `ente-photos` crate's `ml_indexing` integration test.
## Layout
diff --git a/infra/services/README.md b/infra/services/README.md
index 8e574bf0d2..52b8414399 100644
--- a/infra/services/README.md
+++ b/infra/services/README.md
@@ -6,7 +6,7 @@ Generally our services (including museum itself) follow the same pattern:
- They're run on vanilla Ubuntu instances. The only expectation they have is for Docker to be installed.
-- They log to fixed, known, locations - `/root/var/log/foo.log` - so that these logs can get ingested by Promtail if needed.
+- They log to fixed, known locations such as `/root/var/logs/foo.log` so Promtail can ingest them when needed.
- Each service should consist of a Docker image (or a Docker compose file), and a systemd unit file.
@@ -51,29 +51,18 @@ SSH into the instance.
ssh <instance>
```
-Move the service `/etc/systemd/service`, and any config files to their expected place. env and other config files that contain credentials are kept in `/root`.
+Move the service to `/etc/systemd/system`, and put configuration files containing credentials under `/root`.
```sh
sudo mv example.service /etc/systemd/system
sudo mv example.env /root
```
-If you want to start the service on boot (as spoken of in the `[Install]` section above), then enable it (this only needs to be done once):
-
-```sh
-sudo systemctl enable service
-```
-
-Restarts systemd so that it gets to know of the service.
+Tell systemd to load the unit, enable it on boot, and start it:
```sh
sudo systemctl daemon-reload
-```
-
-Now you can manage the service using standard systemd commands.
-
-```sh
-sudo systemctl start example
+sudo systemctl enable --now example
```
To view stdout/err, use:
@@ -84,12 +73,10 @@ sudo journalctl --follow --unit example
## Logging
-Simple services can log to their standard output: these are captured by Docker, and by default promtail is setup to injest Docker logs and send them to Grafana.
-
-One issue with the above simple setup is that we cannot attach job names.
+Simple services can log to standard output and error. Docker captures these logs, and Promtail sends them to Grafana.
-If the service needs to to attach a specific job name, or if the service wants more control over the log retention etc, then then services can log to to its own files.
+Services that need a specific job name or more control over retention can log to their own files.
- Such files should be in `/var/logs` within the container, and this should be mounted to `/root/var/logs` on the instance (using the `-v` flag in the service file which launches the Docker container or the Docker compose cluster).
-- There should be entry for this log file in the `promtail/promtail.yaml` on that instance. The logs will then get scraped by Promtail and sent over to Grafana.
+- Add each log file to `promtail/promtail.yaml` on that instance so Promtail can send it to Grafana.
diff --git a/infra/services/caddy/README.md b/infra/services/caddy/README.md
index d13d016d1c..5aa0b1947f 100644
--- a/infra/services/caddy/README.md
+++ b/infra/services/caddy/README.md
@@ -10,10 +10,10 @@ sudo mv Caddyfile /root/caddy/conf
sudo chown root:root /root/caddy/conf/Caddyfile
```
-Rest of it works like our other systemd services.
+The rest works like our other systemd services.
If the Caddyfile changes, the running instance can be updated without restarts by using `sudo systemctl reload caddy`.
## Backups
-The entire `/root/caddy` directory can be backed up and contains the everything needed to resurrect the same setup.
+The entire `/root/caddy` directory can be backed up and contains everything needed to restore the same setup.
diff --git a/infra/services/listmonk/README.md b/infra/services/listmonk/README.md
index d62346a346..b85232165c 100644
--- a/infra/services/listmonk/README.md
+++ b/infra/services/listmonk/README.md
@@ -26,7 +26,7 @@ sudo mv listmonk.service /etc/systemd/system/
sudo mv listmonk.nginx.conf /root/nginx/conf.d
```
-> The very first time we ran Listmonk, at this point we also needed to get it to install the tables it needs in the Postgres DB. For this, we used the `initialize-db.sh` script.
+> For a fresh database, run `initialize-db.sh` once before starting Listmonk.
>
> ```sh
> scp services/listmonk/initialize-db.sh <instance>:
diff --git a/infra/services/metabase/README.md b/infra/services/metabase/README.md
index b014264250..6db94aade4 100644
--- a/infra/services/metabase/README.md
+++ b/infra/services/metabase/README.md
@@ -1,8 +1,8 @@
# Metabase
-Use the embedded H2 database (this db contains users, saved queries etc). The database is a mounted as a file from the local filesystem into the container.
+Metabase uses its embedded H2 database for users, saved queries, and other state. The database is mounted from the local filesystem into the container.
-To take backups, backup `/root/metabase.db`
+Back up `/root/metabase.db` to preserve this state.
## Installation
diff --git a/infra/services/nginx/README.md b/infra/services/nginx/README.md
index 497b5a30cb..55d7922b35 100644
--- a/infra/services/nginx/README.md
+++ b/infra/services/nginx/README.md
@@ -38,7 +38,7 @@ When adding new services that sit behind Nginx,
1. Add its nginx conf file to `/root/nginx/conf.d`
-2. Restart nginx (`sudo systemctl reload nginx`)
+2. Reload nginx (`sudo systemctl reload nginx`)
## Configuration files
@@ -61,6 +61,6 @@ This is a [handy tool](https://nginx-playground.wizardzines.com) to check the sy
Nginx configuration files can be changed without needing to restart anything.
-1. Update the configuration file at `/root/nginx/conf.d/museum.conf`
+1. Update the service's configuration file under `/root/nginx/conf.d`.
2. Verify that there are no errors in the configuration by using `sudo docker exec nginx nginx -t`.
3. Ask nginx to reload the configuration `sudo systemctl reload nginx`.
diff --git a/infra/services/sentry/README.md b/infra/services/sentry/README.md
index 112f33ea9a..7c634e5819 100644
--- a/infra/services/sentry/README.md
+++ b/infra/services/sentry/README.md
@@ -1,6 +1,6 @@
# Sentry
-- [Data flow](#understanding-the-data-flow)
+- [Data flow](#data-flow)
- [Setting up a new instance](#setting-up-a-new-instance)
## Data flow
@@ -9,11 +9,11 @@
Clients tunnel events to sentry-reporter.ente.io, and include the DSN in the request. At the other end of the tunnel is a Cloudflare Worker which unwraps the event, remaps the DSN if needed, and sends it to our actual self-hosted Sentry instance, sentry.ente.io.
-Among other things, this indirection allows us to treat the Sentry instance as disposable, and recreate it from scratch anytime. The existing DSN's change, but that is not a problem because we remap DSNs in the worker that handles the tunneled requests.
+Among other things, this indirection allows us to treat the Sentry instance as disposable and recreate it from scratch. Project DSNs can change without requiring client updates because the worker remaps them.
### DSN
-Sentry identifies each project with a unique ID it calls **DSN** (Data Source Name). The DSN is a URL that includes the project ID. For example, here is the DSN for the debug builds of the photos mobile app:
+Sentry identifies a project through a **DSN** (Data Source Name), a URL containing its public key, host, and project ID. For example, here is the DSN for debug builds of the photos mobile app:
@@ -73,7 +73,7 @@ SENTRY_EVENT_RETENTION_DAYS=30
### Configure external nginx
-Add the nginx service (See [services/nginx](../services/nginx/README.md)) to the instance.
+Add the nginx service (see [services/nginx](../nginx/README.md)) to the instance.
Add the Sentry nginx conf and certificates (since this instance will be running only sentry, we can use sentry specific certificates instead of our general wildcard ones).
@@ -92,7 +92,7 @@ cd /home/ente/self-hosted
sudo docker compose up -d
```
-The (external) nginx service will also start automatically on boot, but if neded it can be manually started by
+The external nginx service also starts automatically on boot, but if needed it can be started manually:
```sh
sudo systemctl start nginx
diff --git a/infra/services/status/README.md b/infra/services/status/README.md
index 3137ee80bb..5b4c94285a 100644
--- a/infra/services/status/README.md
+++ b/infra/services/status/README.md
@@ -36,4 +36,4 @@ sudo systemctl reload nginx
## Administration
-Login into the [dashboard](https://status.ente.com/dashboard) for administration.
+Log in to the [dashboard](https://status.ente.com/dashboard) for administration.
diff --git a/infra/staff/README.md b/infra/staff/README.md
index 67066161b0..ff28481934 100644
--- a/infra/staff/README.md
+++ b/infra/staff/README.md
@@ -1,4 +1,4 @@
-## Staff dashboard
+# Staff dashboard
Web app for staff members to help with support and other administration.
diff --git a/infra/workers/README.md b/infra/workers/README.md
index 05b061bef9..f3f64024b6 100644
--- a/infra/workers/README.md
+++ b/infra/workers/README.md
@@ -2,39 +2,40 @@
Source code for our [Cloudflare Workers](https://developers.cloudflare.com/workers/).
-Workers are organized as npm workspaces sharing a common `package.json` and base `tsconfig`. They can however be deployed individually.
+Workers are npm workspaces that share a root `package.json` and base `tsconfig`, but are deployed individually.
## Deploying
-Install dependencies with `npm ci`.
+Install dependencies:
-> [!NOTE]
->
-> If `package-lock.json` has not changed since your last `npm ci`, you can use `npm install` as a faster incremental alternative.
+```sh
+npm ci
+```
+
+Log in if needed, then deploy the worker:
-Then, to deploy an individual worker
+```sh
+npm exec --workspace health-check -- wrangler login
+npm exec --workspace health-check -- wrangler deploy
+```
-- Login into wrangler (if needed) using `npm exec --workspace health-check -- wrangler login`
+Replace `health-check` with the worker to deploy. Wrangler credentials are shared across the workspaces.
-- Deploy! `npm exec --workspace health-check -- wrangler deploy`
+Stream logs from a deployed worker:
-Wrangler is the CLI provided by Cloudflare to manage workers. Apart from deploying, it also allows us to stream logs from running workers by using `npm exec --workspace <worker-name> -- wrangler tail`.
+```sh
+npm exec --workspace health-check -- wrangler tail
+```
-> [!NOTE]
->
-> When you're done, remember to logout!
->
-> ```sh
-> npm exec --workspace health-check -- wrangler logout
-> ```
+Log out when finished:
-> [!TIP]
->
-> `wrangler login` and `wrangler logout` can be run from any of the worker workspaces, wrangler stores the credentials in some OS dependent shared location.
+```sh
+npm exec --workspace health-check -- wrangler logout
+```
## Creating a new worker
-Copy paste an existing one. Unironically this is a good option because Cloudflare's template has a lot of unnecessary noise, but if really do want to create one from scratch, use `npm create cloudflare@latest`.
+Copy an existing workspace. This avoids the unnecessary boilerplate in Cloudflare's template. To create one from scratch, use `npm create cloudflare@latest`.
To import an existing worker from the Cloudflare dashboard, use
@@ -44,8 +45,10 @@ npm create cloudflare@2 existing-worker-name -- --type pre-existing --existing-s
## Logging
-Attach the tail worker to your worker by adding
+Attach the tail worker by adding this to `wrangler.toml`:
- tail_consumers = [{ service = "tail" }]
+```toml
+tail_consumers = [{ service = "tail" }]
+```
-in its `wrangler.toml`. Then any `console.(log|warn|error)` statements and uncaught exceptions in your worker will be logged to Grafana.
+The tail worker sends console output and uncaught exceptions to Grafana.