Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
17 changes: 11 additions & 6 deletions docs/ADR-0001-shopware-namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <host>` 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

Expand Down
29 changes: 19 additions & 10 deletions docs/command-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <host>` via compose `web` (host from `APP_URL`; scheme, path, and port omitted) |

## Map

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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 <host>`. `<host>` 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
Expand All @@ -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)

Expand Down Expand Up @@ -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 <host>` when `APP_URL` is set **and** a dump
was imported on a non-live consumer. `<host>` 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/<item>/` (or derived
`{data_base}/{shop_id}/live`) → local `$DATA_ROOT/<item>/` (tar/docker
fallback if rsync cannot write), then `chown 82:82`. `--dry-run` prints
Expand Down
6 changes: 3 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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) \
Expand Down Expand Up @@ -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. \
Expand Down
54 changes: 40 additions & 14 deletions src/shopware/restore.rs
Original file line number Diff line number Diff line change
@@ -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 <host>` via compose `web`, not SQL.
//! `<host>` is parsed from `APP_URL` (scheme and path stripped; port is not passed).

use super::data::{normalize_data, DataSelection};
use super::env::{
Expand All @@ -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;
Expand Down Expand Up @@ -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)?,
}
};

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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();
Expand All @@ -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"));
Expand Down
Loading
Loading