Skip to content

Commit 2432259

Browse files
committed
Run separate web server, registry watcher and build servers in docker-compose
1 parent 7de76c9 commit 2432259

File tree

2 files changed

+133
-8
lines changed

2 files changed

+133
-8
lines changed

docker-compose.yml

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,98 @@ 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"]
15-
volumes:
16-
- "/var/run/docker.sock:/var/run/docker.sock"
17-
- ".rustwide-docker:/opt/docsrs/rustwide"
18-
- "cratesio-index:/opt/docsrs/prefix/crates.io-index"
13+
- "3000:80"
1914
environment:
20-
DOCSRS_RUSTWIDE_WORKSPACE: /opt/docsrs/rustwide
15+
DOCSRS_PREFIX: /opt/docsrs/prefix
2116
DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@db
2217
DOCSRS_STORAGE_BACKEND: s3
2318
S3_ENDPOINT: http://s3:9000
2419
AWS_ACCESS_KEY_ID: cratesfyi
2520
AWS_SECRET_ACCESS_KEY: secret_key
2621
env_file:
2722
- .env
23+
healthcheck:
24+
test: ["CMD", "curl", "--silent", "--fail", "localhost:80"]
25+
interval: 10s
26+
timeout: 5s
27+
retries: 10
28+
29+
registry-watcher:
30+
build:
31+
context: .
32+
dockerfile: ./dockerfiles/Dockerfile
33+
target: registry-watcher
34+
platform: "linux/amd64"
35+
depends_on:
36+
- db
37+
volumes:
38+
- "cratesio-index:/opt/docsrs/prefix/crates.io-index"
39+
environment:
40+
DOCSRS_PREFIX: /opt/docsrs/prefix
41+
DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@db
42+
env_file:
43+
- .env
2844
healthcheck:
2945
test: ["CMD", "curl", "--silent", "--fail", "localhost:3000"]
3046
interval: 10s
3147
timeout: 5s
3248
retries: 10
3349

50+
builder:
51+
build:
52+
context: .
53+
dockerfile: ./dockerfiles/Dockerfile
54+
target: build-server
55+
depends_on:
56+
- db
57+
- s3
58+
volumes:
59+
- "/var/run/docker.sock:/var/run/docker.sock"
60+
- "cratesio-index:/opt/docsrs/prefix/crates.io-index"
61+
environment:
62+
RUST_BACKTRACE: true
63+
DOCSRS_PREFIX: /opt/docsrs/prefix
64+
DOCSRS_RUSTWIDE_WORKSPACE: /opt/docsrs/rustwide
65+
DOCSRS_DOCKER: true
66+
DOCSRS_DOCKER_IMAGE: ghcr.io/rust-lang/crates-build-env/linux-micro
67+
DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@db
68+
DOCSRS_STORAGE_BACKEND: s3
69+
S3_ENDPOINT: http://s3:9000
70+
AWS_ACCESS_KEY_ID: cratesfyi
71+
AWS_SECRET_ACCESS_KEY: secret_key
72+
env_file:
73+
- .env
74+
deploy:
75+
replicas: 2
76+
77+
cli:
78+
build:
79+
context: .
80+
dockerfile: ./dockerfiles/Dockerfile
81+
target: cli
82+
depends_on:
83+
- db
84+
- s3
85+
volumes:
86+
- "cratesio-index:/opt/docsrs/prefix/crates.io-index"
87+
environment:
88+
DOCSRS_PREFIX: /opt/docsrs/prefix
89+
DOCSRS_RUSTWIDE_WORKSPACE: /opt/docsrs/rustwide
90+
DOCSRS_DOCKER: true
91+
DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@db
92+
DOCSRS_STORAGE_BACKEND: s3
93+
S3_ENDPOINT: http://s3:9000
94+
AWS_ACCESS_KEY_ID: cratesfyi
95+
AWS_SECRET_ACCESS_KEY: secret_key
96+
env_file:
97+
- .env
98+
3499
db:
35100
build:
36101
context: ./dockerfiles

dockerfiles/Dockerfile

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

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

0 commit comments

Comments
 (0)