diff --git a/README.md b/README.md index 8829bff..3021fe9 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,9 @@ hostname `live`) is refused by default. | `backup recover` | `--i-understand-this-restores-this-host` (or `BACKUP_CONFIRM_RESTORE=1`), **and** `SHOPWARE_ALLOW_LIVE_RESTORE=1` when `SHOPWARE_DEPLOY_ENV=live` | `backup create` / `backup prune` are allowed on live (that is the cron path). -URL rewrite after apply uses `APP_URL` and is skipped on live. Passwords are +URL rewrite after apply calls Shopware `sales-channel:update:domain` with the +host from `APP_URL` (scheme and path stripped; port is not passed) and is +skipped on live. Passwords are never printed. ## Usage @@ -146,8 +148,9 @@ Identity: `SHOPWARE_SHOP_ID`, `SHOPWARE_DEPLOY_ENV`, optional `SHOPWARE_DATA_BASE` (default `/var/lib/shopware/data`) or `SHOPWARE_DATA_ROOT`. Laptop SSH: `SHOPWARE_SSH_HOST` / `USER` / `KEY` in `.env.local` (host defaults to the `--from` alias). Remote live data: -`SHOPWARE_REMOTE_DATA_ROOT` or `{data_base}/{shop_id}/live`. Rewrite: -`APP_URL`. Live gate: `SHOPWARE_ALLOW_LIVE_RESTORE`. +`SHOPWARE_REMOTE_DATA_ROOT` or `{data_base}/{shop_id}/live`. Rewrite: host +from `APP_URL` via `sales-channel:update:domain`. Live gate: +`SHOPWARE_ALLOW_LIVE_RESTORE`. ### env init diff --git a/docs/ADR-0001-shopware-namespace.md b/docs/ADR-0001-shopware-namespace.md index 68e9c54..6a8668c 100644 --- a/docs/ADR-0001-shopware-namespace.md +++ b/docs/ADR-0001-shopware-namespace.md @@ -36,14 +36,19 @@ Those scripts already call other tools: `deploy/compose.yaml` + `compose.prod.yaml` + `compose.vps.yaml`. Never build images or compile themes in these paths. - **URL rewrite (opt-in after restore):** - `bin/console fyrst:sales-channel:rewrite-urls` via compose `web`. + Shopware `bin/console sales-channel:update:domain ` via compose + `web`. The host is parsed from `APP_URL` (scheme and path stripped; the + port is not passed). Example: `APP_URL=https://staging.example.com` → + `staging.example.com`. Skipped on live, when no dump was imported, and + when `APP_URL` is unset. Not part of bare `db import`. `fyrst-dev/recipes` and `fyrst-dev/shopware-cd` stay the product sources for -those scripts and the console command. This CLI does not become a second -implementation of dump or of `fyrst:sales-channel:rewrite-urls`. It *does* -implement the six overlay operator verbs in-process (including compose -rollout) and it *does* call the MySQL client for import, because no upstream -CLI command exists. +those scripts. This CLI does not become a second implementation of dump or +of sales-channel domain replacement. It calls Shopware +`sales-channel:update:domain` after a non-live DB import and does not +reimplement origin, scheme, or port replacement. It *does* implement the six +overlay operator verbs in-process (including compose rollout) and it *does* +call the MySQL client for import, because no upstream CLI command exists. ## Decision diff --git a/docs/command-matrix.md b/docs/command-matrix.md index 87872a1..7c65ac9 100644 --- a/docs/command-matrix.md +++ b/docs/command-matrix.md @@ -20,7 +20,7 @@ Delegated tools: | **DB import** | **`fyrst-cli shopware db import`** (MySQL/MariaDB client). shopware-cli has no import. | | VPS release | **`fyrst-cli shopware deploy release`** (`docker compose` with `deploy/compose.yaml` + `compose.prod.yaml` + `compose.vps.yaml`) | | VPS rollback | **`fyrst-cli shopware deploy rollback`** (same compose files; `IMAGE_TAG` from `.previous-tag`) | -| Opt-in URL rewrite after restore | `bin/console fyrst:sales-channel:rewrite-urls` via compose `web` | +| Opt-in URL rewrite after restore | `bin/console sales-channel:update:domain ` via compose `web` (host from `APP_URL`; scheme, path, and port omitted) | ## Map @@ -61,9 +61,10 @@ for apply, pull, import, and backup recover (also in `shopware --help`). | `backup recover` | confirm flag (`--i-understand-this-restores-this-host` or `BACKUP_CONFIRM_RESTORE=1`) **and** `SHOPWARE_ALLOW_LIVE_RESTORE=1` when `SHOPWARE_DEPLOY_ENV=live` | | `deploy release` / `deploy rollback` | post-deploy health probe required (`DEPLOY_HEALTH_URL` or `APP_URL`). Ops escape: `--allow-no-deploy-health` or `ALLOW_NO_DEPLOY_HEALTH=1` | -URL rewrite after apply uses `APP_URL` and is **skipped** on live (never -applied). Staging / playground / dev need no extra live flag for backup -recover (still need confirmation). +URL rewrite after apply calls Shopware `sales-channel:update:domain` with +the host from `APP_URL` (scheme and path stripped; port is not passed) and +is **skipped** on live (never applied). Staging / playground / dev need no +extra live flag for backup recover (still need confirmation). ## Shop env files @@ -85,7 +86,7 @@ Data root: `{SHOPWARE_DATA_BASE}/{SHOPWARE_SHOP_ID}/{SHOPWARE_DEPLOY_ENV}` `SHOPWARE_DATA_ROOT`. SSH: `SHOPWARE_SSH_HOST` (defaults to the `--from` alias), `SHOPWARE_SSH_USER`, `SHOPWARE_SSH_KEY`. Port is always `22`. Remote live data: `SHOPWARE_REMOTE_DATA_ROOT` or `{data_base}/{shop_id}/live`. -Rewrite: `APP_URL` only. CI `VPS_*` secrets stay secrets — they are not shop +Rewrite: host from `APP_URL` (`sales-channel:update:domain`). CI `VPS_*` secrets stay secrets — they are not shop `.env`. ## Exact env init CLI @@ -346,7 +347,11 @@ apply (kept for clap compatibility with `sync capture` / `sync pull`). 4. If `--data` includes db: existing import module (`db.sql.gz` then `db.sql`). 5. If rewrite was requested **and** db was restored: `docker compose … run --rm --pull never --entrypoint php web bin/console - fyrst:sales-channel:rewrite-urls …`. If db was skipped, rewrite is skipped. + sales-channel:update:domain `. `` is `APP_URL` with scheme and + path stripped (port is not passed). If db was skipped, or `APP_URL` is + unset, rewrite is skipped. Not run when `SHOPWARE_DEPLOY_ENV` is live + (`SHOPWARE_ALLOW_LIVE_RESTORE` does not enable it). Not part of bare + `db import`. 6. Restore selected bind-mount items into `SHOPWARE_DATA_ROOT` or derived `$SHOPWARE_DATA_BASE/$SHOPWARE_SHOP_ID/$SHOPWARE_DEPLOY_ENV` (`SHOPWARE_DATA_BASE` defaults to `/var/lib/shopware/data`). Prefer rsync @@ -355,7 +360,9 @@ apply (kept for clap compatibility with `sync capture` / `sync pull`). 7. Start previously stopped app services. 8. Non-fatal `cache:clear` when `IMAGE` is set; hints when rewrite was off. -Passwords are never logged. Rewrite is not a Rust SQL rewriter. +Passwords are never logged. Rewrite is not a Rust SQL rewriter. The CLI +passes the `APP_URL` host to Shopware `sales-channel:update:domain` and does +not replace scheme, port, or path itself. ## `shopware sync capture` (volumes implemented; not a dump) @@ -410,9 +417,11 @@ dev). Typical cron: `--from live --data all`. operator instructions to run `shopware-cli project dump` on the source and place `db.sql.gz` for import (`fyrst-cli shopware db import --file` is the same module). `--skip-db` skips this leg. -5. `fyrst:sales-channel:rewrite-urls` when `APP_URL` is set **and** a dump - was imported on a non-live consumer. Skipped when `--skip-db` / no dump - imported / live. +5. `sales-channel:update:domain ` when `APP_URL` is set **and** a dump + was imported on a non-live consumer. `` is the `APP_URL` host + (scheme and path stripped; port is not passed). Skipped when `--skip-db` / + no dump imported / live / `APP_URL` unset. `SHOPWARE_ALLOW_LIVE_RESTORE` + does not enable it. Not part of bare `db import`. 6. Volume leg: rsync `SHOPWARE_REMOTE_DATA_ROOT//` (or derived `{data_base}/{shop_id}/live`) → local `$DATA_ROOT//` (tar/docker fallback if rsync cannot write), then `chown 82:82`. `--dry-run` prints diff --git a/src/cli.rs b/src/cli.rs index 3ebd0be..9cf064c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -43,7 +43,7 @@ env init = fyrst-cli shopware env init (shop-root .env after create + Flex). Release = fyrst-cli shopware deploy release (VPS compose; never builds). Rollback = fyrst-cli shopware deploy rollback (IMAGE_TAG from .previous-tag). sync capture = bind-mount trees into --snapshot-dir (not a dump). -sync apply also restores bind-mount volumes and opt-in rewrite via compose web. +sync apply also restores bind-mount volumes and opt-in sales-channel:update:domain via compose web. sync pull = rsync remote bind-mounts + import of an already-present dump (does not dump). sync local = VPS → local project-dev rsync (never DB; not SHOPWARE_DATA_ROOT; --data all refused). Backup = fyrst-cli shopware backup create (volumes + operator db.sql.gz; live allowed). @@ -76,7 +76,7 @@ Database dumps are owned by `shopware-cli project dump`; fyrst-cli does not wrap `shopware deploy rollback` re-deploys IMAGE using IMAGE_TAG from `.previous-tag`. \ `shopware sync capture` copies bind-mount / volume trees; it is not a dump command. \ `shopware sync apply` loads --snapshot-dir (same import module, bind-mount volumes, \ -opt-in rewrite via compose web). \ +opt-in sales-channel:update:domain via compose web). \ `shopware sync pull` pulls from `--from` (rsync bind-mounts + import of an already-present dump) and does not dump. \ `shopware sync local` rsyncs VPS upload trees into a local project-dev checkout (never DB). \ `shopware backup create` copies bind-mount trees into BACKUP_TARGET (live allowed) \ @@ -115,7 +115,7 @@ plan and does not write. Passwords are never printed.\n\n\ `db import` is implemented: MySQL/MariaDB client import (Compose `mysql` exec, else a \ one-shot client image for DATABASE_URL). `sync apply` uses that same import module, \ restores bind-mount volumes from --snapshot-dir, stops/starts web/worker/scheduler, and \ -runs opt-in `bin/console fyrst:sales-channel:rewrite-urls` via compose `web`. \ +runs opt-in `bin/console sales-channel:update:domain` (host from `APP_URL`, scheme and path stripped, port omitted) via compose `web`. \ `sync pull` is the cron/operator pull path: rsync remote bind-mounts onto this host, then \ import `db.sql.gz` from `--snapshot-dir` if `--data` includes db (does not dump). \ `--from local` is a capture+apply pipeline check, not the staging cron path. \ diff --git a/src/shopware/restore.rs b/src/shopware/restore.rs index d322acc..6d55960 100644 --- a/src/shopware/restore.rs +++ b/src/shopware/restore.rs @@ -1,8 +1,9 @@ //! `fyrst-cli shopware sync apply` — DB import plus bind-mount volumes and -//! post-apply orchestration (stop/start, APP_URL rewrite, cache:clear hint). +//! post-apply orchestration (stop/start, APP_URL domain update, cache:clear hint). //! -//! Database import is the same module as `shopware db import`. Rewrite is -//! `bin/console fyrst:sales-channel:rewrite-urls` via compose `web`, not SQL. +//! Database import is the same module as `shopware db import`. Domain update is +//! `bin/console sales-channel:update:domain ` via compose `web`, not SQL. +//! `` is parsed from `APP_URL` (scheme and path stripped; port is not passed). use super::data::{normalize_data, DataSelection}; use super::env::{ @@ -17,7 +18,7 @@ use super::mysql::{ }; use super::rewrite::{ compose_rewrite_args, rewrite_log_line, rewrite_requested, should_rewrite, skip_live_log, - skip_without_db_log, + skip_without_db_log, DOMAIN_COMMAND, UPDATE_DOMAIN_FAILED, }; use super::volumes::{archive_image, execute_bind_restore, plan_bind_restore, VolumeRestore}; use crate::cli::SyncOpArgs; @@ -163,8 +164,8 @@ pub fn plan_with_env( RewriteAction::SkipNoDb } else { RewriteAction::Run { - docker_args: compose_rewrite_args(env, &compose_dir, dry_run), - log_line: rewrite_log_line(env, &compose_dir, dry_run), + docker_args: compose_rewrite_args(env, &compose_dir)?, + log_line: rewrite_log_line(env, &compose_dir)?, } }; @@ -238,7 +239,7 @@ pub fn execute(plan: &RestorePlan) -> Result<(), Error> { log_line, } => { println!( - "==> Opt-in sales_channel_domain rewrite via fyrst:sales-channel:rewrite-urls (sales channel domains only; media CDN / plugin configs / payment webhooks are not updated)" + "==> Opt-in sales_channel_domain rewrite via {DOMAIN_COMMAND} (sales channel domains only; media CDN / plugin configs / payment webhooks are not updated)" ); if plan.log_contains_secret(log_line) { return Err(Error::fail( @@ -291,9 +292,7 @@ fn run_rewrite(compose_dir: &Path, docker_args: &[String]) -> Result<(), Error> if status.success() { Ok(()) } else { - Err(Error::fail( - "fyrst:sales-channel:rewrite-urls failed. composer update fyrst/shopware-cd so the command and FyrstShopwareCdBundle exist, then composer recipes:update fyrst/shopware-cd.", - )) + Err(Error::fail(UPDATE_DOMAIN_FAILED)) } } @@ -674,7 +673,7 @@ mod tests { fn rewrite_run_is_compose_console_when_db_restored() { let shop = TempShop::new("rewrun"); shop.write_env( - "SHOPWARE_SHOP_ID=acme\nSHOPWARE_DEPLOY_ENV=staging\nAPP_URL=https://staging.example.com\nMYSQL_USER=u\nMYSQL_PASSWORD=s3cret-value\n", + "SHOPWARE_SHOP_ID=acme\nSHOPWARE_DEPLOY_ENV=staging\nAPP_URL=https://staging.example.com:8443/de\nMYSQL_USER=u\nMYSQL_PASSWORD=s3cret-value\n", ); shop.write_compose_mysql(); shop.write_dump(); @@ -685,16 +684,43 @@ mod tests { docker_args, } => { assert!( - log_line.contains("fyrst:sales-channel:rewrite-urls"), + log_line.contains("sales-channel:update:domain"), "{log_line}" ); + assert!(log_line.contains(" staging.example.com"), "{log_line}"); assert!( log_line.contains("run --rm --pull never --entrypoint php"), "{log_line}" ); - assert!(log_line.contains("--dry-run"), "{log_line}"); assert!(!log_line.contains("s3cret-value"), "{log_line}"); - assert!(docker_args.contains(&"fyrst:sales-channel:rewrite-urls".to_string())); + assert!(!log_line.contains(":8443"), "{log_line}"); + assert!(!log_line.contains("/de"), "{log_line}"); + assert!(!log_line.contains("https://"), "{log_line}"); + for gone in [ + "--app-url", + "--deploy-env", + "--sync-env", + "--checkout-basename", + "--dry-run", + "fyrst:sales-channel:rewrite-urls", + "sales-channel:replace:url", + "composer update fyrst/shopware-cd", + ] { + assert!(!log_line.contains(gone), "{gone} in {log_line}"); + assert!( + !docker_args.iter().any(|a| a.contains(gone)), + "{gone} in {docker_args:?}" + ); + } + let cmd_at = docker_args + .iter() + .position(|a| a == "sales-channel:update:domain") + .unwrap_or_else(|| panic!("{docker_args:?}")); + assert_eq!( + docker_args.get(cmd_at + 1).map(String::as_str), + Some("staging.example.com") + ); + assert_eq!(docker_args.len(), cmd_at + 2); assert!(!docker_args .iter() .any(|a| a == "-p" || a == "--project-name")); diff --git a/src/shopware/rewrite.rs b/src/shopware/rewrite.rs index ed85088..f15c5fc 100644 --- a/src/shopware/rewrite.rs +++ b/src/shopware/rewrite.rs @@ -1,7 +1,9 @@ -//! Sales-channel URL rewrite after restore. +//! Sales-channel domain update after a non-live DB import. //! -//! Target URL is `APP_URL`. On live, rewrite is skipped (APP_URL is a shop -//! runtime var, not a restore opt-in — refusing it would block live DR). +//! Shopware `sales-channel:update:domain` takes the new host. The host is +//! parsed from `APP_URL` (scheme and path stripped; port is not passed). +//! On live, the command is skipped (`APP_URL` is a shop runtime var, not a +//! restore opt-in — refusing it would block live DR). use super::env::{existing_compose_files, ShopEnv}; use super::error::Error; @@ -10,6 +12,11 @@ use super::mysql::{compose_argv, compose_cli_log, require_docker}; use std::path::Path; use std::process::Command; +pub const DOMAIN_COMMAND: &str = "sales-channel:update:domain"; + +/// Shown when the console command exits non-zero. Shopware ships this command. +pub const UPDATE_DOMAIN_FAILED: &str = "sales-channel:update:domain failed."; + pub fn rewrite_app_url(env: &ShopEnv) -> Option<&str> { env.get("APP_URL") } @@ -18,7 +25,7 @@ pub fn rewrite_requested(env: &ShopEnv) -> bool { rewrite_app_url(env).is_some() } -/// Rewrite never runs on live. Returns Ok so restore/DR can continue. +/// Domain update never runs on live. Returns Ok so restore/DR can continue. pub fn assert_not_live_rewrite(signals: &LiveSignals) -> Result<(), Error> { if !signals.is_live() { return Ok(()); @@ -30,30 +37,67 @@ pub fn should_rewrite(env: &ShopEnv, signals: &LiveSignals) -> bool { rewrite_requested(env) && !signals.is_live() } -pub fn console_flag_args(env: &ShopEnv, checkout: &str, dry_run: bool) -> Vec { - let mut args = Vec::new(); - if let Some(url) = rewrite_app_url(env) { - args.push(format!("--app-url={url}")); +/// Host argument for `sales-channel:update:domain`. +/// +/// Scheme, userinfo, port, path, query, and fragment are not passed. +/// `https://staging.example.com` and `https://staging.example.com:8443/en` +/// both become `staging.example.com`. +pub fn app_url_host(app_url: &str) -> Option { + let url = app_url.trim(); + if url.is_empty() { + return None; } - args.push(format!( - "--deploy-env={}", - env.get("SHOPWARE_DEPLOY_ENV").unwrap_or("") - )); - args.push(format!( - "--sync-env={}", - env.get("SHOPWARE_DEPLOY_ENV").unwrap_or("") - )); - args.push(format!("--checkout-basename={checkout}")); - if dry_run { - args.push("--dry-run".into()); + let after_scheme = match url.split_once("://") { + Some((scheme, rest)) => { + if scheme.is_empty() || rest.is_empty() { + return None; + } + rest + } + None => url, + }; + let authority = after_scheme.split(['/', '?', '#']).next().unwrap_or(""); + if authority.is_empty() { + return None; + } + let authority = match authority.rsplit_once('@') { + Some((_, hostport)) => hostport, + None => authority, + }; + if authority.is_empty() { + return None; + } + let host = if let Some(rest) = authority.strip_prefix('[') { + let end = rest.find(']')?; + let host = &rest[..end]; + if host.is_empty() { + return None; + } + host + } else { + match authority.split_once(':') { + Some((host, _)) => host, + None => authority, + } + }; + if host.is_empty() { + None + } else { + Some(host.to_string()) } - args } -pub fn compose_rewrite_args(env: &ShopEnv, compose_dir: &Path, dry_run: bool) -> Vec { - let files = existing_compose_files(compose_dir); - let checkout = super::live::shop_basename(compose_dir); - let mut args = compose_argv(compose_dir, &files); +pub fn domain_host(env: &ShopEnv) -> Result { + let url = rewrite_app_url(env) + .ok_or_else(|| Error::fail("APP_URL is unset; cannot run sales-channel:update:domain."))?; + app_url_host(url).ok_or_else(|| { + Error::fail(format!( + "APP_URL has no host for sales-channel:update:domain ({url}). The argument is the host only: scheme and path are stripped, and the port is not passed." + )) + }) +} + +fn push_domain_command(args: &mut Vec, host: &str) { args.extend([ "run".into(), "--rm".into(), @@ -63,21 +107,26 @@ pub fn compose_rewrite_args(env: &ShopEnv, compose_dir: &Path, dry_run: bool) -> "php".into(), "web".into(), "bin/console".into(), - "fyrst:sales-channel:rewrite-urls".into(), + DOMAIN_COMMAND.into(), ]); - args.extend(console_flag_args(env, &checkout, dry_run)); - args + args.push(host.to_string()); } -pub fn rewrite_log_line(env: &ShopEnv, compose_dir: &Path, dry_run: bool) -> String { +pub fn compose_rewrite_args(env: &ShopEnv, compose_dir: &Path) -> Result, Error> { let files = existing_compose_files(compose_dir); - let checkout = super::live::shop_basename(compose_dir); - let flags = console_flag_args(env, &checkout, dry_run); - format!( - "{} run --rm --pull never --entrypoint php web bin/console fyrst:sales-channel:rewrite-urls {}", + let host = domain_host(env)?; + let mut args = compose_argv(compose_dir, &files); + push_domain_command(&mut args, &host); + Ok(args) +} + +pub fn rewrite_log_line(env: &ShopEnv, compose_dir: &Path) -> Result { + let files = existing_compose_files(compose_dir); + let host = domain_host(env)?; + Ok(format!( + "{} run --rm --pull never --entrypoint php web bin/console {DOMAIN_COMMAND} {host}", compose_cli_log(compose_dir, &files), - flags.join(" ") - ) + )) } /// Names used by `shopware sync pull` (same predicates as restore). @@ -117,30 +166,14 @@ pub fn maybe_rewrite( return Ok(()); } println!( - "==> Sales_channel_domain rewrite via fyrst:sales-channel:rewrite-urls from APP_URL (sales channel domains only; media CDN / plugin configs / payment webhooks are not updated)" + "==> Sales_channel_domain rewrite via {DOMAIN_COMMAND} from APP_URL (sales channel domains only; media CDN / plugin configs / payment webhooks are not updated)" ); if files.is_empty() { return Err(Error::fail( - "No compose files found under shop root; cannot run fyrst:sales-channel:rewrite-urls.", + "No compose files found under shop root; cannot run sales-channel:update:domain.", )); } - let checkout = super::live::shop_basename(compose_dir); - let args = { - let mut a = compose_argv(compose_dir, files); - a.extend([ - "run".into(), - "--rm".into(), - "--pull".into(), - "never".into(), - "--entrypoint".into(), - "php".into(), - "web".into(), - "bin/console".into(), - "fyrst:sales-channel:rewrite-urls".into(), - ]); - a.extend(console_flag_args(env, &checkout, dry_run)); - a - }; + let args = compose_rewrite_args(env, compose_dir)?; if dry_run { println!("==> DRY-RUN docker {}", args.join(" ")); return Ok(()); @@ -152,9 +185,7 @@ pub fn maybe_rewrite( .status() .map_err(|e| Error::fail(format!("could not exec docker compose rewrite: {e}")))?; if !status.success() { - return Err(Error::fail( - "fyrst:sales-channel:rewrite-urls failed. composer update fyrst/shopware-cd so the command and FyrstShopwareCdBundle exist, then composer recipes:update fyrst/shopware-cd.", - )); + return Err(Error::fail(UPDATE_DOMAIN_FAILED)); } Ok(()) } @@ -174,6 +205,22 @@ mod tests { ShopEnv::from_vars(PathBuf::from("/shops/acme-staging"), vars) } + fn assert_no_legacy_flags(joined: &str) { + for gone in [ + "--app-url", + "--deploy-env", + "--sync-env", + "--checkout-basename", + "--dry-run", + "--map", + "sales-channel:replace:url", + "fyrst:sales-channel:rewrite-urls", + "composer update fyrst/shopware-cd", + ] { + assert!(!joined.contains(gone), "{gone} in {joined}"); + } + } + #[test] fn requested_only_when_app_url_set() { assert!(!rewrite_requested(&env_from(&[]))); @@ -184,37 +231,66 @@ mod tests { } #[test] - fn console_args_omit_dry_run_when_off() { + fn host_strips_scheme_path_and_port() { + assert_eq!( + app_url_host("https://staging.example.com").as_deref(), + Some("staging.example.com") + ); + assert_eq!( + app_url_host("https://staging.example.com/").as_deref(), + Some("staging.example.com") + ); + assert_eq!( + app_url_host("https://staging.example.com/de").as_deref(), + Some("staging.example.com") + ); + assert_eq!( + app_url_host("https://staging.example.com:8443/en?x=1").as_deref(), + Some("staging.example.com") + ); + assert_eq!( + app_url_host("http://localhost:8000").as_deref(), + Some("localhost") + ); + assert_eq!( + app_url_host("https://user:pass@staging.example.com:8443/shop").as_deref(), + Some("staging.example.com") + ); + assert_eq!(app_url_host(" ").as_deref(), None); + assert_eq!(app_url_host("https://").as_deref(), None); + } + + #[test] + fn console_args_are_command_plus_host_only() { let env = env_from(&[ - ("APP_URL", "https://staging.example.com"), + ("APP_URL", "https://staging.example.com:8443/de"), ("SHOPWARE_DEPLOY_ENV", "staging"), ]); - let args = console_flag_args(&env, "acme-staging", false); + let args = compose_rewrite_args(&env, Path::new("/shops/acme-staging")).unwrap(); let joined = args.join(" "); - assert!(!args.iter().any(|a| a == "--dry-run"), "{joined}"); - assert!( - joined.contains("--app-url=https://staging.example.com"), - "{joined}" - ); - assert!(joined.contains("--deploy-env=staging"), "{joined}"); - assert!(joined.contains("--sync-env=staging"), "{joined}"); + let cmd_at = args + .iter() + .position(|a| a == DOMAIN_COMMAND) + .expect(&joined); + assert!(cmd_at > 0, "{joined}"); + assert_eq!(args[cmd_at - 1], "bin/console"); + assert_eq!(args[cmd_at + 1], "staging.example.com"); + assert_eq!(args.len(), cmd_at + 2, "{joined}"); assert!( - joined.contains("--checkout-basename=acme-staging"), + joined.contains("run --rm --pull never --entrypoint php web bin/console"), "{joined}" ); - assert!(!joined.contains("--map="), "{joined}"); + assert!(!joined.contains(":8443"), "{joined}"); + assert!(!joined.contains("https://"), "{joined}"); + assert!(!joined.contains("/de"), "{joined}"); + assert_no_legacy_flags(&joined); } #[test] - fn console_args_add_dry_run() { - let env = env_from(&[("APP_URL", "https://staging.example.com")]); - let args = console_flag_args(&env, "acme-staging", true); - let joined = args.join(" "); - assert!(args.iter().any(|a| a == "--dry-run"), "{joined}"); - assert!( - joined.contains("--app-url=https://staging.example.com"), - "{joined}" - ); + fn failure_text_does_not_ask_for_shopware_cd_update() { + assert!(!UPDATE_DOMAIN_FAILED.contains("composer update fyrst/shopware-cd")); + assert!(!UPDATE_DOMAIN_FAILED.contains("fyrst:sales-channel:rewrite-urls")); + assert!(UPDATE_DOMAIN_FAILED.contains(DOMAIN_COMMAND)); } #[test] @@ -225,8 +301,9 @@ mod tests { ("SHOPWARE_DEPLOY_ENV", "staging"), ("COMPOSE_PROJECT_NAME", "shopware-acme"), ]); - let line = rewrite_log_line(&env, Path::new("/shops/acme-staging"), true); - assert!(line.contains("fyrst:sales-channel:rewrite-urls"), "{line}"); + let line = rewrite_log_line(&env, Path::new("/shops/acme-staging")).unwrap(); + assert!(line.contains(DOMAIN_COMMAND), "{line}"); + assert!(line.contains(" staging.example.com"), "{line}"); assert!( line.contains("run --rm --pull never --entrypoint php"), "{line}" @@ -239,15 +316,15 @@ mod tests { "{line}" ); assert!(!line.contains("shopware-acme"), "{line}"); - assert!(line.contains("--dry-run"), "{line}"); assert!( !line.to_ascii_lowercase().contains("update sales_channel"), "{line}" ); - let args = compose_rewrite_args(&env, Path::new("/shops/acme-staging"), false); - assert!(args.contains(&"fyrst:sales-channel:rewrite-urls".to_string())); + assert_no_legacy_flags(&line); + let args = compose_rewrite_args(&env, Path::new("/shops/acme-staging")).unwrap(); + assert!(args.contains(&DOMAIN_COMMAND.to_string())); + assert_eq!(args.last().map(String::as_str), Some("staging.example.com")); assert!(!args.iter().any(|a| a == "-p" || a == "--project-name")); - assert!(!args.iter().any(|a| a == "--dry-run")); } #[test] @@ -270,11 +347,12 @@ mod tests { ("SHOPWARE_SHOP_ID", "acme"), ("SHOPWARE_DEPLOY_ENV", "staging"), ]); - let args = compose_rewrite_args(&env, &dir, false); + let args = compose_rewrite_args(&env, &dir).unwrap(); assert!(args.windows(2).any(|w| w == ["--env-file", ".env"])); assert!(args.windows(2).any(|w| w == ["--env-file", ".env.local"])); assert!(args.windows(2).any(|w| w == ["-f", "deploy/compose.yaml"])); assert!(!args.iter().any(|a| a == "-p" || a == "--project-name")); + assert_eq!(args.last().map(String::as_str), Some("staging.example.com")); let _ = std::fs::remove_dir_all(&dir); } diff --git a/tests/restore.rs b/tests/restore.rs index 62c11ca..34fe66e 100644 --- a/tests/restore.rs +++ b/tests/restore.rs @@ -148,6 +148,7 @@ fn volume_dry_run_prints_rsync_plan() { "{log}" ); assert!(!log.contains("fyrst:sales-channel:rewrite-urls"), "{log}"); + assert!(!log.contains("sales-channel:update:domain"), "{log}"); } #[test] @@ -226,6 +227,10 @@ fn rewrite_skipped_when_skip_db() { !log.contains("fyrst:sales-channel:rewrite-urls"), "must not run rewrite when db skipped:\n{log}" ); + assert!( + !log.contains("sales-channel:update:domain"), + "must not run domain update when db skipped:\n{log}" + ); } #[test] @@ -265,6 +270,10 @@ SHOPWARE_DATA_ROOT={} !log.contains("fyrst:sales-channel:rewrite-urls"), "must not run rewrite on live:\n{log}" ); + assert!( + !log.contains("sales-channel:update:domain"), + "must not run domain update on live:\n{log}" + ); let combined = format!("{log}{}", stderr(&out)); assert!(!combined.contains("super-secret-pass"), "{combined}"); } @@ -282,15 +291,20 @@ fn rewrite_dry_run_is_compose_console() { let log = stdout(&out); let combined = format!("{log}{}", stderr(&out)); assert!(!combined.contains("super-secret-pass"), "{combined}"); - assert!(log.contains("fyrst:sales-channel:rewrite-urls"), "{log}"); + assert!(log.contains("sales-channel:update:domain"), "{log}"); + assert!(log.contains(" staging.example.com"), "{log}"); assert!( log.contains("run --rm --pull never --entrypoint php"), "{log}" ); - assert!( - log.contains("--app-url=https://staging.example.com"), - "{log}" - ); + assert!(!log.contains("https://staging.example.com"), "{log}"); + assert!(!log.contains("fyrst:sales-channel:rewrite-urls"), "{log}"); + assert!(!log.contains("--app-url"), "{log}"); + assert!(!log.contains("--deploy-env"), "{log}"); + assert!(!log.contains("--sync-env"), "{log}"); + assert!(!log.contains("--checkout-basename"), "{log}"); + assert!(!log.contains("sales-channel:replace:url"), "{log}"); + assert!(!log.contains("composer update fyrst/shopware-cd"), "{log}"); assert!( !log.to_ascii_lowercase().contains("update sales_channel"), "{log}" diff --git a/tests/sync.rs b/tests/sync.rs index 5170640..00d8b57 100644 --- a/tests/sync.rs +++ b/tests/sync.rs @@ -416,6 +416,8 @@ fn rewrite_skipped_on_live_even_with_allow() { "{}", stdout(&out) ); + assert!(!all.contains("sales-channel:update:domain"), "{all}"); + assert!(!all.contains("fyrst:sales-channel:rewrite-urls"), "{all}"); } #[test] @@ -452,6 +454,60 @@ fn rewrite_skipped_when_skip_db() { assert!(log.contains("db was skipped"), "{log}"); assert!(log.contains("DRY-RUN rsync -az --delete"), "{log}"); assert!(!log.contains("fyrst:sales-channel:rewrite-urls"), "{log}"); + assert!(!log.contains("sales-channel:update:domain"), "{log}"); +} + +#[test] +fn rewrite_dry_run_calls_native_domain_command() { + let shop = TempShop::new("rw-run"); + shop.write_staging(); + fs::write( + shop.path().join(".env"), + format!( + "{}\nAPP_URL=https://staging.example.com\n", + fs::read_to_string(shop.path().join(".env")).unwrap().trim() + ), + ) + .unwrap(); + fs::write(shop.path().join("var/runtime-sync/db.sql"), b"SELECT 1;\n").unwrap(); + let out = sync_cmd( + shop.path(), + &[ + "--dry-run", + "--from", + "live", + "--data", + "db", + "--skip-volumes", + ], + ); + assert_eq!( + out.status.code(), + Some(0), + "stderr={} stdout={}", + stderr(&out), + stdout(&out) + ); + let log = stdout(&out); + assert!(log.contains("sales-channel:update:domain"), "{log}"); + assert!(log.contains(" staging.example.com"), "{log}"); + assert!( + log.contains("run --rm --pull never --entrypoint php"), + "{log}" + ); + assert!(!log.contains("https://staging.example.com"), "{log}"); + assert!(!log.contains("fyrst:sales-channel:rewrite-urls"), "{log}"); + assert!(!log.contains("--app-url"), "{log}"); + assert!(!log.contains("--deploy-env"), "{log}"); + assert!(!log.contains("--sync-env"), "{log}"); + assert!(!log.contains("--checkout-basename"), "{log}"); + assert!(!log.contains("sales-channel:replace:url"), "{log}"); + assert!(!log.contains("composer update fyrst/shopware-cd"), "{log}"); + assert!( + !combined(&out).contains("super-secret-pass"), + "{}", + combined(&out) + ); } #[test]