Skip to content

Commit 76c0b35

Browse files
committed
Add wiki pages for docs.rs
1 parent e6596a3 commit 76c0b35

File tree

7 files changed

+505
-23
lines changed

7 files changed

+505
-23
lines changed

src/SUMMARY.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@
3838
- [Crater agents](./infra/docs/crater-agents.md)
3939
- [Discord moderation bot](./infra/docs/discord-mods-bot.md)
4040
- [Domain names and DNS](./infra/docs/dns.md)
41-
- [docs.rs](./infra/docs/docs-rs.md)
41+
- [docs.rs](./infra/docs/docs-rs/README.md)
42+
- [Adding dependencies to the build environment](./infra/docs/docs-rs/add-dependencies.md)
43+
- [Developing without docker-compose](./infra/docs/docs-rs/no-docker-compose.md)
44+
- [Self-hosting a docs.rs instance](./infra/docs/docs-rs/self-hosting.md)
45+
- [Maintenance procedures](./infra/docs/docs-rs/maintenance.md)
46+
- [Migrating from a local database to S3](./infra/docs/docs-rs/migrate-s3.md)
4247
- [Monitoring](./infra/docs/monitoring.md)
4348
- [rust-bots server](./infra/docs/rust-bots.md)
4449
- [rust-lang/rust CI](./infra/docs/rustc-ci.md)

