Skip to content

Replace docker compose script in yarn #8541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 30, 2025
Merged

Replace docker compose script in yarn #8541

merged 10 commits into from
Apr 30, 2025

Conversation

robert-oleynik
Copy link
Contributor

Steps to test:

  • Run yarn refresh-screenshots and yarn refresh-e2e-snapshots

TODOs:

  • ...

Issues:

  • Scripts depending on removed docker compose file

(Please delete unneeded items, merge only when none are left open)

@robert-oleynik robert-oleynik self-assigned this Apr 16, 2025
Copy link
Contributor

coderabbitai bot commented Apr 16, 2025

📝 Walkthrough
## Walkthrough

This change updates the automation scripts related to refreshing screenshots and end-to-end (E2E) snapshots in the project's `package.json`. The scripts now use a newly introduced `tools/docker-env.sh` shell script to manage Docker-based test environments. The `refresh-screenshots` script now retries the screenshot tests up to three times within a Puppeteer Docker container, while the `refresh-e2e-snapshots` script replaces Docker Compose commands with a direct `sbt` test invocation inside the Docker environment managed by `tools/docker-env.sh`. The new shell script handles Docker service setup, environment variable configuration, command execution, and cleanup. Additionally, the PostgreSQL port mapping was changed in the Docker Compose configuration, and the PostgreSQL port was updated in the CI workflow environment variables.

## Changes

| File(s)                                  | Change Summary                                                                                                      |
|------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| package.json                             | Updated `refresh-screenshots` to run `tools/refresh-screenshots.sh`; simplified `remove-e2e-snapshots`; updated `refresh-e2e-snapshots` to run `sbt` via `tools/docker-env.sh`. |
| tools/docker-env.sh                      | Added new shell script to set environment variables, start/stop Docker services, run passed commands, and clean up.  |
| tools/refresh-screenshots.sh             | Added new shell script to remove screenshots and run Puppeteer tests inside a Docker container with retries.         |
| .github/docker-compose.yml               | Changed PostgreSQL port mapping from `5432:5432` to `5434:5432`; switched PostgreSQL data volume to named Docker volume. |
| .github/workflows/build_test_deploy.yml | Updated `POSTGRES_URL` environment variable port from `5432` to `5434`.                                              |

## Suggested labels

`CI`

## Poem

> 🐇  
> In Docker’s warren, scripts now dwell,  
> With bash and yarn, they cast their spell.  
> Three hops for screenshots, E2E anew,  
> Docker-env makes all things true!  
> Snapshots refreshed, the tests all run—  
> This rabbit’s work is never done!  
> 🥕

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a640cb and 43530a8.

📒 Files selected for processing (1)
  • tools/refresh-screenshots.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/refresh-screenshots.sh
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build-smoketest-push
  • GitHub Check: frontend-tests
  • GitHub Check: backend-tests
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tools/docker-env.sh (1)

1-21: Solid approach for Docker environment management; consider signal trapping and error handling.

This script effectively centralizes Docker environment setup and teardown for test workflows. It is readable and should work as intended for most CI and local development scenarios.

Suggestions for improvement:

  • Signal trapping: If the script is interrupted (e.g., Ctrl+C), Docker containers may be left running. Consider trapping signals (SIGINT, SIGTERM, EXIT) to ensure cleanup.
  • Docker daemon check: Add a check to ensure Docker is running before proceeding.
  • Error handling: If docker compose up fails, the script continues. Consider checking the exit status and aborting early if setup fails.
  • Working directory assumption: The script assumes it is run from the project root. Document this assumption or make the script robust to being called from other directories.

Example for signal trapping and error handling:

