Skip to content

Commit 3f4cfcf

Browse files
committed
Change gui-tests script to run all steps inside docker containers
1 parent 0366ef5 commit 3f4cfcf

File tree

6 files changed

+177
-69
lines changed

6 files changed

+177
-69
lines changed

.github/workflows/ci.yml

+2-12
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,11 @@ jobs:
119119
needs: build
120120
steps:
121121
- uses: actions/checkout@v4
122-
- id: install
123-
run: |
124-
rustup override set stable
125-
rustup update stable
126-
127-
- name: restore build & cargo cache
128-
uses: Swatinem/rust-cache@v2
129122

130-
- name: Launch postgres and min.io
123+
- name: Run GUI tests
131124
run: |
132125
touch .docker.env
133-
docker compose up --wait --wait-timeout 30 db s3
134-
135-
- name: Run GUI tests
136-
run: ./dockerfiles/run-gui-tests.sh
126+
gui-tests/in-docker
137127
138128
build_tests:
139129
runs-on: ubuntu-latest

docker-compose.yml

+46-12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ x-environment: &environment
3131
DOCSRS_BUILD_CPU_LIMIT: 2
3232
DOCSRS_INCLUDE_DEFAULT_TARGETS: false
3333

34+
x-gui-tests-environment: &gui-tests-environment
35+
<< : *environment
36+
DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@db/gui-tests
37+
DOCSRS_S3_BUCKET: gui-tests
38+
3439
x-builder: &builder
3540
build:
3641
context: .
@@ -47,7 +52,7 @@ x-builder: &builder
4752
test: curl --silent --fail localhost:3000/about/metrics
4853

4954
services:
50-
web:
55+
web: &web
5156
build:
5257
context: .
5358
dockerfile: ./dockerfiles/Dockerfile
@@ -98,7 +103,7 @@ services:
98103
- ".rustwide-docker/builder-b:/opt/docsrs/rustwide"
99104
- "/var/run/docker.sock:/var/run/docker.sock"
100105

101-
cli:
106+
cli: &cli
102107
build:
103108
context: .
104109
dockerfile: ./dockerfiles/Dockerfile
@@ -134,8 +139,16 @@ services:
134139
image: minio/minio
135140
entrypoint: >
136141
/bin/sh -c "
137-
mkdir -p /data/rust-docs-rs;
138-
minio server /data --console-address ":9001";
142+
set -meu
143+
mc alias rm s3 || true
144+
mc alias rm gcs || true
145+
mc alias rm local || true
146+
mc alias rm play || true
147+
minio server /data --console-address ":9001" &
148+
sleep 1
149+
mc alias set local http://s3:9000 cratesfyi secret_key
150+
mc mb --ignore-existing s3/rust-docs-rs
151+
fg
139152
"
140153
ports:
141154
- "127.0.0.1:9000:9000"
@@ -159,15 +172,36 @@ services:
159172
<< : *healthcheck-interval
160173
test: promtool check healthy
161174

162-
gui_tests:
163-
build:
164-
context: .
165-
dockerfile: ./dockerfiles/Dockerfile-gui-tests
166-
network_mode: "host"
167-
extra_hosts:
168-
- "host.docker.internal:host-gateway"
175+
gui-tests-cli:
176+
<< : *cli
177+
environment: *gui-tests-environment
178+
profiles:
179+
- all
180+
181+
gui-tests-builder:
182+
<< : *builder
183+
environment: *gui-tests-environment
169184
volumes:
170-
- "${PWD}:/build/out"
185+
- ".rustwide-docker/builder-gui-tests:/opt/docsrs/rustwide"
186+
- "/var/run/docker.sock:/var/run/docker.sock"
187+
profiles:
188+
- all
189+
190+
gui-tests-web:
191+
<< : *web
192+
ports:
193+
- "3001:80"
194+
environment: *gui-tests-environment
195+
profiles:
196+
- all
197+
198+
gui-tests:
199+
build:
200+
context: gui-tests
201+
depends_on:
202+
- gui-tests-web
203+
environment:
204+
SERVER_URL: http://gui-tests-web
171205
profiles:
172206
- all
173207

dockerfiles/run-gui-tests.sh

-40
This file was deleted.

dockerfiles/Dockerfile-gui-tests gui-tests/Dockerfile

+3-5
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ RUN curl -sL https://nodejs.org/dist/v14.4.0/node-v14.4.0-linux-x64.tar.xz | tar
6565
ENV PATH="/node-v14.4.0-linux-x64/bin:${PATH}"
6666
ENV NODE_PATH="/node-v14.4.0-linux-x64/lib/node_modules/"
6767

68-
WORKDIR /build
69-
70-
RUN mkdir out
68+
WORKDIR /gui-tests
7169

