diff --git a/.dockerignore b/.dockerignore index b96afe2a7..29b8ca6ad 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,12 @@ +/target/ /.rustwide /.rustwide-docker +/Justfile +/LICENSE +/README.md +/docker-compose.yml +/docs/ /ignored -**/target +/mcps +/triagebot.toml +/clippy.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5642e4e93..4ba6f7f8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,13 +44,8 @@ jobs: - name: Launch postgres run: | - cp .env.sample .env - mkdir -p ${DOCSRS_PREFIX}/public-html - docker-compose up -d db - # Give the database enough time to start up - sleep 5 - # Make sure the database is actually working - psql "${DOCSRS_DATABASE_URL}" + touch .docker.env + docker compose up --wait --wait-timeout 30 db - name: run database migrations run: cargo run -- database migrate @@ -68,9 +63,6 @@ jobs: --database-url $DOCSRS_DATABASE_URL \ --target-version 0 - - name: Clean up the database - run: docker-compose down --volumes - test: env: SQLX_OFFLINE: 1 @@ -92,13 +84,8 @@ jobs: - name: Launch postgres and min.io run: | - cp .env.sample .env - mkdir -p ${DOCSRS_PREFIX}/public-html - docker-compose up -d db s3 - # Give the database enough time to start up - sleep 5 - # Make sure the database is actually working - psql "${DOCSRS_DATABASE_URL}" + touch .docker.env + docker compose up --wait --wait-timeout 30 db s3 - name: run workspace tests run: | @@ -110,17 +97,10 @@ jobs: run: | cargo test --locked -- --ignored --test-threads=1 - - name: Clean up the database - run: docker-compose down --volumes - GUI_test: runs-on: ubuntu-latest 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 @@ -129,19 +109,14 @@ jobs: - name: Launch postgres and min.io run: | - cp .env.sample .env - mkdir -p ${DOCSRS_PREFIX}/public-html - docker-compose up -d db s3 - # Give the database enough time to start up - sleep 5 - # Make sure the database is actually working - psql "${DOCSRS_DATABASE_URL}" + touch .docker.env + docker compose up --wait --wait-timeout 30 db s3 - name: Run GUI tests - run: ./dockerfiles/run-gui-tests.sh + run: | + touch .docker.env + gui-tests/in-docker - - name: Clean up the database - run: docker-compose down --volumes fmt: name: Rustfmt diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 84ae05b95..1fd4cb261 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -9,5 +9,7 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Build the Docker image - run: docker build -t docs-rs -f dockerfiles/Dockerfile . + - run: docker build --target web-server -f dockerfiles/Dockerfile . + - run: docker build --target build-server -f dockerfiles/Dockerfile . + - run: docker build --target registry-watcher -f dockerfiles/Dockerfile . + - run: docker build --target cli -f dockerfiles/Dockerfile . diff --git a/.gitignore b/.gitignore index 99643b163..9d9ef06ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /ignored /.env +/.docker.env /src/web/badge/Cargo.lock target *.css diff --git a/README.md b/README.md index 4d59dc5e7..7715e74b6 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,7 @@ mkdir -p ignored/cratesfyi-prefix/crates.io-index # Builds the docs.rs binary cargo build # Start the external services. -# It may be `docker compose` in newer versions -docker-compose up -d db s3 +docker compose up --wait db s3 # anything that doesn't run via docker-compose needs the settings defined in # .env. Either via `. ./.env` as below, or via any dotenv shell integration. . ./.env @@ -111,19 +110,37 @@ can take a look at its documentation [here](https://github.com/GuillaumeGomez/br ### Pure docker-compose -If you have trouble with the above commands, consider using `docker-compose up --build`, +If you have trouble with the above commands, consider using `docker compose up --build`, which uses docker-compose for the web server as well. This will not cache dependencies - in particular, you'll have to rebuild all 400 whenever the lockfile changes - but makes sure that you're in a known environment so you should have fewer problems getting started. -You can also use the `web` container to run builds on systems which don't support running builds directly (mostly on Mac OS or Windows): +You'll need to `touch .docker.env` first, this file can have any environment +variable overrides you want to use in docker containers. + +You can also use the `builder-a` container to run builds on systems which don't support running builds directly (mostly on Mac OS or Windows): + ```sh +# update the toolchain +docker compose run --rm builder-a build update-toolchain # run a build for a single crate -docker-compose run web build crate regex 1.3.1 -# or build essential files -docker-compose run web build add-essential-files -# rebuild the web container when you changed code. -docker-compose build web +docker compose run --rm builder-a build crate regex 1.3.1 +# rebuild containers when you changed code. +docker compose up --wait --build +``` + +You can also run other non-build commands like the setup steps above, or queueing crates for the background builders from within the `cli` container: + +```sh +docker compose run --rm cli database migrate +docker compose run --rm cli queue add regex 1.3.1 +``` + +If the command needs the crates.io-index clone then it must be run from within +a `registry-watcher` container: + +```sh +docker compose run --rm registry-watcher queue set-last-seen-reference --head ``` Note that running tests is not supported when using pure docker-compose. @@ -137,22 +154,22 @@ Three services are defined: | name | access | credentials | description | |------|-------------------------------------------------|----------------------------|----------------------------------------| -| web | http://localhost:3000 | N/A | A container running the docs.rs binary | -| db | postgresql://cratesfyi:password@localhost:15432 | - | Postgres database used by web | -| s3 | http://localhost:9000 | `cratesfyi` - `secret_key` | MinIO (simulates AWS S3) used by web | +| web | http://0.0.0.0:3000 | N/A | A container running the docs.rs binary | +| db | postgresql://cratesfyi:password@127.0.0.1:15432 | - | Postgres database used by web | +| s3 | http://127.0.0.1:9000 | `cratesfyi` - `secret_key` | MinIO (simulates AWS S3) used by web | [docker-compose.yml]: ./docker-compose.yml #### Rebuilding Containers -To rebuild the site, run `docker-compose build`. +To rebuild the site, run `docker compose --profile all build`. Note that docker-compose caches the build even if you change the source code, so this will be necessary anytime you make changes. If you want to completely clean up the database, don't forget to remove the volumes too: ```sh -$ docker-compose down --volumes +$ docker compose down --volumes ``` #### FAQ @@ -166,7 +183,7 @@ This is probably because you have `git.autocrlf` set to true, ##### I see the error `/opt/rustwide/cargo-home/bin/cargo: cannot execute binary file: Exec format error` when running builds. -You are most likely not on a Linux platform. Running builds directly is only supported on `x86_64-unknown-linux-gnu`. On other platforms you can use the `docker-compose run web build [...]` workaround described above. +You are most likely not on a Linux platform. Running builds directly is only supported on `x86_64-unknown-linux-gnu`. On other platforms you can use the `docker compose run --rm builder-a build [...]` workaround described above. See [rustwide#41](https://github.com/rust-lang/rustwide/issues/41) for more details about supporting more platforms directly. @@ -194,11 +211,11 @@ cargo run -- start-web-server ```sh # Builds and adds it into database # This is the main command to build and add a documentation into docs.rs. -# For example, `docker-compose run web build crate regex 1.1.6` +# For example, `docker compose run --rm builder-a build crate regex 1.1.6` cargo run -- build crate -# alternatively, via the web container -docker-compose run web build crate +# alternatively, within docker-compose containers +docker compose run --rm builder-a build crate # Builds every crate on crates.io and adds them into database # (beware: this may take months to finish) diff --git a/docker-compose.yml b/docker-compose.yml index ce503de9c..1dd5022cf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,35 +1,121 @@ -version: "3" +version: "3.4" + +x-healthcheck: &healthcheck-interval + interval: 1s + timeout: 1s + start_period: 10s + # TODO: https://github.com/docker/compose/issues/10461 + # interval: 10s + # start_interval: 1s + +x-environment: &environment + RUST_BACKTRACE: true + + DOCSRS_PREFIX: /opt/docsrs/prefix + + DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@db + DOCSRS_MIN_POOL_SIZE: 2 + DOCSRS_MAX_POOL_SIZE: 10 + + DOCSRS_STORAGE_BACKEND: s3 + + S3_ENDPOINT: http://s3:9000 + AWS_ACCESS_KEY_ID: cratesfyi + AWS_SECRET_ACCESS_KEY: secret_key + + DOCSRS_RENDER_THREADS: 2 + + DOCSRS_RUSTWIDE_WORKSPACE: /opt/docsrs/rustwide + DOCSRS_DOCKER: true + DOCSRS_DOCKER_IMAGE: ghcr.io/rust-lang/crates-build-env/linux-micro + 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: . + dockerfile: ./dockerfiles/Dockerfile + target: build-server + depends_on: + - db + - s3 + environment: *environment + env_file: + - .docker.env + healthcheck: + << : *healthcheck-interval + test: curl --silent --fail localhost:3000/about/metrics + services: - web: + web: &web build: context: . dockerfile: ./dockerfiles/Dockerfile + target: web-server platform: "linux/amd64" depends_on: - db - s3 ports: - - "3000:3000" - # for metrics - expose: ["3000"] + - "3000:80" + environment: *environment + env_file: + - .docker.env + healthcheck: + << : *healthcheck-interval + test: curl --silent --fail localhost:80/about/metrics + + # Include the registry watcher with `docker compose --profile watch up --build --wait` + registry-watcher: + build: + context: . + dockerfile: ./dockerfiles/Dockerfile + target: registry-watcher + platform: "linux/amd64" + depends_on: + - db volumes: - - "/var/run/docker.sock:/var/run/docker.sock" - - ".rustwide-docker:/opt/docsrs/rustwide" - "cratesio-index:/opt/docsrs/prefix/crates.io-index" - environment: - DOCSRS_RUSTWIDE_WORKSPACE: /opt/docsrs/rustwide - DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@db - DOCSRS_STORAGE_BACKEND: s3 - S3_ENDPOINT: http://s3:9000 - AWS_ACCESS_KEY_ID: cratesfyi - AWS_SECRET_ACCESS_KEY: secret_key + environment: *environment env_file: - - .env + - .docker.env + profiles: + - watch + - all healthcheck: - test: ["CMD", "curl", "--silent", "--fail", "localhost:3000"] - interval: 10s - timeout: 5s - retries: 10 + << : *healthcheck-interval + test: curl --silent --fail localhost:3000/about/metrics + + builder-a: + << : *builder + volumes: + - ".rustwide-docker/builder-a:/opt/docsrs/rustwide" + - "/var/run/docker.sock:/var/run/docker.sock" + + builder-b: + << : *builder + volumes: + - ".rustwide-docker/builder-b:/opt/docsrs/rustwide" + - "/var/run/docker.sock:/var/run/docker.sock" + + cli: &cli + build: + context: . + dockerfile: ./dockerfiles/Dockerfile + target: cli + depends_on: + - db + - s3 + environment: *environment + env_file: + - .docker.env + profiles: + - all db: build: @@ -42,63 +128,80 @@ services: POSTGRES_PASSWORD: password ports: # Use a non-standard port on the host to avoid conflicting with existing postgres servers - - "15432:5432" + - "127.0.0.1:15432:5432" healthcheck: - test: ["CMD", "pg_isready", "--username", "cratesfyi"] - interval: 10s - timeout: 5s - retries: 10 + << : *healthcheck-interval + test: pg_isready --username cratesfyi s3: 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: - - "9000:9000" - - "9001:9001" + - "127.0.0.1:9000:9000" + - "127.0.0.1:9001:9001" volumes: - minio-data:/data environment: MINIO_ROOT_USER: cratesfyi MINIO_ROOT_PASSWORD: secret_key healthcheck: - test: - [ - "CMD", - "curl", - "--silent", - "--fail", - "localhost:9000/minio/health/ready", - ] - interval: 10s - timeout: 5s - retries: 10 + << : *healthcheck-interval + test: mc ready local prometheus: build: context: ./dockerfiles dockerfile: ./Dockerfile-prometheus ports: - - "9090:9090" + - "127.0.0.1:9090:9090" healthcheck: - test: - ["CMD", "curl", "--silent", "--fail", "localhost:9090/-/ready"] - interval: 10s - timeout: 5s - retries: 10 + << : *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 volumes: postgres-data: {} diff --git a/dockerfiles/Dockerfile b/dockerfiles/Dockerfile index 2ece0578d..c9eb819d4 100644 --- a/dockerfiles/Dockerfile +++ b/dockerfiles/Dockerfile @@ -66,42 +66,80 @@ RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \ && DEBIAN_FRONTEND=noninteractive apt-get install -y \ ca-certificates \ + curl \ tini \ && rm -rf /var/lib/apt/lists/* +WORKDIR /srv/docsrs + +# Tini is a small init binary to properly handle signals +ENTRYPOINT ["/usr/bin/tini", "/usr/local/bin/cratesfyi", "--"] +CMD ["start-web-server", "0.0.0.0:80"] + COPY --from=build /build/target/release/cratesfyi /usr/local/bin COPY static /srv/docsrs/static COPY templates /srv/docsrs/templates COPY vendor /srv/docsrs/vendor -WORKDIR /srv/docsrs +######################## +# Build server stage # +######################## + +FROM ubuntu:22.04 AS build-server + +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + ca-certificates \ + tini \ + curl \ + docker.io \ + build-essential \ + gcc \ + pkg-config \ + libssl-dev \ + && rm -rf /var/lib/apt/lists/* + # Tini is a small init binary to properly handle signals -CMD ["/usr/bin/tini", "/usr/local/bin/cratesfyi", "start-web-server", "0.0.0.0:80"] +ENTRYPOINT ["/usr/bin/tini", "/usr/local/bin/cratesfyi", "--"] +CMD ["start-build-server"] -################## -# Output stage # -################## +COPY --from=build /build/target/release/cratesfyi /usr/local/bin + +############################ +# Registry watcher stage # +############################ -FROM ubuntu:22.04 AS output +FROM ubuntu:22.04 AS registry-watcher -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - git \ - libmagic1 \ - docker.io \ - ca-certificates \ - build-essential \ - gcc \ - pkg-config \ - libssl-dev +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + ca-certificates \ + tini \ + curl \ + git \ + && rm -rf /var/lib/apt/lists/* + +# Tini is a small init binary to properly handle signals +ENTRYPOINT ["/usr/bin/tini", "/usr/local/bin/cratesfyi", "--"] +CMD ["start-registry-watcher", "--repository-stats-updater=enabled", "--cdn-invalidator=enabled"] + +COPY --from=build /build/target/release/cratesfyi /usr/local/bin + +############### +# CLI stage # +############### + +FROM ubuntu:22.04 AS cli + +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + ca-certificates \ + tini \ + && rm -rf /var/lib/apt/lists/* -RUN mkdir -p /opt/docsrs/prefix +ENTRYPOINT ["/usr/bin/tini", "/usr/local/bin/cratesfyi", "--"] COPY --from=build /build/target/release/cratesfyi /usr/local/bin -COPY static /opt/docsrs/static -COPY templates /opt/docsrs/templates -COPY dockerfiles/entrypoint.sh /opt/docsrs/ -COPY vendor /opt/docsrs/vendor - -WORKDIR /opt/docsrs -ENTRYPOINT ["/opt/docsrs/entrypoint.sh"] -CMD ["daemon", "--registry-watcher=disabled"] diff --git a/dockerfiles/entrypoint.sh b/dockerfiles/entrypoint.sh deleted file mode 100755 index b8fdc61aa..000000000 --- a/dockerfiles/entrypoint.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -set -euv - -export DOCSRS_PREFIX=/opt/docsrs/prefix -export DOCSRS_DOCKER=true -export DOCSRS_LOG=${DOCSRS_LOG-"docs-rs,rustwide=info"} -export PATH="$PATH:/build/target/release" - -# Try migrating the database multiple times if it fails -# This avoids the docker container crashing the first time it's started with -# docker-compose, as PostgreSQL needs some time to initialize. -set +e -failed=0 -while true; do - if ! cratesfyi database migrate; then - ((failed=failed + 1)) - if [ "${failed}" -eq 5 ]; then - exit 1 - fi - echo "failed to migrate the database" - echo "waiting 1 second..." - sleep 1 - else - break - fi -done -set -e - -if ! [ -d "${DOCSRS_PREFIX}/crates.io-index/.git" ]; then - git clone ${REGISTRY_URL:-https://github.com/rust-lang/crates.io-index} "${DOCSRS_PREFIX}/crates.io-index" - # Prevent new crates built before the container creation to be built - git --git-dir="$DOCSRS_PREFIX/crates.io-index/.git" branch crates-index-diff_last-seen -fi - -cratesfyi build update-toolchain --only-first-time - -cratesfyi "$@" diff --git a/dockerfiles/run-gui-tests.sh b/dockerfiles/run-gui-tests.sh deleted file mode 100755 index aeae6bfc4..000000000 --- a/dockerfiles/run-gui-tests.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# Just in case it's running, we stop the web server. -docker-compose stop web - -docker-compose up -d db s3 - -# If we have a .env file, we need to temporarily move it so -# it doesn't make sqlx fail compilation. -if [ -f .env ]; then - mv .env .tmp.env -fi - -# We add the information we need. -cargo run -- database migrate -cargo run -- build update-toolchain -cargo run -- build crate sysinfo 0.23.4 -cargo run -- build crate sysinfo 0.23.5 -cargo run -- build crate libtest 0.0.1 -cargo run -- build add-essential-files - -if [ -f .tmp.env ]; then - mv .tmp.env .env -fi - -# In case we don't have a `.env`, we create one. -if [ ! -f .env ]; then - cp .env.sample .env -fi - -. .env - -cargo run -- start-web-server & -SERVER_PID=$! - -# status="docker run . -v `pwd`:/build/out:ro gui_tests" -docker-compose run gui_tests -status=$? -exit $status diff --git a/dockerfiles/Dockerfile-gui-tests b/gui-tests/Dockerfile similarity index 95% rename from dockerfiles/Dockerfile-gui-tests rename to gui-tests/Dockerfile index 4e4108d2d..6563249ba 100644 --- a/dockerfiles/Dockerfile-gui-tests +++ b/gui-tests/Dockerfile @@ -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: @@ -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"] diff --git a/gui-tests/README.md b/gui-tests/README.md new file mode 100644 index 000000000..b7e5e564f --- /dev/null +++ b/gui-tests/README.md @@ -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. diff --git a/gui-tests/in-docker b/gui-tests/in-docker new file mode 100755 index 000000000..b5b7d0cd0 --- /dev/null +++ b/gui-tests/in-docker @@ -0,0 +1,70 @@ +#!/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 + run docker compose run --rm gui-tests-builder build crate libtest 0.0.1 + + # 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