src/infra/docs/docs-rs/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# docs.rs
2+
3+
* Source code: [rust-lang/docs.rs][repo]
4+
* Hosted on: `docsrs.infra.rust-lang.org` (behind the bastion -- [how to connect][bastion-connect])
5+
* Maintainers: [onur][onur], [QuietMisdreavus][QuietMisdreavus]
6+
* [Instance metrics][grafana-instance] (only available to infra team members).
7+
* [Application metrics][grafana-app] (only available to infra team members).
8+
9+
[repo]: https://github.com/rust-lang/docs.rs
10+
[grafana-instance]: https://grafana.rust-lang.org/d/rpXrFfKWz/instance-metrics?orgId=1&var-instance=docsrs.infra.rust-lang.org:9100
11+
[grafana-app]: https://grafana.rust-lang.org/d/-wWFg2cZz/docs-rs?orgId=1
12+
[bastion-connect]: https://github.com/rust-lang/infra-team/blob/master/docs/hosts/bastion.md#logging-into-servers-through-the-bastion
13+
[onur]: https://github.com/onur
14+
[QuietMisdreavus]: https://github.com/QuietMisdreavus
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Add a dependency to the build environment
2+
3+
Rustwide internally uses `rustops/crates-build-env` as the build environment for the crate. If you want to add a system package for crates to link to, this is place you're looking for.
4+
5+
## Getting started
6+
7+
First, clone the crates-build-env repo:
8+
9+
```console
10+
$ git clone https://github.com/rust-lang/crates-build-env && cd crates-build-env
11+
```
12+
13+
Next, add the package to `packages.txt`. This should be the name of a package in the **Ubuntu 18.04** Repositories. See [the package home page](https://packages.ubuntu.com/) for a full list/search bar, or use `apt search` locally.
14+
15+
## Building the image
16+
17+
Now build the image. This will take a very long time, probably 10-20 minutes.
18+
19+
```console
20+
$ docker build --tag build-env .
21+
```
22+
23+
## Testing the image
24+
25+
Use the image to build your crate.
26+
27+
```
28+
$ cd /path/to/docs.rs
29+
$ docker-compose build
30+
# NOTE: this must be an absolute path, not a relative path
31+
# On platforms with coreutils, you can instead use `$(realpath ../relative/path)`
32+
$ YOUR_CRATE=/path/to/your/crate
33+
# avoid docker-compose creating the volume if it doesn't exist
34+
$ if [ -e "$YOUR_CRATE" ]; then
35+
docker-compose run -e DOCS_RS_LOCAL_IMAGE=build-env \
36+
-v "$YOUR_CRATE":/opt/rustwide/workdir \
37+
web build crate --local /opt/rustwide/workdir
38+
else
39+
echo "$YOUR_CRATE does not exist";
40+
fi
41+
```
42+
43+
## Making multiple changes
44+
45+
If your build fails even after your changes, it will be annoying to rebuild the image from scratch just to add a single package. Instead, you can make changes directly to the Dockerfile so that the existing packages are cached. Be sure to move these new packages from the Dockerfile to `packages.txt` once you are sure they work.
46+
47+
On line 7 of the Dockerfile, add this line: `RUN apt-get install -y your_second_package`.
48+
Rerun the build and start the container; it should take much less time now:
49+
50+
```console
51+
$ cd /path/to/crates-build-env
52+
$ docker build --tag build-env .
53+
$ cd /path/to/docs.rs
54+
$ docker-compose run -e DOCS_RS_LOCAL_IMAGE=build-env \
55+
-v "$YOUR_CRATE":/opt/rustwide/workdir \
56+
web build crate --local /opt/rustwide/workdir
57+
```
58+
59+
## Run the lint script
60+
61+
Before you make a PR, run the shell script `ci/lint.sh` and make sure it passes. It ensures `packages.txt` is in order and will tell you exactly what changes you need to make if not.
62+
63+
## Make a pull request
64+
65+
Once you are sure your package builds, you can make a pull request to get it adopted upstream for docs.rs and crater. Go to https://github.com/rust-lang/crates-build-env and click 'Fork' in the top right. Locally, add your fork as a remote in git and push your changes:
66+
67+
```console
68+
$ git remote add personal https://github.com/<your_username_here>/crates-build-env
69+
$ git add -u
70+
$ git commit -m 'add packages necessary for <your_package_here> to compile'
71+
$ git push personal
72+
```
73+
74+
Back on github, make a pull request:
75+
76+
1. Go to https://github.com/rust-lang/crates-build-env/compare
77+
2. Click 'compare across forks'
78+
3. Click 'head repository' -> <your_username>/crates-build-env
79+
4. Click 'Create pull request'
80+
5. Add a description of what packages you added and what crate they fixed
81+
6. Click 'Create pull request' again in the bottom right.
82+
83+
Hopefully your changes will be merged quickly! After that you can either publish a point release (rebuilds your docs immediately) or request for a member of the docs.rs team to schedule a new build (may take a while depending on their schedules).

src/infra/docs/docs-rs.md renamed to src/infra/docs/docs-rs/maintenance.md

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
# docs.rs
1+
# Common maintenance procedures
22

3-
* Source code: [rust-lang/docs.rs][repo]
4-
* Hosted on: `docsrs.infra.rust-lang.org` (behind the bastion -- [how to connect][bastion-connect])
5-
* Maintainers: [onur][onur], [QuietMisdreavus][QuietMisdreavus]
6-
* [Instance metrics][grafana-instance] (only available to infra team members).
7-
* [Application metrics][grafana-app] (only available to infra team members).
8-
9-
## Common maintenance procedures
10-
11-
### Temporarily remove a crate from the queue
3+
## Temporarily remove a crate from the queue
124

135
It might happen that a crate fails to build repeatedly due to a docs.rs bug,
146
clogging up the queue and preventing other crates to build. In this case it's
@@ -32,7 +24,7 @@ query:
3224
UPDATE queue SET attempt = 0 WHERE name = '<CRATE_NAME>';
3325
```
3426

35-
### Pinning a version of nightly
27+
## Pinning a version of nightly
3628

3729
Sometimes the latest nightly might be broken, causing doc builds to fail. In
3830
those cases it's possible to tell docs.rs to stop updating to the latest
@@ -53,7 +45,7 @@ systemctl restart docs.rs
5345
To return to the latest nightly simply remove the environment variable and
5446
restart docs.rs again.
5547

56-
### Rebuild a specific crate
48+
## Rebuild a specific crate
5749

5850
If a bug was recently fixed, you may want to rebuild a crate so that it builds with the latest version.
5951
From the docs.rs machine:
@@ -64,7 +56,7 @@ cratesfyi queue add <crate> <version>
6456

6557
This will add the crate with a lower priority than new crates by default, you can change the priority with the `-p` option.
6658

67-
### Adding all the crates failed after a date back in the queue
59+
## Adding all the crates failed after a date back in the queue
6860

6961
After an outage you might want to add all the failed builds back to the queue.
7062
To do that, log into the machine and open a PostgreSQL shell with:
@@ -80,7 +72,7 @@ HH:MM:SS` back in the queue:
8072
UPDATE queue SET attempt = 0 WHERE attempt >= 5 AND build_time > 'YYYY-MM-DD HH:MM:SS';
8173
```
8274

83-
### Removing a crate from the website
75+
## Removing a crate from the website
8476

8577
Sometimes it might be needed to remove all the content related to a crate from
8678
docs.rs (for example after receiving a DMCA). To do that, log into the server
@@ -93,7 +85,7 @@ cratesfyi database delete-crate CRATE_NAME
9385
The command will remove all the data from the database, and then remove the
9486
files from S3.
9587

96-
### Blacklisting crates
88+
## Blacklisting crates
9789

9890
Occasionally it might be needed to prevent a crate from being built on docs.rs,
9991
for example if we can't legally host the content of those crates. To add a
@@ -107,10 +99,3 @@ Other operations (such as `list` and `remove`) are also supported.
10799

108100
> **Warning:** blacklisting a crate doesn't remove existing content from the
109101
> website, it just prevents new versions from being built!
110-
111-
[repo]: https://github.com/rust-lang/docs.rs
112-
[grafana-instance]: https://grafana.rust-lang.org/d/rpXrFfKWz/instance-metrics?orgId=1&var-instance=docsrs.infra.rust-lang.org:9100
113-
[grafana-app]: https://grafana.rust-lang.org/d/-wWFg2cZz/docs-rs?orgId=1
114-
[bastion-connect]: https://github.com/rust-lang/infra-team/blob/master/docs/hosts/bastion.md#logging-into-servers-through-the-bastion
115-
[onur]: https://github.com/onur
116-
[QuietMisdreavus]: https://github.com/QuietMisdreavus

src/infra/docs/docs-rs/migrate-s3.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Migrating from a local database to S3
2+
3+
If you're running your own instance of docs.rs for personal development, and you'd like to test out the S3 integration, there are a couple steps involved. It's mostly straightforward, but there's at least one major caveat that should be taken into account.
4+
5+
## Requirements
6+
7+
Since docs.rs uses a fixed bucket name to upload files, you'll need to set up an independent server that implements the Amazon S3 API. [Minio](https://min.io/) is an example of a server you can set up. Instructions for installing and configuring Minio (or any S3-compliant provider) are beyond the scope of this article.
8+
9+
## Configuring your docs.rs instance
10+
11+
Once you have your server and credentials set up, you need to tell the docs.rs server to use it. You'll need to add some extra environment variables to the environment file you use to configure docs.rs. It uses the `S3_ENDPOINT` variable to determine where to call, and the other variables to configure its access privileges. The available environment variables are documented in `rusoto`'s [`EnvironmentProvider`](https://docs.rs/rusoto_credential/0.40.0/rusoto_credential/struct.EnvironmentProvider.html).
12+
13+
```text
14+
AWS_ACCESS_KEY_ID=<access key>
15+
AWS_SECRET_ACCESS_KEY=<access secret>
16+
S3_ENDPOINT=<endpoint url>
17+
```
18+
19+
## Migrating files out of the database
20+
21+
Before you restart the process to load the new credentials, the files that are currently in the local database need to be migrated out to S3. Once docs.rs sees that it has AWS credentials in its environment, it will stop reading from the `files` table entirely. Therefore, to properly transition to using the new file storage, you need to run an extra command to upload them. It's helpful to lock the build queue while this is happening, so that no new files will sneak in while the migration happens.
22+
23+
```sh
24+
cratesfyi build lock
25+
# edit the environment file with the above variables if you haven't already
26+
cratesfyi database move-to-s3 # this will take a while, depending on the size of your database
27+
sudo systemctl restart cratesfyi # or however you manage your docs.rs service
28+
# verify that files are loading from S3/Minio/etc
29+
cratesfyi build unlock
30+
```
31+
32+
Once this is done, new crate builds will upload files directly to your file storage service rather than into the database. The `move-to-s3` command will remove rows from the `files` table in the database as it uploads them, so once you're done, you can compact the database to shrink its on-disk size.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Developing locally without docker-compose
2+
3+
These are instructions for developing docs.rs locally. For deploying in a production environment, see [Self-hosting a docs.rs instance](self-hosting.html).
4+
5+
While the docker-compose allows for easier setup of the required dependencies and environment, here is a breakdown of how to use the service without an outer docker container. This is useful e.g. for quickly iterating during development.
6+
7+
Note that this does not remove the docker dependency altogether, since docs.rs uses docker at runtime for sandboxing. This just allows you to run commands more quickly since you are building in debug mode instead of release and are also caching more of the build.
8+
9+
## Requirements
10+
11+
The commands and package names on this page will assume a Debian-like machine with `apt` installed, but most dependencies should be relatively easy to find on Linux. Do note however that this requires the host to be `x86_64-unknown-linux-gnu`.
12+
13+
Docs.rs has a few basic requirements:
14+
15+
* Rust
16+
* Git
17+
* CMake, GCC, G++, and `pkg-config` (to build dependencies for crates and docs.rs itself)
18+
* OpenSSL, zlib, curl, and `libmagic` (to link against)
19+
* PostgreSQL
20+
21+
```console
22+
# apt install build-essential git curl cmake gcc g++ pkg-config libmagic-dev libssl-dev zlib1g-dev postgresql
23+
$ sudo -u postgres psql -c "CREATE USER cratesfyi WITH PASSWORD 'password';"
24+
$ sudo -u postgres psql -c "CREATE DATABASE cratesfyi OWNER cratesfyi;"
25+
```
26+
27+
## Building the site
28+
29+
Be warned - this builds over 350 crates! Depending on your computer, this may
30+
take upwards of 10 minutes.
31+
32+
```console
33+
$ git clone https://github.com/rust-lang/docs.rs && cd docs.rs
34+
$ cargo build
35+
```
36+
37+
## The "prefix" directory
38+
39+
docs.rs stores several files in a "prefix" directory. This can be anywhere, but if you put it in the doc.rs repo, it should go under the ./ignored/ directory so that it is not seen by git or the docker daemon.
40+
41+
```console
42+
$ mkdir -p ignored/cratesfyi-prefix
43+
$ cd ignored/cratesfyi-prefix
44+
$ mkdir -vp documentations public_html sources
45+
$ git clone https://github.com/rust-lang/crates.io-index && cd crates.io-index
46+
$ git branch crates-index-diff_last-seen
47+
```
48+
49+
(That last command is used to set up the `crates-index-diff` crate, so we can start monitoring new crate releases.)
50+
51+
## Docker group
52+
53+
docs.rs needs to run docker containers for sandboxing. Therefore, you need to be in the 'docker' group to build crates. If you are already in the docker group, you can skip this step (you can check with `groups`).
54+
55+
```console
56+
# usermod -a -G docker "$USER"
57+
$ # now logout and back in to your shell
58+
$ cd /path/to/docs.rs/ignored/cratesfyi-prefix
59+
```
60+
61+
## Environment for the server
62+
63+
To ensure that the docs.rs server is configured properly, we need to set a few environment variables. This is most easily done by making a shell script.
64+
65+
```sh
66+
$ cd ..
67+
$ echo '
68+
export CRATESFYI_PREFIX=.
69+
# or add an appropriate username/password as necessary
70+
export CRATESFYI_DATABASE_URL=postgresql://cratesfyi:password@localhost
71+
export CRATESFYI_GITHUB_USERNAME=
72+
export CRATESFYI_GITHUB_ACCESSTOKEN=
73+
export RUST_LOG=cratesfyi,rustwide=info
74+
' > env.sh
75+
```
76+
77+
This last command assumes you put the shell script in `./env.sh`,
78+
but you can name it anything as long as it is in the current directory.
79+
80+
```console
81+
$ . ./env.sh
82+
$ cargo run database migrate
83+
$ cargo run database update-search-index
84+
$ cargo run database update-release-activity
85+
# This will take between 5 and 30 minutes on the first run, depending on your internet speed.
86+
# It downloads the rustops/crates-build-env crates which is almost 1 GB.
87+
# It does not currently display a progress bar, this is https://github.com/rust-lang/rustwide/issues/9
88+
# As a workaround, you can run `docker pull rustops/crates-build-env` in a separate terminal.
89+
$ cargo run build crate rand 0.5.5
90+
```
91+
92+
## Building on platforms other than Linux
93+
94+
This is not currently possible. We assume in several places that the rustup toolchain is x86_64-unknown-linux-gnu. As a result, the only way to build on Mac or Alpine is to use the docker-compose file.
95+
96+
## Resetting the database
97+
98+
Occasionally, if you make changes to the migrations in a PR, those migrations will be saved in the database but will not be in the code when you switch back to the master branch. In this case, there is no way to undo the migration without knowing exactly which version of the code made the change (`cargo migrate` will have no effect). Here is a convenient shell script to reset the database so you don't have to remember how to undo your changes.
99+
100+
NOTE: DO NOT RUN THIS IN PRODUCTION.
101+
102+
```sh
103+
#!/bin/sh
104+
set -euv
105+
106+
. ./env.sh
107+
108+
sudo -u postgres dropdb cratesfyi --if-exists
109+
sudo -u postgres psql -c 'CREATE DATABASE cratesfyi OWNER cratesfyi;'
110+
cargo run database migrate
111+
```

0 commit comments

Comments
 (0)