7270
# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
7371
# to create a new folder. For reference:
@@ -76,6 +74,6 @@ RUN mkdir out
7674
# We also specify the version in case we need to update it to go around cache limitations.
7775
RUN npm install -g [email protected] --unsafe-perm=true
7876

79-
EXPOSE 3000
77+
COPY . /gui-tests
8078

81-
CMD ["node", "/build/out/gui-tests/tester.js"]
79+
CMD ["node", "tester.js"]

gui-tests/README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## Running gui-tests in docker
2+
3+
The easiest way to run the gui-tests in a stable environment setup as they
4+
expect is by spinning up a temporary web service with the correct data in
5+
docker.
6+
7+
This is supported by the `in-docker` script. It has three phases that can be
8+
run, to allow quicker feedback when editing the gui-tests themselves.
9+
10+
```console
11+
# initialize a temporary database and web service and builds some crates in it
12+
> gui-tests/in-docker init
13+
...
14+
✔ Container docsrs-db-1 Healthy
15+
✔ Container docsrs-s3-1 Healthy
16+
✔ Container docsrs-gui-tests-web-1 Healthy
17+
18+
# while you have changes to make
19+
# do
20+
# edit your tests
21+
> vim gui-tests/basic.goml
22+
23+
# run the tests against the temporary web service
24+
> gui-tests/in-docker run
25+
...
26+
Running 2 docs.rs GUI (2 concurrently) ...
27+
.. (2/2)
28+
# done
29+
30+
# tear down the temporary database and web service
31+
> gui-tests/in-docker cleanup
32+
...
33+
Removed `local/gui-tests` successfully.
34+
```
35+
36+
Running with `all` or without an argument will run all steps in sequence,
37+
skipping the cleanup if it fails so you can inspect the failure. Useful if
38+
you've done some other changes and want to run the gui-tests but aren't
39+
expecting them to fail.
40+
41+
If you are changing the web service or doc builder, take a look in the script at
42+
the steps that `init` takes, you can likely run just one of these steps manually
43+
within your edit-test loop rather than having to fully reinit the setup
44+
(remember to use `--build` to ensure docker-compose rebuilds the image from your
45+
updated source).
46+
47+
```console
48+
# e.g. after editing the doc builder
49+
docker compose run --build --rm gui-tests-builder build crate sysinfo 0.23.4
50+
docker compose run --build --rm gui-tests-builder build crate sysinfo 0.23.5
51+
52+
# or after editing the web service
53+
docker compose up --build --wait --wait-timeout 10 gui-tests-web
54+
```
55+
56+
The web service is also bound onto `localhost:3001` so that you can manually
57+
inspect the pages if necessary.

gui-tests/in-docker

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
run() {
6+
cmd="$1"
7+
shift
8+
printf ' \e[36;1mRunning\e[0m `%q' "$cmd" >&2
9+
printf ' %q' "$@" >&2
10+
printf '`\n' >&2
11+
"$cmd" "$@"
12+
}
13+
14+
cleanup() {
15+
run docker compose rm --stop --volumes --force gui-tests-web
16+
17+
run docker compose up --wait --wait-timeout 10 db s3
18+
19+
run docker compose exec db dropdb --user cratesfyi gui-tests || true
20+
run docker compose exec s3 mc rb --force local/gui-tests || true
21+
}
22+
23+
init() {
24+
run docker compose up --wait --wait-timeout 10 db s3
25+
26+
run docker compose exec db createdb --user cratesfyi gui-tests
27+
run docker compose exec s3 mc mb local/gui-tests
28+
29+
# Pre-build the images needed
30+
run docker compose build cli builder-a gui-tests-web
31+
32+
# Add the information we need
33+
run docker compose run --rm gui-tests-cli database migrate
34+
run docker compose run --rm gui-tests-builder build update-toolchain
35+
run docker compose run --rm gui-tests-builder build crate sysinfo 0.23.4
36+
run docker compose run --rm gui-tests-builder build crate sysinfo 0.23.5
37+
38+
# Start the web server up
39+
run docker compose up --wait --wait-timeout 10 gui-tests-web
40+
}
41+
42+
execute() {
43+
run docker compose build gui-tests
44+
run docker compose run --rm gui-tests
45+
}
46+
47+
case "${1:-all}"
48+
in
49+
cleanup)
50+
cleanup
51+
;;
52+
init)
53+
cleanup
54+
init
55+
;;
56+
run)
57+
execute
58+
;;
59+
all)
60+
cleanup
61+
init
62+
execute
63+
cleanup
64+
;;
65+
*)
66+
echo 'unknown command `'"$1"'`, expected one of [init, run, cleanup, all]' >&2
67+
exit 1
68+
;;
69+
esac

0 commit comments

Comments
 (0)