+cleanup() {
+  cd .github || exit
+  docker compose down -v
+  cd .. || exit
+}
+trap cleanup EXIT INT TERM
+
cd .github || exit
docker compose down -v
docker compose up -d postgres redis fossildb || exit 1
cd .. || exit
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 867ef96 and 024e8f5.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • tools/docker-env.sh (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build-smoketest-push
  • GitHub Check: frontend-tests
  • GitHub Check: backend-tests
🔇 Additional comments (1)
package.json (1)

101-101: Good migration to centralized Docker environment; verify downstream dependencies and document retry rationale.

  • The new scripts are cleaner and should improve reliability by centralizing Docker management.
  • The retry loop for screenshots is a pragmatic solution for flaky tests; consider documenting the rationale for future maintainers.
  • Please verify that all scripts, CI jobs, and developer workflows that previously used Docker Compose directly are now updated or accounted for, as the PR objectives mention possible breakage.
  • Remember to update documentation and the changelog before merging.

Also applies to: 107-107

package.json Outdated
@@ -98,13 +98,13 @@
"test-e2e": "tools/postgres/dbtool.js prepare-test-db && tools/test.sh test-e2e --timeout=60s --verbose",
"test-screenshot": "tools/test.sh test-screenshot --timeout=5m",
"test-wkorg-screenshot": "tools/test.sh test-wkorg-screenshot --timeout=5m",
"refresh-screenshots": "rm -rf frontend/javascripts/test/screenshots/** && docker compose up screenshot-tests",
"refresh-screenshots": "rm -rf frontend/javascripts/test/screenshots/** && ./tools/docker-env.sh bash -c 'for i in {1..3}; do yarn test-screenshot && break; done'",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am getting a No matches found: "frontend/javascripts/test/screenshots/* error when trying to execute the script while the screenshots are already removed. There might be multiple possible reasons for this maybe zsh behaviour or so. This can be fixed by forcing execution in bash:

Suggested change
"refresh-screenshots": "rm -rf frontend/javascripts/test/screenshots/** && ./tools/docker-env.sh bash -c 'for i in {1..3}; do yarn test-screenshot && break; done'",
"refresh-screenshots": "bash -c 'rm -rf frontend/javascripts/test/screenshots/**' && ./tools/docker-env.sh bash -c 'for i in {1..3}; do yarn test-screenshot && break; done'",

Could you please fix that? 🙏

Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, the screenshot tests do not work for me :/. Don't know why but the dataset id cannot be retrieved successfully :/

 dtype_datasets_rendering.screenshot › Dataset IDs were retrieved successfully  public-test/test-bundle/test/puppeteer/dtype_datasets_rendering.screenshot.js:158
   157: import_dataset_rendering_helpers.test.serial("Dataset IDs were retrieved successfully", (t) => {
   158:   (0, import_dataset_rendering_helpers.assertDatasetIds)(t, datasetNames, datasetNameToId);     
   159: });                                                                                             
 Dataset ID not found for "dtype_test_uint8_color"
 Value is not truthy:
 undefined

@philippotto Do you maybe know more about this? I checked my browser stack credentials and wk auth token env var and they seemed to be alright.

Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this robert. But sadly the current version does not work for me. Please see my comments below

package.json Outdated
@@ -98,13 +98,13 @@
"test-e2e": "tools/postgres/dbtool.js prepare-test-db && tools/test.sh test-e2e --timeout=60s --verbose",
"test-screenshot": "tools/test.sh test-screenshot --timeout=5m",
"test-wkorg-screenshot": "tools/test.sh test-wkorg-screenshot --timeout=5m",
"refresh-screenshots": "rm -rf frontend/javascripts/test/screenshots/** && docker compose up screenshot-tests",
"refresh-screenshots": "rm -rf frontend/javascripts/test/screenshots/** && ./tools/docker-env.sh bash -c 'for i in {1..3}; do yarn test-screenshot && break; done'",
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, the screenshot tests do not work for me :/. Don't know why but the dataset id cannot be retrieved successfully :/

 dtype_datasets_rendering.screenshot › Dataset IDs were retrieved successfully  public-test/test-bundle/test/puppeteer/dtype_datasets_rendering.screenshot.js:158
   157: import_dataset_rendering_helpers.test.serial("Dataset IDs were retrieved successfully", (t) => {
   158:   (0, import_dataset_rendering_helpers.assertDatasetIds)(t, datasetNames, datasetNameToId);     
   159: });                                                                                             
 Dataset ID not found for "dtype_test_uint8_color"
 Value is not truthy:
 undefined

@philippotto Do you maybe know more about this? I checked my browser stack credentials and wk auth token env var and they seemed to be alright.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
tools/refresh-screenshots.sh (1)

7-13: Harden and pin the Docker run command
A few improvements to make the Docker invocation more reproducible and robust:

  1. Pin the image instead of using :master:

    -scalableminds/puppeteer:master
    +scalableminds/puppeteer:v1.2.3  # or use a digest
  2. Derive the repo root from the script’s location to avoid relative‐path pitfalls:

    REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"

    Then mount with -v "${REPO_ROOT}:/home/pptruser/webknossos".

  3. Validate required env vars up front:

    : "${URL:?Please set URL}"
    : "${WK_AUTH_TOKEN:?Please set WK_AUTH_TOKEN}"
  4. Optionally pre-pull the image to surface registry errors early:

    docker pull scalableminds/puppeteer:v1.2.3

These changes improve reproducibility, error reporting, and portability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4cd010d and 5dd8e54.

📒 Files selected for processing (3)
  • .github/docker-compose.yml (2 hunks)
  • package.json (1 hunks)
  • tools/refresh-screenshots.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/docker-compose.yml
  • package.json
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: frontend-tests
  • GitHub Check: backend-tests
  • GitHub Check: build-smoketest-push


set -xe

rm -rf frontend/javascripts/test/screenshots/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fix globbing to reliably clear screenshots
The pattern ** requires shopt -s globstar (not enabled by default), so it may not remove nested files. A simpler, reliable approach is:

-rm -rf frontend/javascripts/test/screenshots/**
+rm -rf frontend/javascripts/test/screenshots/*

Or explicitly enable recursive globbing at the top:

shopt -s globstar

Either ensures the directory is properly emptied.

Comment on lines +1 to +3
#!/usr/bin/env bash

set -xe
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Enhance shell strictness for safer execution
Currently the script uses set -xe, but adding stricter options can catch more classes of failures and undefined variables:

-set -xe
+set -euxo pipefail
  • -u: error on unset variables
  • -o pipefail: propagate failures in pipelines
  • Keeps -x (trace) and -e (exit on error)

This hardens the script and surfaces issues early.


🏁 Script executed:

#!/bin/bash
sed -n '1,200p' tools/refresh-screenshots.sh

Length of output: 398


Enhance shell strictness for safer execution in tools/refresh-screenshots.sh
In the shebang section, replace:

- set -xe
+ set -euxo pipefail
  • -u: error on unset variables (e.g. $URL, $WK_AUTH_TOKEN)
  • -o pipefail: catch failures in any pipeline
  • retains -x (command tracing) and -e (exit on error)

This hardens the script and surfaces issues early.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#!/usr/bin/env bash
set -xe
#!/usr/bin/env bash
set -euxo pipefail

@fm3
Copy link
Member

fm3 commented Apr 24, 2025

This will also need to be adapted now to the new snapshot locations due to the changes from #8543

@MichaelBuessemeyer
Copy link
Contributor

I just tied to refresh the snapshots with this PR's code but was unable to do so. I think the reason is that the docker (compose) runs an outdated node version:

$ yarn refresh-screenshots
...
+ docker run --rm -t -e URL= -e WK_AUTH_TOKEN= -w /home/pptruser/webknossos -v .:/home/pptruser/webknossos -u 1000:1000 scalableminds/puppeteer:master bash -c 'for i in {1..3}; do yarn test-screenshot && break; done'
yarn run v1.22.19
error webknossos@: The engine "node" is incompatible with this module. Expected version ">=22". Got "18.20.4"
error Commands cannot run with an incompatible environment.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
yarn run v1.22.19
error webknossos@: The engine "node" is incompatible with this module. Expected version ">=22". Got "18.20.4"
error Commands cannot run with an incompatible environment.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
yarn run v1.22.19
error webknossos@: The engine "node" is incompatible with this module. Expected version ">=22". Got "18.20.4"
error Commands cannot run with an incompatible environment.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

And

$ yarn refresh-e2e-snapshots
...
The CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details. => webknossos / Test / testOnly 6s
failed to load config from <wk-path>webknossos/vitest.config.ts

⎯⎯⎯⎯⎯⎯⎯ Startup Error ⎯⎯⎯⎯⎯⎯⎯⎯
Error [ERR_REQUIRE_ESM]: require() of ES Module <wk-path>webknossos/node_modules/vite-tsconfig-paths/dist/index.js from <wk-path>webknossos/vitest.config.ts not supported.
Instead change the require of index.js in <wk-path>webknossos/vitest.config.ts to a dynamic import() which is available in all CommonJS modules.
    at _require.extensions.<computed> [as .js] (file://<wk-path>webknossos/node_modules/vite/dist/node/chunks/dep-Bid9ssRr.js:54697:9)
    at Object.<anonymous> (<wk-path>webknossos/vitest.config.ts:37:42)
    at _require.extensions.<computed> [as .js] (file://<wk-path>webknossos/node_modules/vite/dist/node/chunks/dep-Bid9ssRr.js:54695:16)
    at loadConfigFromBundledFile (file://<wk-path>webknossos/node_modules/vite/dist/node/chunks/dep-Bid9ssRr.js:54701:17)
    at async bundleAndLoadConfigFile (file://<wk-path>webknossos/node_modules/vite/dist/node/chunks/dep-Bid9ssRr.js:54526:22)
    at async loadConfigFromFile (file://<wk-path>webknossos/node_modules/vite/dist/node/chunks/dep-Bid9ssRr.js:54488:44)
    at async resolveConfig (file://<wk-path>webknossos/node_modules/vite/dist/node/chunks/dep-Bid9ssRr.js:53987:24)
    at async _createServer (file://<wk-path>webknossos/node_modules/vite/dist/node/chunks/dep-Bid9ssRr.js:43886:18)
    at async createViteServer (file://<wk-path>webknossos/node_modules/vitest/dist/chunks/cli-api.bwYuoT4p.js:10149:17)
    at async createVitest (file://<wk-path>webknossos/node_modules/vitest/dist/chunks/cli-api.bwYuoT4p.js:13130:17)
    at async prepareVitest (file://<wk-path>webknossos/node_modules/vitest/dist/chunks/cli-api.bwYuoT4p.js:13521:14)
    at async startVitest (file://<wk-path>webknossos/node_modules/vitest/dist/chunks/cli-api.bwYuoT4p.js:13454:14)
    at async start (file://<wk-path>webknossos/node_modules/vitest/dist/chunks/cac.DK21mt6F.js:1468:15)
    at async CAC.run (file://<wk-path>webknossos/node_modules/vitest/dist/chunks/cac.DK21mt6F.js:1440:2) {
  code: 'ERR_REQUIRE_ESM'
}

@robert-oleynik
Copy link
Contributor Author

The node images require an update in our Dockerfiles: See scalableminds/dockerfiles#65

Copy link
Member

@fm3 fm3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refresh-e2e-snapshots now worked for me 🎉 did not test screenshots.

@MichaelBuessemeyer
Copy link
Contributor

MichaelBuessemeyer commented Apr 29, 2025

screenshots also work 🎉

@robert-oleynik robert-oleynik enabled auto-merge (squash) April 30, 2025 07:33
@robert-oleynik robert-oleynik merged commit dca7c5b into master Apr 30, 2025
5 checks passed
@robert-oleynik robert-oleynik deleted the fix-yarn-scripts branch April 30, 2025 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants