Skip to content

Commit

Permalink
Change gui-tests script to run all steps inside docker containers
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Nov 24, 2023
1 parent 0366ef5 commit 22c01b3
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 69 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,11 @@ jobs:
needs: build
steps:
- uses: actions/checkout@v4
- id: install
run: |
rustup override set stable
rustup update stable
- name: restore build & cargo cache
uses: Swatinem/rust-cache@v2

- name: Launch postgres and min.io
- name: Run GUI tests
run: |
touch .docker.env
docker compose up --wait --wait-timeout 30 db s3
- name: Run GUI tests
run: ./dockerfiles/run-gui-tests.sh
gui-tests/in-docker
build_tests:
runs-on: ubuntu-latest
Expand Down
58 changes: 46 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ x-environment: &environment
DOCSRS_BUILD_CPU_LIMIT: 2
DOCSRS_INCLUDE_DEFAULT_TARGETS: false

x-gui-tests-environment: &gui-tests-environment
<< : *environment
DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@db/gui-tests
DOCSRS_S3_BUCKET: gui-tests

x-builder: &builder
build:
context: .
Expand All @@ -47,7 +52,7 @@ x-builder: &builder
test: curl --silent --fail localhost:3000/about/metrics

services:
web:
web: &web
build:
context: .
dockerfile: ./dockerfiles/Dockerfile
Expand Down Expand Up @@ -98,7 +103,7 @@ services:
- ".rustwide-docker/builder-b:/opt/docsrs/rustwide"
- "/var/run/docker.sock:/var/run/docker.sock"

cli:
cli: &cli
build:
context: .
dockerfile: ./dockerfiles/Dockerfile
Expand Down Expand Up @@ -134,8 +139,16 @@ services:
image: minio/minio
entrypoint: >
/bin/sh -c "
mkdir -p /data/rust-docs-rs;
minio server /data --console-address ":9001";
set -meu
mc alias rm s3 || true
mc alias rm gcs || true
mc alias rm local || true
mc alias rm play || true
minio server /data --console-address ":9001" &
sleep 1
mc alias set local http://s3:9000 cratesfyi secret_key
mc mb --ignore-existing s3/rust-docs-rs
fg
"
ports:
- "127.0.0.1:9000:9000"
Expand All @@ -159,15 +172,36 @@ services:
<< : *healthcheck-interval
test: promtool check healthy

gui_tests:
build:
context: .
dockerfile: ./dockerfiles/Dockerfile-gui-tests
network_mode: "host"
extra_hosts:
- "host.docker.internal:host-gateway"
gui-tests-cli:
<< : *cli
environment: *gui-tests-environment
profiles:
- all

gui-tests-builder:
<< : *builder
environment: *gui-tests-environment
volumes:
- "${PWD}:/build/out"
- ".rustwide-docker/builder-gui-tests:/opt/docsrs/rustwide"
- "/var/run/docker.sock:/var/run/docker.sock"
profiles:
- all

gui-tests-web:
<< : *web
ports:
- "3001:80"
environment: *gui-tests-environment
profiles:
- all

gui-tests:
build:
context: gui-tests
depends_on:
- gui-tests-web
environment:
SERVER_URL: http://gui-tests-web
profiles:
- all

Expand Down
40 changes: 0 additions & 40 deletions dockerfiles/run-gui-tests.sh

This file was deleted.

8 changes: 3 additions & 5 deletions dockerfiles/Dockerfile-gui-tests → gui-tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ RUN curl -sL https://nodejs.org/dist/v14.4.0/node-v14.4.0-linux-x64.tar.xz | tar
ENV PATH="/node-v14.4.0-linux-x64/bin:${PATH}"
ENV NODE_PATH="/node-v14.4.0-linux-x64/lib/node_modules/"

WORKDIR /build

RUN mkdir out
WORKDIR /gui-tests

# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
# to create a new folder. For reference:
Expand All @@ -76,6 +74,6 @@ RUN mkdir out
# We also specify the version in case we need to update it to go around cache limitations.
RUN npm install -g browser-ui-test@0.16.10 --unsafe-perm=true

EXPOSE 3000
COPY . /gui-tests

CMD ["node", "/build/out/gui-tests/tester.js"]
CMD ["node", "tester.js"]
57 changes: 57 additions & 0 deletions gui-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Running gui-tests in docker

The easiest way to run the gui-tests in a stable environment setup as they
expect is by spinning up a temporary web service with the correct data in
docker.

This is supported by the `in-docker` script. It has three phases that can be
run, to allow quicker feedback when editing the gui-tests themselves.

```console
# initialize a temporary database and web service and builds some crates in it
> gui-tests/in-docker init
...
✔ Container docsrs-db-1 Healthy
✔ Container docsrs-s3-1 Healthy
✔ Container docsrs-gui-tests-web-1 Healthy

# while you have changes to make
# do
# edit your tests
> vim gui-tests/basic.goml

# run the tests against the temporary web service
> gui-tests/in-docker run
...
Running 2 docs.rs GUI (2 concurrently) ...
.. (2/2)
# done

# tear down the temporary database and web service
> gui-tests/in-docker cleanup
...
Removed `local/gui-tests` successfully.
```

Running with `all` or without an argument will run all steps in sequence,
skipping the cleanup if it fails so you can inspect the failure. Useful if
you've done some other changes and want to run the gui-tests but aren't
expecting them to fail.

If you are changing the web service or doc builder, take a look in the script at
the steps that `init` takes, you can likely run just one of these steps manually
within your edit-test loop rather than having to fully reinit the setup
(remember to use `--build` to ensure docker-compose rebuilds the image from your
updated source).

```console
# e.g. after editing the doc builder
docker compose run --build --rm gui-tests-builder build crate sysinfo 0.23.4
docker compose run --build --rm gui-tests-builder build crate sysinfo 0.23.5

# or after editing the web service
docker compose up --build --wait --wait-timeout 10 gui-tests-web
```

The web service is also bound onto `localhost:3001` so that you can manually
inspect the pages if necessary.
69 changes: 69 additions & 0 deletions gui-tests/in-docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash

set -euo pipefail

run() {
cmd="$1"
shift
printf ' \e[36;1mRunning\e[0m `%q' "$cmd" >&2
printf ' %q' "$@" >&2
printf '`\n' >&2
"$cmd" "$@"
}

cleanup() {
run docker compose rm --stop --volumes --force gui-tests-web

run docker compose up --wait --wait-timeout 10 db s3

run docker compose exec db dropdb --user cratesfyi gui-tests || true
run docker compose exec s3 mc rb --force local/gui-tests || true
}

init() {
run docker compose up --wait --wait-timeout 10 db s3

run docker compose exec db createdb --user cratesfyi gui-tests
run docker compose exec s3 mc mb local/gui-tests

# Pre-build the images needed
run docker compose build gui-tests-cli gui-tests-builder gui-tests-web

# Add the information we need
run docker compose run --rm gui-tests-cli database migrate
run docker compose run --rm gui-tests-builder build update-toolchain
run docker compose run --rm gui-tests-builder build crate sysinfo 0.23.4
run docker compose run --rm gui-tests-builder build crate sysinfo 0.23.5

# Start the web server up
run docker compose up --wait --wait-timeout 10 gui-tests-web
}

execute() {
run docker compose build gui-tests
run docker compose run --rm gui-tests
}

case "${1:-all}"
in
cleanup)
cleanup
;;
init)
cleanup
init
;;
run)
execute
;;
all)
cleanup
init
execute
cleanup
;;
*)
echo 'unknown command `'"$1"'`, expected one of [init, run, cleanup, all]' >&2
exit 1
;;
esac

0 comments on commit 22c01b3

Please sign in to comment.