Skip to content

Commit c8f8d43

Browse files
committed
Run separate web server, registry watcher and build servers in docker-compose
1 parent 2fd03ee commit c8f8d43

File tree

3 files changed

+149
-12
lines changed

3 files changed

+149
-12
lines changed

docker-compose.yml

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,85 @@ services:
44
build:
55
context: .
66
dockerfile: ./dockerfiles/Dockerfile
7+
target: web-server
78
platform: "linux/amd64"
89
depends_on:
910
- db
1011
- s3
1112
ports:
12-
- "3000:3000"
13-
# for metrics
14-
expose: ["3000"]
13+
- "3000:80"
14+
env_file:
15+
- docker.env
16+
- .env
17+
healthcheck:
18+
test: ["CMD", "curl", "--silent", "--fail", "localhost:80"]
19+
interval: 10s
20+
timeout: 5s
21+
retries: 10
22+
23+
registry-watcher:
24+
build:
25+
context: .
26+
dockerfile: ./dockerfiles/Dockerfile
27+
target: registry-watcher
28+
platform: "linux/amd64"
29+
depends_on:
30+
- db
1531
volumes:
16-
- "/var/run/docker.sock:/var/run/docker.sock"
17-
- ".rustwide-docker:/opt/docsrs/rustwide"
1832
- "cratesio-index:/opt/docsrs/prefix/crates.io-index"
19-
environment:
20-
DOCSRS_RUSTWIDE_WORKSPACE: /opt/docsrs/rustwide
21-
DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@db
22-
DOCSRS_STORAGE_BACKEND: s3
23-
S3_ENDPOINT: http://s3:9000
24-
AWS_ACCESS_KEY_ID: cratesfyi
25-
AWS_SECRET_ACCESS_KEY: secret_key
2633
env_file:
34+
- docker.env
2735
- .env
2836
healthcheck:
2937
test: ["CMD", "curl", "--silent", "--fail", "localhost:3000"]
3038
interval: 10s
3139
timeout: 5s
3240
retries: 10
3341

42+
builder-a:
43+
build:
44+
context: .
45+
dockerfile: ./dockerfiles/Dockerfile
46+
target: build-server
47+
depends_on:
48+
- db
49+
- s3
50+
volumes:
51+
- ".rustwide-docker/a:/opt/docsrs/rustwide"
52+
- "/var/run/docker.sock:/var/run/docker.sock"
53+
env_file:
54+
- docker.env
55+
- .env
56+
57+
builder-b:
58+
build:
59+
context: .
60+
dockerfile: ./dockerfiles/Dockerfile
61+
target: build-server
62+
depends_on:
63+
- db
64+
- s3
65+
volumes:
66+
- ".rustwide-docker/b:/opt/docsrs/rustwide"
67+
- "/var/run/docker.sock:/var/run/docker.sock"
68+
env_file:
69+
- docker.env
70+
- .env
71+
72+
cli:
73+
build:
74+
context: .
75+
dockerfile: ./dockerfiles/Dockerfile
76+
target: cli
77+
depends_on:
78+
- db
79+
- s3
80+
volumes:
81+
- "cratesio-index:/opt/docsrs/prefix/crates.io-index"
82+
env_file:
83+
- docker.env
84+
- .env
85+
3486
db:
3587
build:
3688
context: ./dockerfiles

docker.env

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# general environment variables shared between all docker compose services
2+
# you can override these in a .env file if needed
3+
4+
export RUST_BACKTRACE=true
5+
6+
export DOCSRS_PREFIX=/opt/docsrs/prefix
7+
8+
export DOCSRS_DATABASE_URL=postgresql://cratesfyi:password@db
9+
export DOCSRS_MIN_POOL_SIZE=2
10+
export DOCSRS_MAX_POOL_SIZE=10
11+
12+
export DOCSRS_STORAGE_BACKEND=s3
13+
14+
export S3_ENDPOINT=http://s3:9000
15+
export AWS_ACCESS_KEY_ID=cratesfyi
16+
export AWS_SECRET_ACCESS_KEY=secret_key
17+
18+
export DOCSRS_RENDER_THREADS=2
19+
20+
export DOCSRS_RUSTWIDE_WORKSPACE=/opt/docsrs/rustwide
21+
export DOCSRS_DOCKER=true
22+
export DOCSRS_DOCKER_IMAGE=ghcr.io/rust-lang/crates-build-env/linux-micro
23+
export DOCSRS_BUILD_CPU_LIMIT=2
24+
export DOCSRS_INCLUDE_DEFAULT_TARGETS=false

dockerfiles/Dockerfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,67 @@ WORKDIR /srv/docsrs
7777
# Tini is a small init binary to properly handle signals
7878
CMD ["/usr/bin/tini", "/usr/local/bin/cratesfyi", "start-web-server", "0.0.0.0:80"]
7979

80+
########################
81+
# Build server stage #
82+
########################
83+
84+
FROM ubuntu:22.04 AS build-server
85+
86+
RUN apt-get update \
87+
&& DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \
88+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
89+
ca-certificates \
90+
tini \
91+
docker.io \
92+
build-essential \
93+
gcc \
94+
pkg-config \
95+
libssl-dev \
96+
&& rm -rf /var/lib/apt/lists/*
97+
98+
COPY --from=build /build/target/release/cratesfyi /usr/local/bin
99+
100+
WORKDIR /srv/docsrs
101+
# Tini is a small init binary to properly handle signals
102+
CMD ["/usr/bin/tini", "/usr/local/bin/cratesfyi", "start-build-server"]
103+
104+
############################
105+
# Registry watcher stage #
106+
############################
107+
108+
FROM ubuntu:22.04 AS registry-watcher
109+
110+
RUN apt-get update \
111+
&& DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \
112+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
113+
ca-certificates \
114+
tini \
115+
git \
116+
&& rm -rf /var/lib/apt/lists/*
117+
118+
COPY --from=build /build/target/release/cratesfyi /usr/local/bin
119+
120+
WORKDIR /srv/docsrs
121+
# Tini is a small init binary to properly handle signals
122+
CMD ["/usr/bin/tini", "/usr/local/bin/cratesfyi", "--", "start-registry-watcher", "--repository-stats-updater=enabled", "--cdn-invalidator=enabled"]
123+
124+
###############
125+
# CLI stage #
126+
###############
127+
128+
FROM ubuntu:22.04 AS cli
129+
130+
RUN apt-get update \
131+
&& DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \
132+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
133+
ca-certificates \
134+
tini \
135+
&& rm -rf /var/lib/apt/lists/*
136+
137+
COPY --from=build /build/target/release/cratesfyi /usr/local/bin
138+
139+
ENTRYPOINT ["/usr/local/bin/cratesfyi"]
140+
80141
##################
81142
# Output stage #
82143
##################

0 commit comments

Comments
 (0)