Skip to content

Commit 16d4957

Browse files
committed
Run gui tests solely inside docker-compose
1 parent fb26bf8 commit 16d4957

File tree

5 files changed

+102
-71
lines changed

5 files changed

+102
-71
lines changed

Diff for: docker-compose.yml

+34-4
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,43 @@ services:
9090
timeout: 5s
9191
retries: 10
9292

93-
gui_tests:
93+
gui-tests-web:
94+
build:
95+
context: .
96+
dockerfile: ./dockerfiles/Dockerfile
97+
platform: "linux/amd64"
98+
depends_on:
99+
- db
100+
- s3
101+
volumes:
102+
- "/var/run/docker.sock:/var/run/docker.sock"
103+
- "./ignored/rustwide-gui-tests-docker:/opt/docsrs/rustwide"
104+
- "cratesio-index:/opt/docsrs/prefix/crates.io-index"
105+
environment:
106+
DOCSRS_PREFIX: /opt/docsrs/prefix
107+
DOCSRS_DOCKER: true
108+
DOCSRS_DOCKER_SKIP_INIT: true
109+
DOCSRS_RUSTWIDE_WORKSPACE: /opt/docsrs/rustwide
110+
DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@db/gui-tests
111+
DOCSRS_STORAGE_BACKEND: s3
112+
DOCSRS_S3_BUCKET: "gui-tests"
113+
S3_ENDPOINT: http://s3:9000
114+
AWS_ACCESS_KEY_ID: cratesfyi
115+
AWS_SECRET_ACCESS_KEY: secret_key
116+
env_file:
117+
- .env
118+
healthcheck:
119+
test: ["CMD", "curl", "--silent", "--fail", "localhost:3000"]
120+
interval: 1s
121+
timeout: 1s
122+
retries: 10
123+
124+
gui-tests:
94125
build:
95126
context: .
96127
dockerfile: ./dockerfiles/Dockerfile-gui-tests
97-
network_mode: "host"
98-
extra_hosts:
99-
- "host.docker.internal:host-gateway"
128+
environment:
129+
SERVER_URL: http://gui-tests-web:3000
100130
volumes:
101131
- "${PWD}:/build/out"
102132

Diff for: dockerfiles/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
9191
build-essential \
9292
gcc \
9393
pkg-config \
94+
curl \
9495
libssl-dev
9596

9697
RUN mkdir -p /opt/docsrs/prefix

Diff for: dockerfiles/Dockerfile-gui-tests

+2-4
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,13 @@ ENV NODE_PATH="/node-v14.4.0-linux-x64/lib/node_modules/"
6767

6868
WORKDIR /build
6969

70-
RUN mkdir out
71-
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:
7472
# https://github.com/puppeteer/puppeteer/issues/375
7573
#
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 /build/gui-tests
8078

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

Diff for: dockerfiles/entrypoint.sh

+27-25
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,34 @@ export DOCSRS_DOCKER=true
77
export DOCSRS_LOG=${DOCSRS_LOG-"docs-rs,rustwide=info"}
88
export PATH="$PATH:/build/target/release"
99

10-
# Try migrating the database multiple times if it fails
11-
# This avoids the docker container crashing the first time it's started with
12-
# docker-compose, as PostgreSQL needs some time to initialize.
13-
set +e
14-
failed=0
15-
while true; do
16-
if ! cratesfyi database migrate; then
17-
((failed=failed + 1))
18-
if [ "${failed}" -eq 5 ]; then
19-
exit 1
20-
fi
21-
echo "failed to migrate the database"
22-
echo "waiting 1 second..."
23-
sleep 1
24-
else
25-
break
26-
fi
27-
done
28-
set -e
10+
if ! [ -n "$DOCSRS_DOCKER_SKIP_INIT" ]; then
11+
# Try migrating the database multiple times if it fails
12+
# This avoids the docker container crashing the first time it's started with
13+
# docker-compose, as PostgreSQL needs some time to initialize.
14+
set +e
15+
failed=0
16+
while true; do
17+
if ! cratesfyi database migrate; then
18+
((failed=failed + 1))
19+
if [ "${failed}" -eq 5 ]; then
20+
exit 1
21+
fi
22+
echo "failed to migrate the database"
23+
echo "waiting 1 second..."
24+
sleep 1
25+
else
26+
break
27+
fi
28+
done
29+
set -e
2930

