Skip to content

Commit a26f307

Browse files
Merge #1106
1106: Add Dockerfiles and docker-compose file r=carols10cents This PR resolves #943. I'm pretty sure I've made it so running `docker-compose up` will just work, but someone else will definitely have to verify. I also wanted to spawn a Minio (or something similar) service to replace S3, but currently the S3 host isn't configurable so I might do all that in another PR.
2 parents 564a722 + a2c67ce commit a26f307

File tree

7 files changed

+174
-0
lines changed

7 files changed

+174
-0
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./.gitignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ npm-debug.log
1919
yarn-error.log
2020
testem.log
2121
.env
22+
docker-compose.override.yml

backend.Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM rust:1.20-stretch
2+
3+
RUN apt-get update \
4+
&& apt-get install -y postgresql cmake \
5+
&& rm -rf /var/lib/apt/lists/* \
6+
&& cargo install diesel_cli --no-default-features --features postgres
7+
8+
WORKDIR /app
9+
COPY . /app
10+
11+
ENTRYPOINT ["/app/docker_entrypoint.sh"]

docker-compose.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
version: "3"
2+
services:
3+
postgres:
4+
image: postgres:9.6
5+
environment:
6+
POSTGRES_DB: cargo_registry
7+
POSTRES_USER: postgres
8+
POSTGRES_PASSWORD: password
9+
ports:
10+
- 5432:5432
11+
volumes:
12+
- postgres-data:/var/lib/postgresql/data
13+
backend:
14+
build:
15+
context: .
16+
dockerfile: backend.Dockerfile
17+
environment:
18+
DATABASE_URL: postgres://postgres:password@postgres/cargo_registry
19+
SESSION_KEY: badkeyabcdefghijklmnopqrstuvwxyzabcdef
20+
GIT_REPO_URL: file://./tmp/index-bare
21+
GIT_REPO_CHECKOUT: ./tmp/index-co
22+
GH_CLIENT_ID: ""
23+
GH_CLIENT_SECRET: ""
24+
links:
25+
- postgres
26+
ports:
27+
- 8888:8888
28+
volumes:
29+
# Mount the src/ directory so we don't have to rebuild the Docker image
30+
# when we want to change some code
31+
- ./src:/app/src:ro
32+
33+
- index:/app/tmp
34+
- cargo-cache:/usr/local/cargo/registry
35+
- target-cache:/app/target
36+
frontend:
37+
build:
38+
context: .
39+
dockerfile: frontend.Dockerfile
40+
entrypoint: yarn run start --proxy http://backend:8888
41+
links:
42+
- backend
43+
ports:
44+
- 4200:4200
45+
volumes:
46+
# Mount the app/ directory so live reload works
47+
- ./app:/app/app:ro
48+
49+
volumes:
50+
postgres-data:
51+
cargo-cache:
52+
target-cache:
53+
index:

docker_entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
# If the backend is started before postgres is ready, the migrations will fail
4+
until diesel migration run; do
5+
echo "Migrations failed, retrying in 5 seconds..."
6+
sleep 5
7+
done
8+
9+
./script/init-local-index.sh
10+
11+
cargo run --bin server

docs/CONTRIBUTING.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,90 @@ this crate's `Cargo.toml`, and `cargo build` should display output like this:
472472
Compiling thiscrate v0.1.0 (file:///path/to/thiscrate)
473473
Finished dev [unoptimized + debuginfo] target(s) in 0.56 secs
474474
```
475+
476+
### Running crates.io with Docker
477+
478+
There are Dockerfiles to build both the backend and the frontend,
479+
(`backend.Dockerfile` and `frontend.Dockerfile`) respectively, but it is most
480+
useful to just use docker-compose to bring up everything that's needed all in
481+
one go:
482+
483+
```
484+
docker-compose up -d
485+
```
486+
487+
The Compose file is filled out with a sane set of defaults that should Just
488+
Work™ out of the box without any modification. Individual settings can be
489+
overridden by creating a `docker-compose.override.yml` with the updated config.
490+
For example, in order to specify a set of Github OAuth Client credentials, a
491+
`docker-compose.override.yml` file might look like this:
492+
493+
```yaml
494+
version: "3"
495+
services:
496+
backend:
497+
environment:
498+
GH_CLIENT_ID: blahblah_ID
499+
GH_CLIENT_SECRET: blahblah_secret
500+
```
501+
502+
#### Accessing services
503+
504+
By default, the services will be exposed on their normal ports:
505+
506+
* `5432` for Postgres
507+
* `8888` for the crates.io backend
508+
* `4200` for the crates.io frontend
509+
510+
These can be changed with the `docker-compose.override.yml` file.
511+
512+
#### Publishing crates
513+
514+
Unlike a local setup, the Git index is not stored in the `./tmp` folder, so in
515+
order to publish to the Dockerized crates.io, run
516+
517+
```
518+
cargo publish --index http://localhost:4200/git/index
519+
```
520+
521+
#### Changing code
522+
523+
The `app/` directory is mounted directly into the frontend Docker container,
524+
which means that the Ember live-reload server will still just work. If
525+
anything outside of `app/` is changed, the base Docker image will have to be
526+
rebuilt:
527+
528+
```sh
529+
# Rebuild frontend Docker image
530+
docker-compose build frontend
531+
532+
# Restart running frontend container (if it's already running)
533+
docker-compose stop frontend
534+
docker-compose rm frontend
535+
docker-compose up -d
536+
```
537+
538+
Similarly, the `src/` directory is mounted into the backend Docker container,
539+
so in order to recompile the backend, run:
540+
541+
```
542+
docker-compose restart backend
543+
```
544+
545+
If anything outside of `src/` is changed, the base Docker image will have to be
546+
rebuilt:
547+
548+
```sh
549+
# Rebuild backend Docker image
550+
docker-compose build backend
551+
552+
# Restart running backend container (if it's already running)
553+
docker-compose stop backend
554+
docker-compose rm backend
555+
docker-compose up -d
556+
```
557+
558+
#### Volumes
559+
560+
A number of names volumes are created, as can be seen in the `volumes` section
561+
of the `docker-compose.yml` file.

frontend.Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:8.6-alpine
2+
3+
WORKDIR /app
4+
COPY package.json /app
5+
6+
RUN yarn install
7+
8+
COPY . /app
9+
10+
ENTRYPOINT ["yarn", "run", "start:staging"]

0 commit comments

Comments
 (0)