Skip to content

Commit a64b47e

Browse files
authored
Merge pull request #470 from jyn514/docker-instructions
Instructions and bugfixes for docker
2 parents 2cc016f + 2d87b80 commit a64b47e

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
6060
git \
6161
libmagic1 \
6262
docker.io \
63-
ca-certificates
63+
ca-certificates \
64+
build-essential \
65+
gcc \
66+
pkg-config \
67+
libssl-dev
6468

6569
RUN mkdir -p /opt/docsrs/prefix
6670

@@ -71,4 +75,4 @@ COPY docker-entrypoint.sh /opt/docsrs/entrypoint.sh
7175

7276
WORKDIR /opt/docsrs
7377
ENTRYPOINT ["/opt/docsrs/entrypoint.sh"]
74-
CMD ["daemon", "--foreground"]
78+
CMD ["start-web-server"]

README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ Example badges for `mio` crate:
4949

5050
## Development
5151

52-
We strongly recommend using docker-compose, which will make it easier to get started
53-
without adding new users and packages to your host machine.
52+
We strongly recommend using [docker-compose](https://docs.docker.com/compose/),
53+
which will make it easier to get started without adding new users and packages
54+
to your host machine.
5455

5556
### Getting started
5657

@@ -60,7 +61,19 @@ Make sure you have docker-compose and are able to download ~10GB data on the fir
6061
git clone https://github.com/rust-lang/docs.rs.git docs.rs
6162
cd docs.rs
6263
cp .env.sample .env
63-
docker-compose up # This may take a half hour or more on the first run
64+
65+
docker-compose build # This builds the docs.rs binary
66+
67+
# Build a sample crate to make sure it works
68+
# This sets up the docs.rs build environment, including installing the nightly
69+
# Rust toolchain. This will take a while the first time but will be cached afterwards.
70+
docker-compose run web build crate regex 1.3.1
71+
72+
# This starts the web server but does not build any crates.
73+
# If you want to build crates, see below under `build` subcommand.
74+
# It should print a link to the website once it finishes initializing.
75+
docker-compose up
76+
6477
```
6578

6679
If you need to store big files in the repository's directory it's recommended to
@@ -91,7 +104,7 @@ This is probably because you have `git.autocrlf` set to true,
91104
```sh
92105
# This command will start web interface of docs.rs and you can access it from
93106
# http://localhost:3000/`
94-
docker-compose run -p 3000:3000 web start-web-server
107+
docker-compose up
95108
```
96109

97110
#### `build` subcommand
@@ -126,15 +139,24 @@ docker-compose run web database add-directory <DIRECTORY> [PREFIX]
126139
docker-compose run web database update-github-fields
127140
```
128141

129-
If you want to explore or edit database manually, you can connect database
130-
with `psql` command.
142+
If you want to explore or edit database manually, you can connect to the database
143+
with the `psql` command.
131144

132145
```sh
133146
# this will print the name of the container it starts
134147
docker-compose run -d db
135148
docker exec -it <the container name goes here> psql -U cratesfyi
136149
```
137150

151+
#### `daemon` subcommand
152+
153+
```sh
154+
# Run a persistent daemon which queues builds and starts a web server.
155+
# Warning: This will try to queue hundreds of packages on crates.io, only start it
156+
# if you have enough resources!
157+
docker-compose run -p 3000:3000 web daemon --foreground
158+
```
159+
138160
### Contact
139161

140162
Docs.rs is run and maintained by [Rustdoc team](https://www.rust-lang.org/governance/teams/dev-tools#rustdoc).

src/web/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,11 @@ pub fn start_web_server(sock_addr: Option<&str>) {
441441
metrics::UPLOADED_FILES_TOTAL.inc_by(0);
442442

443443
let cratesfyi = CratesfyiHandler::new();
444-
Iron::new(cratesfyi).http(sock_addr.unwrap_or("0.0.0.0:3000")).unwrap();
444+
let addr = sock_addr.unwrap_or("0.0.0.0:3000");
445+
// need to assign this so it's not dropped before the function ends
446+
let _server = Iron::new(cratesfyi).http(addr)
447+
.unwrap_or_else(|_| panic!("Failed to bind to socket on {}", addr));
448+
info!("Running docs.rs web server on http://{}", addr);
445449
}
446450

447451

0 commit comments

Comments
 (0)