30-
if ! [ -d "${DOCSRS_PREFIX}/crates.io-index/.git" ]; then
31-
git clone ${REGISTRY_URL:-https://github.com/rust-lang/crates.io-index} "${DOCSRS_PREFIX}/crates.io-index"
32-
# Prevent new crates built before the container creation to be built
33-
git --git-dir="$DOCSRS_PREFIX/crates.io-index/.git" branch crates-index-diff_last-seen
34-
fi
31+
if ! [ -d "${DOCSRS_PREFIX}/crates.io-index/.git" ]; then
32+
git clone ${REGISTRY_URL:-https://github.com/rust-lang/crates.io-index} "${DOCSRS_PREFIX}/crates.io-index"
33+
# Prevent new crates built before the container creation to be built
34+
git --git-dir="$DOCSRS_PREFIX/crates.io-index/.git" branch crates-index-diff_last-seen
35+
fi
3536

36-
cratesfyi build update-toolchain --only-first-time
37+
cratesfyi build update-toolchain --only-first-time
38+
fi
3739

3840
cratesfyi "$@"

Diff for: dockerfiles/run-gui-tests.sh

+38-38
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
#!/usr/bin/env bash
22

3-
set -e
4-
5-
# Just in case it's running, we stop the web server.
6-
docker-compose stop web
7-
8-
docker-compose up -d db s3
9-
10-
# If we have a .env file, we need to temporarily move it so
11-
# it doesn't make sqlx fail compilation.
12-
if [ -f .env ]; then
13-
mv .env .tmp.env
14-
fi
15-
16-
# We add the information we need.
17-
cargo run -- database migrate
18-
cargo run -- build update-toolchain
19-
cargo run -- build crate sysinfo 0.23.4
20-
cargo run -- build crate sysinfo 0.23.5
21-
cargo run -- build add-essential-files
22-
23-
if [ -f .tmp.env ]; then
24-
mv .tmp.env .env
25-
fi
26-
27-
# In case we don't have a `.env`, we create one.
28-
if [ ! -f .env ]; then
29-
cp .env.sample .env
30-
fi
31-
32-
. .env
33-
34-
cargo run -- start-web-server &
35-
SERVER_PID=$!
36-
37-
# status="docker run . -v `pwd`:/build/out:ro gui_tests"
38-
docker-compose run gui_tests
39-
status=$?
40-
exit $status
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+
# Pre-build the images for the web server and test containers
15+
run docker compose build gui-tests-web gui-tests
16+
17+
# Stop any leftover server from prior runs
18+
run docker compose stop gui-tests-web
19+
20+
# Ensure the database and S3 are running
21+
run docker compose up --wait --wait-timeout 10 db s3
22+
23+
# Wipe the database and S3 storage
24+
run docker compose exec db dropdb --user cratesfyi gui-tests
25+
run docker compose exec db createdb --user cratesfyi gui-tests
26+
run docker compose exec s3 rm -rf /data/gui-tests
27+
run docker compose exec s3 mkdir -p /data/gui-tests
28+
29+
# Add the information we need
30+
run docker compose run --rm gui-tests-web database migrate
31+
run docker compose run --rm gui-tests-web build update-toolchain
32+
run docker compose run --rm gui-tests-web build crate sysinfo 0.23.4
33+
run docker compose run --rm gui-tests-web build crate sysinfo 0.23.5
34+
35+
# Start the web server up
36+
run docker compose up --wait --wait-timeout 10 gui-tests-web
37+
trap 'run docker compose stop gui-tests-web' EXIT
38+
39+
# Run the tests
40+
run docker compose run gui-tests

0 commit comments

Comments
 (0)