Skip to content

[#2718] Used 'export-db' for the Lagoon pre-deployment database backup.#2724

Merged
AlexSkrypnyk merged 3 commits into
mainfrom
feature/2718-lagoon-export-db
Jun 25, 2026
Merged

[#2718] Used 'export-db' for the Lagoon pre-deployment database backup.#2724
AlexSkrypnyk merged 3 commits into
mainfrom
feature/2718-lagoon-export-db

Conversation

@AlexSkrypnyk

@AlexSkrypnyk AlexSkrypnyk commented Jun 25, 2026

Copy link
Copy Markdown
Member

Closes #2718

Summary

Switches the Lagoon pre-deployment database backup from calling export-db-file directly to calling the public export-db router. The router now detects whether it is running on the host (via a RUN_ON_HOST override or presence of docker in PATH) and dispatches accordingly: inside a Lagoon container (off-host) it runs export-db-file in place without requiring Docker, while on the host it continues to use docker compose exec for file exports or export-db-image for image exports. Unit tests cover all dispatch paths.

Changes

  • .lagoon.yml: replaced export-db-file with export-db in the pre-deployment backup task; VORTEX_DB_DIR preserved, no new flags added.
  • .vortex/tooling/src/export-db: added is_host() helper (honours RUN_ON_HOST override, else probes command -v docker); restructured dispatch so off-host runs export-db-file in place and on-host continues the existing Docker Compose / image paths; removed the hard docker dependency check that blocked container-side execution.
  • .vortex/tooling/tests/unit/export-db.bats: new unit tests covering in-place file export (off-host), Docker Compose file export (on-host), auto-detection via Docker CLI, image export, and image export with registry deployment.
  • 5 installer Lagoon fixture snapshots regenerated to reflect the .lagoon.yml change.

Before / After

BEFORE
──────
.lagoon.yml pre-deploy task
  └─ calls export-db-file directly
       └─ runs inside Lagoon container
            └─ FAIL: export-db-file is an internal script;
                      export-db required Docker (unavailable in container)

export-db (host-only)
  ├─ requires docker in PATH (hard check, exits if missing)
  ├─ no image → docker compose exec ... export-db-file
  └─ image set → export-db-image [→ deploy-container-registry]

AFTER
─────
.lagoon.yml pre-deploy task
  └─ calls export-db (public router)
       └─ is_host()? NO (inside Lagoon container, no docker)
            └─ runs export-db-file in place (no Docker needed) ✓

export-db (host + container aware)
  ├─ is_host()? YES (docker found or RUN_ON_HOST=1)
  │    ├─ no image → docker compose exec -T cli export-db-file
  │    └─ image set → export-db-image [→ deploy-container-registry]
  └─ is_host()? NO
       └─ export-db-file in place (zero Docker dependency)

Summary by CodeRabbit

  • New Features

    • Database export now automatically chooses the appropriate execution mode based on the environment, improving reliability across host and container setups.
    • Production backup handling now uses the updated database export flow during rollout.
  • Bug Fixes

    • Improved consistency for database backup and export operations by simplifying how the export path is selected.

The 'export-db' router now runs the file export in place when not on a Docker host, so the Lagoon backup routes through it instead of calling 'export-db-file' directly. Host detection is overridable via 'RUN_ON_HOST' for tests.
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The production backup step now calls export-db. The export script routes host and non-host execution across file export, image export, and optional registry deployment. New unit tests cover the routing paths.

Changes

DB export routing

Layer / File(s) Summary
Lagoon backup command
.lagoon.yml
The production post-rollout backup command now invokes export-db with the existing private backup directory.
Host routing and export modes
.vortex/tooling/src/export-db
export-db adds host detection and switches between Docker Compose file export, image export, optional registry deployment, and a direct file export off-host.
Host-mode tests
.vortex/tooling/tests/unit/export-db.bats
The Bats suite adds stubs and covers the RUN_ON_HOST paths for in-place export, Docker Compose export, and host detection from docker availability.
Image export tests
.vortex/tooling/tests/unit/export-db.bats
The Bats suite covers image export on host and the optional registry deployment branch when the proceed flag is set.

Sequence Diagram(s)

sequenceDiagram
  participant post_rollout as "post-rollout task"
  participant export_db as "export-db"
  participant docker_cmd as "docker"
  participant docker_compose as "docker compose"
  participant export_db_file as "export-db-file"
  participant export_db_image as "export-db-image"
  participant deploy_container_registry as "deploy-container-registry"

  post_rollout->>export_db: run backup command
  export_db->>docker_cmd: check availability on PATH
  alt host
    export_db->>docker_compose: compose exec -T ... export-db-file
    docker_compose->>export_db_file: export database dump
    opt VORTEX_EXPORT_DB_IMAGE is set
      export_db->>export_db_image: export database image
      opt VORTEX_EXPORT_DB_CONTAINER_REGISTRY_DEPLOY_PROCEED=1
        export_db->>deploy_container_registry: deploy image
      end
    end
  else non-host
    export_db->>export_db_file: export database file directly
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

Needs review

Poem

A bunny hopped by with a backup sack,
and export-db took the scenic track.
File or image, it knows the way,
with registry sparkles on the way!
🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: switching Lagoon backup to use export-db.
Linked Issues check ✅ Passed The PR routes Lagoon backup through export-db, preserves the backup destination, and adds tests covering the dispatch paths.
Out of Scope Changes check ✅ Passed The changes stay focused on export-db routing and related tests, with no obvious unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/2718-lagoon-export-db

Comment @coderabbitai help to get the list of available commands.

@AlexSkrypnyk AlexSkrypnyk added this to the 1.40.0 milestone Jun 25, 2026
@AlexSkrypnyk AlexSkrypnyk added the A2 Working clone index A2 label Jun 25, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.vortex/tooling/tests/unit/export-db.bats:
- Around line 54-63: The export-db test is not actually exercising Docker-based
host detection because RUN_ON_HOST may still be inherited, and is_host() in
.vortex/tooling/src/export-db will prefer that override first. Update the test
case in export-db.bats to explicitly clear RUN_ON_HOST before running
.vortex/tooling/src/export-db, so the assertion verifies the docker CLI
detection path and the mock_docker expectations remain valid.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 923cc2c6-f4c6-4092-8e01-466925662dcc

📥 Commits

Reviewing files that changed from the base of the PR and between d01b90c and db13a18.

⛔ Files ignored due to path filters (5)
  • .vortex/installer/tests/Fixtures/handler_process/hosting_lagoon/.lagoon.yml is excluded by !.vortex/installer/tests/Fixtures/**
  • .vortex/installer/tests/Fixtures/handler_process/hosting_project_name___lagoon/.lagoon.yml is excluded by !.vortex/installer/tests/Fixtures/**
  • .vortex/installer/tests/Fixtures/handler_process/migration_disabled_lagoon/.lagoon.yml is excluded by !.vortex/installer/tests/Fixtures/**
  • .vortex/installer/tests/Fixtures/handler_process/migration_enabled_lagoon/.lagoon.yml is excluded by !.vortex/installer/tests/Fixtures/**
  • .vortex/installer/tests/Fixtures/handler_process/provision_database_lagoon/.lagoon.yml is excluded by !.vortex/installer/tests/Fixtures/**
📒 Files selected for processing (3)
  • .lagoon.yml
  • .vortex/tooling/src/export-db
  • .vortex/tooling/tests/unit/export-db.bats

Comment on lines +54 to +63
@test "export-db: Detects the host from the Docker CLI when the override is unset" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1

mock_docker=$(mock_command "docker")
mock_set_output "${mock_docker}" "Exported through detected Docker." 1

run .vortex/tooling/src/export-db
assert_success
assert_output_contains "Exported through detected Docker."
assert_equal "1" "$(mock_get_call_num "${mock_docker}")"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Unset RUN_ON_HOST before asserting auto-detection behavior.

This test claims the override is unset, but it never clears RUN_ON_HOST. Since is_host prefers RUN_ON_HOST over docker detection (.vortex/tooling/src/export-db: is_host()), an inherited env var can bypass the path under test.

Suggested patch
 `@test` "export-db: Detects the host from the Docker CLI when the override is unset" {
   pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
 
+  unset RUN_ON_HOST
   mock_docker=$(mock_command "docker")
   mock_set_output "${mock_docker}" "Exported through detected Docker." 1
📝 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
@test "export-db: Detects the host from the Docker CLI when the override is unset" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
mock_docker=$(mock_command "docker")
mock_set_output "${mock_docker}" "Exported through detected Docker." 1
run .vortex/tooling/src/export-db
assert_success
assert_output_contains "Exported through detected Docker."
assert_equal "1" "$(mock_get_call_num "${mock_docker}")"
`@test` "export-db: Detects the host from the Docker CLI when the override is unset" {
pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1
unset RUN_ON_HOST
mock_docker=$(mock_command "docker")
mock_set_output "${mock_docker}" "Exported through detected Docker." 1
run .vortex/tooling/src/export-db
assert_success
assert_output_contains "Exported through detected Docker."
assert_equal "1" "$(mock_get_call_num "${mock_docker}")"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.vortex/tooling/tests/unit/export-db.bats around lines 54 - 63, The
export-db test is not actually exercising Docker-based host detection because
RUN_ON_HOST may still be inherited, and is_host() in
.vortex/tooling/src/export-db will prefer that override first. Update the test
case in export-db.bats to explicitly clear RUN_ON_HOST before running
.vortex/tooling/src/export-db, so the assertion verifies the docker CLI
detection path and the mock_docker expectations remain valid.

@github-actions

Copy link
Copy Markdown

Code coverage (threshold: 90%)

  Classes: 100.00% (1/1)
  Methods: 100.00% (2/2)
  Lines:   98.55% (204/207)
Per-class coverage
Drupal\ys_demo\Plugin\Block\CounterBlock
  Methods: 100.00% ( 2/ 2)   Lines: 100.00% ( 10/ 10)

@AlexSkrypnyk

This comment has been minimized.

2 similar comments
@AlexSkrypnyk

This comment has been minimized.

@AlexSkrypnyk

Copy link
Copy Markdown
Member Author

Code coverage (threshold: 90%)

  Classes: 100.00% (1/1)
  Methods: 100.00% (2/2)
  Lines:   98.55% (204/207)
Per-class coverage
Drupal\ys_demo\Plugin\Block\CounterBlock
  Methods: 100.00% ( 2/ 2)   Lines: 100.00% ( 10/ 10)

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.22%. Comparing base (d01b90c) to head (db13a18).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2724      +/-   ##
==========================================
- Coverage   86.67%   86.22%   -0.45%     
==========================================
  Files          96       89       -7     
  Lines        4719     4560     -159     
  Branches       47        3      -44     
==========================================
- Hits         4090     3932     -158     
+ Misses        629      628       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown

📖 Documentation preview for this pull request has been deployed to Netlify:

https://6a3cb3148470f9d2b9aa1700--vortex-docs.netlify.app

This preview is rebuilt on every commit and is not the production documentation site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A2 Working clone index A2

Projects

Status: Release queue

Development

Successfully merging this pull request may close these issues.

Use 'export-db' for the Lagoon pre-deployment database backup

1 participant