From 3536f9fe4229e7079cbdb69091abceb3f7c5900a Mon Sep 17 00:00:00 2001 From: Benoit TELLIER Date: Fri, 2 Oct 2026 14:48:58 +0200 Subject: [PATCH] [QA] Add a twake-qa compatible QA environment --- scripts/qa-environment/.gitignore | 1 + scripts/qa-environment/build.sh | 14 +++ scripts/qa-environment/docker-compose.yaml | 29 ++++++ scripts/qa-environment/start.sh | 106 +++++++++++++++++++++ scripts/qa-environment/stop.sh | 17 ++++ 5 files changed, 167 insertions(+) create mode 100644 scripts/qa-environment/.gitignore create mode 100755 scripts/qa-environment/build.sh create mode 100644 scripts/qa-environment/docker-compose.yaml create mode 100755 scripts/qa-environment/start.sh create mode 100755 scripts/qa-environment/stop.sh diff --git a/scripts/qa-environment/.gitignore b/scripts/qa-environment/.gitignore new file mode 100644 index 000000000..ecb842d70 --- /dev/null +++ b/scripts/qa-environment/.gitignore @@ -0,0 +1 @@ +.generated/ diff --git a/scripts/qa-environment/build.sh b/scripts/qa-environment/build.sh new file mode 100755 index 000000000..720ee097a --- /dev/null +++ b/scripts/qa-environment/build.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# +# Builds the web app image start.sh runs, from the working tree, with the release Dockerfile. +# The backend image is pulled by start.sh. +# +# scripts/qa-environment/build.sh # once, and whenever the code under test changes +# +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +REPO_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" + +# host network: pub get fails from the default bridge network on some hosts +docker build --network host -t tmail-web-qa -f "$REPO_DIR/Dockerfile" "$REPO_DIR" diff --git a/scripts/qa-environment/docker-compose.yaml b/scripts/qa-environment/docker-compose.yaml new file mode 100644 index 000000000..202da9903 --- /dev/null +++ b/scripts/qa-environment/docker-compose.yaml @@ -0,0 +1,29 @@ +# QA stack started by start.sh. The backend configuration is the one of backend-docker/, except +# the files start.sh generates under .generated/ (JWT keys, jmap.properties with the public URLs, +# the env.file of the web app). +services: + tmail-backend: + image: ${TMAIL_BACKEND_IMAGE:?} + volumes: + - ./.generated/jwt_publickey:/root/conf/jwt_publickey + - ./.generated/jwt_privatekey:/root/conf/jwt_privatekey + - ./.generated/jmap.properties:/root/conf/jmap.properties + - ../../backend-docker/mailetcontainer.xml:/root/conf/mailetcontainer.xml + - ../../backend-docker/imapserver.xml:/root/conf/imapserver.xml + - ../../backend-docker/deletedMessageVault.properties:/root/conf/deletedMessageVault.properties + - ../../backend-docker/listeners.xml:/root/conf/listeners.xml + - ../../backend-docker/linagora-ecosystem.properties:/root/conf/linagora-ecosystem.properties + - ../../backend-docker/openpaas.properties:/root/conf/openpaas.properties + - ../../provisioning/integration_test/provisioning.sh:/root/conf/integration_test/provisioning.sh + - ../../provisioning/integration_test/backup.zip:/root/conf/integration_test/backup.zip + ports: + - "${QA_JMAP_PORT:?}:80" + environment: + - DOMAIN=example.com + + web: + image: tmail-web-qa + volumes: + - ./.generated/env.file:/usr/share/nginx/html/assets/env.file:ro + ports: + - "${QA_WEB_PORT:?}:80" diff --git a/scripts/qa-environment/start.sh b/scripts/qa-environment/start.sh new file mode 100755 index 000000000..3c259dd1e --- /dev/null +++ b/scripts/qa-environment/start.sh @@ -0,0 +1,106 @@ +#!/bin/bash +# +# Starts a long lived web app + tmail-backend stack for manual or agent driven exploratory QA. +# +# Same backend as the patrol integration tests (backend-docker/, provisioned with +# provisioning/integration_test/provisioning.sh), but under its own compose project and ports so it +# does not clash with them, and kept up until stop.sh is called. +# +# scripts/qa-environment/build.sh # once, and whenever the code under test changes +# scripts/qa-environment/start.sh +# QA_USERS="frank grace" scripts/qa-environment/start.sh # extra accounts +# +# Accounts are @example.com, the password is the uid: alice, bob (with a restored mailbox, +# a quota and the bob-guests team mailbox), brian, charlotte, david, emma, plus QA_USERS. +# +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +REPO_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" +GENERATED_DIR="$SCRIPT_DIR/.generated" + +QA_PROJECT="${QA_PROJECT:-tmail-qa}" +QA_USERS="${QA_USERS:-}" +DOMAIN="example.com" +export QA_WEB_PORT="${QA_WEB_PORT:-8080}" +export QA_JMAP_PORT="${QA_JMAP_PORT:-8090}" +# Single source of truth for the backend version: the compose file of the integration tests. +TMAIL_BACKEND_IMAGE="$(sed -n 's/^ *image: *\(linagora\/tmail-backend:.*\)$/\1/p' "$REPO_DIR/backend-docker/docker-compose.yaml")" +export TMAIL_BACKEND_IMAGE + +JMAP_URL="http://localhost:$QA_JMAP_PORT" +WEB_URL="http://localhost:$QA_WEB_PORT" + +compose() { + docker compose -p "$QA_PROJECT" -f "$SCRIPT_DIR/docker-compose.yaml" "$@" +} + +webadmin() { + compose exec -T tmail-backend curl -s "$@" +} + +if ! docker image inspect tmail-web-qa >/dev/null 2>&1; then + echo "The tmail-web-qa image is missing, build it first: scripts/qa-environment/build.sh" >&2 + exit 1 +fi + +echo "==> Generating the configuration in $GENERATED_DIR" +mkdir -p "$GENERATED_DIR" +if [ ! -f "$GENERATED_DIR/jwt_privatekey" ]; then + openssl genpkey -algorithm rsa -pkeyopt rsa_keygen_bits:4096 -out "$GENERATED_DIR/jwt_privatekey" 2>/dev/null + openssl rsa -in "$GENERATED_DIR/jwt_privatekey" -pubout -out "$GENERATED_DIR/jwt_publickey" 2>/dev/null +fi +# James advertises these URLs in its JMAP session, the app uses them for every later request. +sed -e "s|^url.prefix=.*|url.prefix=$JMAP_URL|" \ + -e "s|^websocket.url.prefix=.*|websocket.url.prefix=ws://localhost:$QA_JMAP_PORT|" \ + "$REPO_DIR/backend-docker/jmap.properties" > "$GENERATED_DIR/jmap.properties" +sed -e "s|^SERVER_URL=.*|SERVER_URL=$JMAP_URL/|" \ + -e "s|^DOMAIN_REDIRECT_URL=.*|DOMAIN_REDIRECT_URL=$WEB_URL|" \ + "$REPO_DIR/integration_test/integration_test_env.file" > "$GENERATED_DIR/env.file" + +echo "==> Starting the stack as compose project '$QA_PROJECT' ($TMAIL_BACKEND_IMAGE)" +compose up -d + +echo "==> Waiting for tmail-backend" +for _ in $(seq 1 120); do + if compose logs tmail-backend 2>/dev/null | grep -qi "JAMES server started"; then + ready=true + break + fi + sleep 5 +done +if [ "${ready:-false}" != "true" ]; then + echo "tmail-backend did not start within 10 minutes, see: docker compose -p $QA_PROJECT logs" >&2 + exit 1 +fi + +echo "==> Creating the QA accounts" +if [ "$(webadmin -I -o /dev/null -w '%{http_code}' "http://localhost:8000/users/bob@$DOMAIN")" = "200" ]; then + echo " already provisioned" +else + compose exec -T tmail-backend /root/conf/integration_test/provisioning.sh >/dev/null +fi +for uid in $QA_USERS; do + status="$(webadmin -o /dev/null -w '%{http_code}' -X PUT -H 'Content-Type: application/json' \ + -d "{\"password\":\"$uid\"}" "http://localhost:8000/users/$uid@$DOMAIN")" + case "$status" in + 204) ;; + *) echo "tmail-backend refused to create $uid@$DOMAIN: HTTP $status" >&2; exit 1 ;; + esac +done +for uid in alice bob brian charlotte david emma $QA_USERS; do + echo " $uid@$DOMAIN / $uid" +done + +cat < The QA environment is up + + Web app: $WEB_URL (basic authentication, no SSO) + JMAP: $JMAP_URL/jmap/session + +From a container (e.g. Playwright), join the network '${QA_PROJECT}_default' and use: + --host-resolver-rules="MAP localhost:$QA_WEB_PORT web:80,MAP localhost:$QA_JMAP_PORT tmail-backend:80" + +Stop it with: scripts/qa-environment/stop.sh +INFO diff --git a/scripts/qa-environment/stop.sh b/scripts/qa-environment/stop.sh new file mode 100755 index 000000000..43f74ef7e --- /dev/null +++ b/scripts/qa-environment/stop.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Stops the QA environment started by start.sh. The backend stores everything in memory: its data +# is gone once stopped. +# +# scripts/qa-environment/stop.sh +# +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" + +QA_PROJECT="${QA_PROJECT:-tmail-qa}" + +# compose interpolates the whole file even to stop it +export TMAIL_BACKEND_IMAGE=unused QA_JMAP_PORT=0 QA_WEB_PORT=0 +docker compose -p "$QA_PROJECT" -f "$SCRIPT_DIR/docker-compose.yaml" down --volumes +echo "==> QA environment '$QA_PROJECT' stopped"