|
| 1 | +# `docs-rs` |
| 2 | + |
| 3 | +This is the [Terraform] module that defines the infrastructure for [docs.rs]. |
| 4 | + |
| 5 | +**NOTE**: As of Feb 2023, this infrastructure configuration is only used for the docs.rs staging environment. The production environment running on docs.rs is using a different architecture. The plan of record is to move production to using this configuration. |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +[docs.rs] consists of a few different components: |
| 10 | + |
| 11 | +- A web frontend hosted as a container running in an [ECS] cluster. |
| 12 | +- A background documentation builder running on [ec2](https://aws.amazon.com/ec2) instances as part of an [autoscaling](https://aws.amazon.com/ec2/autoscaling) group. |
| 13 | +- A background utility (**TODO**: this is currently not configured) which includes: |
| 14 | + - crate registry watcher that watches for changes to the crates registry and enqueues doc builds |
| 15 | + - the repository stats updater that ensures # stars, # issues, etc. from GitHub & GitLab are up-to-date |
| 16 | + - the CDN invalidation queue handler |
| 17 | + |
| 18 | +These are documented in more detail below. |
| 19 | + |
| 20 | +Data is stored in two different locations: |
| 21 | + |
| 22 | + - Static rendered crate documentation is stored in [S3](https://aws.amazon.com/s3). |
| 23 | + - Other data is stored in a postgresql database [RDS](https://aws.amazon.com/rds) instance. |
| 24 | + |
| 25 | +### The Flow |
| 26 | + |
| 27 | +```mermaid |
| 28 | +flowchart TD |
| 29 | + web[Web Frontend]<-->Postgres |
| 30 | + s3-->web |
| 31 | + worker[Background Worker]<-->Postgres |
| 32 | + worker-->s3 |
| 33 | + watcher[Registry Watcher]-->Postgres |
| 34 | +``` |
| 35 | + |
| 36 | +The registry watcher watches the registry for new entries. When a new crate is added, it adds that crate to a queue stored in the database. The background worker watches the queue and works off crates from the queue as quickly as possible. It builds crate documentation and stores the artifacts in s3, adds relevant information to the database, and removes the crate from the queue. The web frontend then displays that information to the user. |
| 37 | + |
| 38 | +## Web Frontend |
| 39 | + |
| 40 | +```mermaid |
| 41 | +flowchart LR |
| 42 | + User -- DNS --> CloudFront |
| 43 | + CloudFront -- DNS --> ECSLB[Application Load Balancer] |
| 44 | + ECSLB --> service[ECS Service] |
| 45 | + |
| 46 | + subgraph ecs [ECS Cluster] |
| 47 | + service --> Container |
| 48 | + service -.-> task[Task Definition] |
| 49 | + end |
| 50 | +``` |
| 51 | + |
| 52 | +The user-facing web frontend for [docs.rs] is hosted on AWS [ECS]. Requests go through several hops on their way from the [CloudFront] distribution through the ECS Cluster to an ECS service and ultimately an ECS task which contains a container running the docs.rs web server. Many of these steps are behind a domain name which is configured in AWS [Route 53]. |
| 53 | + |
| 54 | +## Background Worker |
| 55 | + |
| 56 | +**TODO**: the background worker is work in progress. Once it is fully configured, we should document how it works here. |
| 57 | + |
| 58 | +## Registry Watcher |
| 59 | + |
| 60 | +**TODO**: the registry watcher is work in progress. Once it is fully configured, we should document how it works here. |
| 61 | + |
| 62 | +[terraform]: https://terraform.io |
| 63 | +[docs.rs]: https://docs.rs |
| 64 | +[ECS]: https://aws.amazon.com/ecs |
| 65 | +[CloudFront]: https://aws.amazon.com/cloudfront |
| 66 | +[Route 53]: https://aws.amazon.com/route53/ |
0 commit comments