Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

feat(web): implement Docker image build and smoke test for web app deployment

Dev jacobf2e9d2850800
diff --git a/.github/workflows/release-web.yml b/.github/workflows/release-web.yml
index c944217f9..5cb154f9f 100644
--- a/.github/workflows/release-web.yml
+++ b/.github/workflows/release-web.yml
@@ -42,8 +42,56 @@ jobs:
run: |
printf '%s\n' \
'Browser build of the shared desktop Flutter app.' \
- 'The website deployment pins the archive and SHA-256 from harness-web-release.json.' \
+ 'The harness-web image serves these exact bytes, verified against harness-web-release.json.' \
> "$RUNNER_TEMP/web-release-notes.md"
gh release create "$RELEASE_TAG" desktop/build/web-dist/* \
--verify-tag --latest=false --title "Harness Web $WEB_VERSION" \
--notes-file "$RUNNER_TEMP/web-release-notes.md"
+
+ # The image ArgoCD rolls out for the app's routes on harness.autonomous.ai (desktop/deploy/web).
+ # Built from the release just published, smoke-tested, then pushed as <HARNESS_WEB_IMAGE>:<tag>.
+ # TODO(devops): set the repository variable HARNESS_WEB_IMAGE (e.g.
+ # <region>-docker.pkg.dev/<project>/<repo>/harness-web) and the GCP_WORKLOAD_IDENTITY_PROVIDER /
+ # GCP_SERVICE_ACCOUNT secrets the website's build uses. Until then the image is built and tested only.
+ image:
+ needs: bundle
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+ permissions:
+ contents: read
+ id-token: write
+ env:
+ RELEASE_TAG: ${{ github.ref_name }}
+ WEB_IMAGE: ${{ vars.HARNESS_WEB_IMAGE }}
+ steps:
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
+ - name: Fetch the published bundle
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: |
+ gh release download "$RELEASE_TAG" -D "$RUNNER_TEMP/release" \
+ -p 'harness-web-*.tar.gz' -p harness-web-release.json
+ - name: Build the image
+ run: |
+ python3 desktop/deploy/web/prepare.py "$RUNNER_TEMP/release/harness-web-release.json" \
+ "$RUNNER_TEMP"/release/harness-web-*.tar.gz "$RUNNER_TEMP/image"
+ docker build -f desktop/deploy/web/Dockerfile -t harness-web:ci "$RUNNER_TEMP/image"
+ - name: Smoke test
+ run: |
+ docker run -d --name harness-web -p 8080:8080 harness-web:ci
+ bash desktop/deploy/web/smoke.sh http://127.0.0.1:8080 "$RUNNER_TEMP/release/harness-web-release.json"
+ - name: Sign in to Google Cloud
+ if: env.WEB_IMAGE != ''
+ uses: google-github-actions/auth@v2
+ with:
+ workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
+ service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
+ - name: Push
+ if: env.WEB_IMAGE != ''
+ run: |
+ gcloud auth configure-docker "${WEB_IMAGE%%/*}" --quiet
+ docker tag harness-web:ci "$WEB_IMAGE:$RELEASE_TAG"
+ docker push "$WEB_IMAGE:$RELEASE_TAG"
+ - name: Not pushed
+ if: env.WEB_IMAGE == ''
+ run: echo "::warning::HARNESS_WEB_IMAGE is not set — the image was built and smoke-tested but not pushed."
diff --git a/desktop/README.md b/desktop/README.md
index 123e4d57e..0a324e1e5 100644
--- a/desktop/README.md
+++ b/desktop/README.md
@@ -83,6 +83,35 @@ For a local production build, run `bash scripts/build-web-release.sh X.Y.Z`.
`FLUTTER_BIN` can select an SDK installed outside `PATH`. Output is under
`build/web-release/` and `build/web-dist/`; the ordinary local preview is separate.
+### Web image
+
+The same tag also builds the app's own image, [`deploy/web/`](deploy/web/), for the
+existing ArgoCD rollout. It is nginx serving only the app's routes (`/`, `/s/:id`,
+`/auth/callback`, `/callback`, `/harness-web/*`) on port 8080, with `/healthz`. The
+website keeps downloads, `/pair`, `/install.sh` and its redirects, so the ingress
+routes only those app paths to this image. The image job:
+
+1. Downloads the release it just published.
+2. Runs `prepare.py`, which verifies the checksum and applies the versioned asset
+ layout above.
+3. Builds the image and runs `smoke.sh` against it. The smoke test fails if `/` is
+ not this release's Flutter app.
+4. Pushes `$HARNESS_WEB_IMAGE:vX.Y.Z_web`.
+
+Push needs the repository variable `HARNESS_WEB_IMAGE` and the
+`GCP_WORKLOAD_IDENTITY_PROVIDER`/`GCP_SERVICE_ACCOUNT` secrets. Without them, the
+image is built and tested only. To build and check it locally:
+
+```bash
+gh release download vX.Y.Z_web -D rel -p 'harness-web-*.tar.gz' -p harness-web-release.json
+python3 deploy/web/prepare.py rel/harness-web-release.json rel/harness-web-X.Y.Z.tar.gz ctx
+docker build -f deploy/web/Dockerfile -t harness-web ctx
+docker run -d -p 8080:8080 harness-web && bash deploy/web/smoke.sh http://127.0.0.1:8080 rel/harness-web-release.json
+```
+
+Keep Docker files out of `web/`: `flutter build web` copies that folder into the
+public bundle.
+
### Browser behavior
- Authenticated access to existing machines uses the shared viewer services and
diff --git a/desktop/deploy/web/Dockerfile b/desktop/deploy/web/Dockerfile
new file mode 100644
index 000000000..a81b4400a
--- /dev/null
+++ b/desktop/deploy/web/Dockerfile
@@ -0,0 +1,13 @@
+# harness.autonomous.ai's browser app as static files, for the existing ArgoCD rollout.
+#
+# The build context is the directory prepare.py writes — site/ and nginx.conf — not this repo:
+# python3 desktop/deploy/web/prepare.py harness-web-release.json harness-web-X.Y.Z.tar.gz ctx
+# docker build -f desktop/deploy/web/Dockerfile -t harness-web ctx
+# so the image serves the exact, checksum-verified bytes of the GitHub release. Non-root, port 8080.
+FROM nginxinc/nginx-unprivileged:1.27-alpine@sha256:65e3e85dbaed8ba248841d9d58a899b6197106c23cb0ff1a132b7bfe0547e4c0
+
+COPY nginx.conf /etc/nginx/conf.d/default.conf
+COPY site/ /usr/share/nginx/html/
+
+EXPOSE 8080
+HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://127.0.0.1:8080/healthz || exit 1
diff --git a/desktop/deploy/web/nginx.conf b/desktop/deploy/web/nginx.conf
new file mode 100644
index 000000000..7012a0021
--- /dev/null
+++ b/desktop/deploy/web/nginx.conf
@@ -0,0 +1,46 @@
+# harness.autonomous.ai's browser app: the app's routes and nothing else. The website keeps downloads,
+# /pair, /install.sh and its redirects; the ingress sends only these paths here.
+#
+# Cache rules are the website's (next.config.js), which the CDN in front relies on:
+# - entry pages and release.json: no-store, so every load sees the current release;
+# - /harness-web/releases/<version>-<sha12>/: immutable, since that URL never changes content;
+# - unversioned /harness-web/ files, kept for tabs opened before a deployment: revalidate every time.
+
+map $uri $harness_cache {
+ ~^/harness-web/releases/ "public, max-age=31536000, immutable";
+ ~^/harness-web/(index\.html|release\.json)$ "no-store";
+ ~^/harness-web/ "public, max-age=0, must-revalidate";
+ default "no-store";
+}
+
+server {
+ listen 8080;
+ server_name _;
+ root /usr/share/nginx/html;
+ server_tokens off;
+
+ # Server-level only: an add_header inside a location would drop all of these for it.
+ add_header Cache-Control $harness_cache always;
+ add_header Referrer-Policy no-referrer always;
+ add_header X-Content-Type-Options nosniff always;
+
+ location = /healthz {
+ access_log off;
+ default_type text/plain;
+ return 200 "ok\n";
+ }
+
+ # `/`, a shared link `/s/<id>`, the OAuth return (`/auth/callback`, and `/callback` for loopback
+ # previews) and `/harness-web` all open the app; the base href keeps the visible URL.
+ location ~ ^/(s/[^/]+|auth/callback|callback|harness-web)?/?$ {
+ rewrite ^ /harness-web/index.html last;
+ }
+
+ location /harness-web/ {
+ try_files $uri =404;
+ }
+
+ location / {
+ return 404;
+ }
+}
diff --git a/desktop/deploy/web/prepare.py b/desktop/deploy/web/prepare.py
new file mode 100644
index 000000000..d54440d68
--- /dev/null
+++ b/desktop/deploy/web/prepare.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python3
+"""Turn a published web bundle into the image's build context.
+
+ python3 prepare.py <harness-web-release.json> <harness-web-X.Y.Z.tar.gz> <out-dir>
+
+Writes <out-dir>/site/harness-web/ and <out-dir>/nginx.conf. Ported from the website's
+fetch-harness-web.mjs + harness-web-assets.mjs, which prepared the same tree inside its image:
+
+- the archive must match the manifest's SHA-256, and its own release.json the manifest;
+- every file is also served from /harness-web/releases/<version>-<sha12>/, and index.html loads
+ JavaScript, fonts and CanvasKit only from there, so an edge or browser cache holding an older
+ release can never mix its assets into a newer page. The unversioned files stay for tabs opened
+ before a deployment;
+- the generated service worker is not started: it could keep serving an older app on its own.
+"""
+import hashlib
+import json
+import re
+import shutil
+import sys
+import tarfile
+from pathlib import Path, PurePosixPath
+
+BASE_HREF = '/harness-web/'
+LOADER = re.compile(r'_flutter\.loader\.load\(\{[\s\S]*?\}\);\s*(?=</script>)')
+
+
+def fail(message: str) -> None:
+ sys.exit(f'ERROR {message}')
+
+
+def release_asset_base(release: dict) -> str:
+ return f"{BASE_HREF}releases/{release['version']}-{release['sha256'][:12]}/"
+
+
+def configure_release_assets(html: str, release: dict) -> str:
+ if len(LOADER.findall(html)) != 1:
+ fail('unexpected Flutter bootstrap; refusing to publish unversioned assets')
+ base = release_asset_base(release)
+ config = {'entrypointBaseUrl': base, 'assetBase': base, 'canvasKitBaseUrl': f'{base}canvaskit/'}
+ # Compact separators: the page must read exactly as the website's JSON.stringify wrote it.
+ return LOADER.sub(f"_flutter.loader.load({json.dumps({'config': config}, separators=(',', ':'))});\n", html)
+
+
+def main(manifest_path: str, archive_path: str, out_dir: str) -> None:
+ release = json.loads(Path(manifest_path).read_text())
+ if not (re.fullmatch(r'\d+\.\d+\.\d+', release.get('version', ''))
+ and re.fullmatch(r'[a-f0-9]{40}', release.get('sourceCommit', ''))
+ and re.fullmatch(r'[a-f0-9]{64}', release.get('sha256', ''))
+ and release.get('baseHref') == BASE_HREF):
+ fail(f'invalid web release manifest: {manifest_path}')
+ if hashlib.sha256(Path(archive_path).read_bytes()).hexdigest() != release['sha256']:
+ fail('web archive checksum mismatch')
+
+ out = Path(out_dir)
+ shutil.rmtree(out, ignore_errors=True)
+ served = out / 'site' / BASE_HREF.strip('/')
+ served.mkdir(parents=True)
+ with tarfile.open(archive_path, 'r:gz') as bundle:
+ for member in bundle.getmembers():
+ name = PurePosixPath(member.name)
+ if name.is_absolute() or '..' in name.parts or not (member.isfile() or member.isdir()):
+ fail(f'web archive contains an unsafe entry: {member.name}')
+ bundle.extractall(served, filter='data')
+
+ metadata = json.loads((served / 'release.json').read_text())
+ index = (served / 'index.html').read_text()
+ if (metadata.get('version') != release['version'] or metadata.get('sourceCommit') != release['sourceCommit']
+ or metadata.get('baseHref') != BASE_HREF or f'<base href="{BASE_HREF}">' not in index):
+ fail('web archive does not match its release manifest')
+
+ entry = configure_release_assets(index, release)
+ versioned = served / release_asset_base(release)[len(BASE_HREF):]
+ shutil.copytree(served, versioned, ignore=shutil.ignore_patterns('releases'))
+ (served / 'index.html').write_text(entry)
+ shutil.copy(Path(__file__).with_name('nginx.conf'), out / 'nginx.conf')
+ print(f"Prepared Harness web {release['version']} ({release['sourceCommit'][:12]}) in {out}")
+
+
+if __name__ == '__main__':
+ if len(sys.argv) != 4:
+ fail('usage: prepare.py <harness-web-release.json> <archive.tar.gz> <out-dir>')
+ main(*sys.argv[1:])
diff --git a/desktop/deploy/web/smoke.sh b/desktop/deploy/web/smoke.sh
new file mode 100644
index 000000000..66f75d593
--- /dev/null
+++ b/desktop/deploy/web/smoke.sh
@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+# Smoke-test a running web image against its release manifest — the website's check-harness-web.mjs,
+# plus the check that would have stopped v1.2.22_web: `/` must be the Flutter app, not some other page.
+#
+# bash smoke.sh http://127.0.0.1:8080 harness-web-release.json
+# No -e: every check runs and reports, and the exit status says whether any failed.
+set -uo pipefail
+
+BASE="${1:?usage: smoke.sh <base-url> <harness-web-release.json>}"
+MANIFEST="${2:?usage: smoke.sh <base-url> <harness-web-release.json>}"
+VERSION="$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["version"])' "$MANIFEST")"
+SHA12="$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["sha256"][:12])' "$MANIFEST")"
+ASSET_BASE="/harness-web/releases/$VERSION-$SHA12/"
+FAILED=0
+
+check() { # <description> <condition-exit-code>
+ if [ "$2" -eq 0 ]; then echo " ok $1"; else echo " FAIL $1"; FAILED=1; fi
+}
+
+for _ in $(seq 1 30); do curl -fs "$BASE/healthz" >/dev/null && break; sleep 1; done
+
+for route in / /s/11111111-1111-4111-8111-111111111111 '/auth/callback?code=fixture-code&state=fixture-state' /callback /harness-web; do
+ headers="$(curl -s -D - -o /tmp/harness-web-smoke.html "$BASE$route")"
+ html="$(cat /tmp/harness-web-smoke.html)"
+ grep -q '^HTTP/[0-9.]* 200' <<<"$headers"; check "$route → 200" $?
+ grep -qi '^content-type: text/html' <<<"$headers"; check "$route is HTML" $?
+ grep -qi '^cache-control: no-store' <<<"$headers"; check "$route is no-store" $?
+ grep -qi '^referrer-policy: no-referrer' <<<"$headers"; check "$route sends no referrer" $?
+ grep -q '<base href="/harness-web/">' <<<"$html"; check "$route is the Flutter app" $?
+ grep -qF "\"entrypointBaseUrl\":\"$ASSET_BASE\"" <<<"$html"; check "$route loads $ASSET_BASE" $?
+ ! grep -q 'fixture-code' <<<"$html"; check "$route does not echo the callback code" $?
+done
+
+for spec in 'main.dart.js|javascript' 'assets/FontManifest.json|json' 'canvaskit/chromium/canvaskit.wasm|application/wasm'; do
+ path="${spec%%|*}"; type="${spec#*|}"
+ headers="$(curl -s -I "$BASE$ASSET_BASE$path")"
+ grep -q '^HTTP/[0-9.]* 200' <<<"$headers"; check "$path → 200" $?
+ grep -qi "^content-type: .*$type" <<<"$headers"; check "$path is $type" $?
+ grep -qi '^cache-control: .*immutable' <<<"$headers"; check "$path is immutable" $?
+done
+
+curl -s "$BASE/harness-web/release.json" | grep -q "\"version\": \"$VERSION\""; check "release.json reports $VERSION" $?
+[ "$(curl -s -o /dev/null -w '%{http_code}' "$BASE/download")" = 404 ]; check "website routes are not served here" $?
+
+rm -f /tmp/harness-web-smoke.html
+[ "$FAILED" -eq 0 ] || { echo "smoke test FAILED"; exit 1; }
+echo "smoke test passed: Harness web $VERSION"
diff --git a/desktop/scripts/release-web.sh b/desktop/scripts/release-web.sh
index 32fb2d687..510d68505 100755
--- a/desktop/scripts/release-web.sh
+++ b/desktop/scripts/release-web.sh
@@ -35,7 +35,9 @@ cd "$ROOT"
BRANCH="${BRANCH:-main}"
WORKFLOW="${WORKFLOW:-release-web.yml}"
WEBSITE_REPO="${WEBSITE_REPO:-autonomous-ai/autonomous-code}"
-WEBSITE_BRANCH="${WEBSITE_BRANCH:-main}"
+# Not the website's main: the Flutter host (bundle fetch in `prebuild`, next.config rewrites) lives on
+# deploy/flutter-web. v1.2.22_web was cut from main and took the app off harness.autonomous.ai.
+WEBSITE_BRANCH="${WEBSITE_BRANCH:-deploy/flutter-web}"
WEBSITE_MANIFEST="${WEBSITE_MANIFEST:-apps/web/harness-web-release.json}"
RUN_APPEAR_TIMEOUT="${RUN_APPEAR_TIMEOUT:-180}" # seconds for the tag's workflow run to show up
@@ -55,6 +57,15 @@ done
say() { echo ">> $*"; }
die() { echo "ERROR $*" >&2; exit 1; }
+# The website branch must actually serve the bundle, or its release replaces the app with the plain site.
+require_flutter_host() {
+ local web="$SITE/apps/web"
+ [ -f "$web/scripts/fetch-harness-web.mjs" ] \
+ && grep -q 'fetch-harness-web' "$web/package.json" \
+ && grep -q 'harness-web' "$web/next.config.js" \
+ || die "$WEBSITE_REPO $WEBSITE_BRANCH does not host the Flutter app (no bundle fetch or /harness-web rewrites) — releasing it would take the app off the site"
+}
+
# Same rollover as release-desktop.sh: .99 goes to the next MINOR at .1.
next_version() {
local current="$1" minor_bump="$2"
@@ -113,12 +124,18 @@ say "website : $WEBSITE_REPO $WEBSITE_BRANCH → $WEBSITE_MANIFEST"
gh repo clone "$WEBSITE_REPO" "$SITE" -- --quiet --filter=blob:none --branch "$WEBSITE_BRANCH" >/dev/null 2>&1 \
|| die "could not clone $WEBSITE_REPO"
SITE_LAST_TAG="$(git -C "$SITE" tag -l 'v*_web' | { grep -E '^v[0-9]+\.[0-9]+\.[0-9]+_web$' || true; } | sort -V | tail -1)"
+require_flutter_host
if [ -n "$SITE_LAST_TAG" ]; then
PENDING="$(git -C "$SITE" log --oneline "$SITE_LAST_TAG..HEAD")"
if [ -n "$PENDING" ]; then
say "website commits since $SITE_LAST_TAG that will ALSO go live:"
echo "$PENDING" | sed 's/^/ /'
fi
+ DROPPED="$(git -C "$SITE" log --oneline "HEAD..$SITE_LAST_TAG")"
+ if [ -n "$DROPPED" ]; then
+ say "WARNING live in $SITE_LAST_TAG but NOT on $WEBSITE_BRANCH — this release takes them down:"
+ echo "$DROPPED" | sed 's/^/ /'
+ fi
fi
if [ "$DRY_RUN" -eq 1 ]; then
@@ -179,6 +196,7 @@ if ! cmp -s "$WORK/harness-web-release.json" "$SITE/$WEBSITE_MANIFEST"; then
fi
cmp -s "$WORK/harness-web-release.json" "$SITE/$WEBSITE_MANIFEST" \
|| die "$WEBSITE_REPO $WEBSITE_BRANCH does not pin $VER after the merge — someone else changed it; check before releasing"
+require_flutter_host
# --- 4. the website release, by the website's own script (skipped when its last release already pins it) ---
if [ -n "$SITE_LAST_TAG" ] && git -C "$SITE" show "$SITE_LAST_TAG:$WEBSITE_MANIFEST" 2>/dev/null \