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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,17 @@ fyrst-cli shopware deploy rollback --dry-run
fyrst-cli shopware deploy rollback --skip-pull
```

On live smoke failure, release prints
After a successful compose recreate, release/rollback GET a health URL
(`curl -fsS`, 30 attempts, 2s sleep). Default probe: `APP_URL` with trailing
slash stripped + `/api/_info/health-check`. Override with `DEPLOY_HEALTH_URL`
(full URL, used as-is). Live (`SHOPWARE_DEPLOY_ENV=live`) requires a probe URL;
ops escape only: `--allow-no-deploy-health` or `ALLOW_NO_DEPLOY_HEALTH=1`.
Non-live skips the probe when no URL can be resolved.

On live deploy-health failure, release prints
`IMAGE_TAG=$(cat .previous-tag) fyrst-cli shopware deploy rollback` and may
auto-rollback; it still exits 1. Live with empty `COMPOSE_PROFILES` warns
auto-rollback (`ROLLBACK_ON_FAIL`; unset → on for live); it still
exits 1. Live with empty `COMPOSE_PROFILES` warns
(recommended: `redis,worker,scheduler`).

### sync capture / apply / pull / local
Expand Down
39 changes: 24 additions & 15 deletions docs/command-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ those scripts. Use the CLI column.
| Historical overlay (removed) | CLI | Nested verbs | Flags | Status |
| --- | --- | --- | --- | --- |
| `deploy/init-env.sh` | `fyrst-cli shopware env init` | `init` | `--shop-id`, `--env`, `--image`, `--dry-run` | **implemented** |
| `deploy/vps-release.sh` | `fyrst-cli shopware deploy release` | `release` | `--dry-run`, `--skip-pull` | **implemented** |
| `deploy/vps-rollback.sh` | `fyrst-cli shopware deploy rollback` | `rollback` | `--dry-run`, `--skip-pull` | **implemented** |
| `deploy/vps-release.sh` | `fyrst-cli shopware deploy release` | `release` | `--dry-run`, `--skip-pull`, `--allow-no-deploy-health` | **implemented** |
| `deploy/vps-rollback.sh` | `fyrst-cli shopware deploy rollback` | `rollback` | `--dry-run`, `--skip-pull`, `--allow-no-deploy-health` | **implemented** |
| `restore_db_*` (sync-runtime) | `fyrst-cli shopware db import` | `import` | `--file`, `--dry-run`, `--allow-live` | **implemented** |
| `deploy/sync-runtime.sh` snapshot | `fyrst-cli shopware sync capture` | `capture` | `--from`, `--data`, `--snapshot-dir`, `--dry-run`, `--skip-db`, `--skip-volumes` | **volumes implemented** (bind-mount trees → `--snapshot-dir/data/<item>/`; named-volume tar fallback). **Not a dump command:** `--data db` exits 2 and tells operators to run `shopware-cli project dump` |
| `deploy/sync-runtime.sh` restore | `fyrst-cli shopware sync apply` | `apply` | same flags | **implemented**: DB via same import module; bind-mount volumes from `data/<item>/` or `volumes/<item>.tar.gz`; stop/start `web`/`worker`/`scheduler`; rewrite from `APP_URL` via compose `web`; live refuse unless `SHOPWARE_ALLOW_LIVE_RESTORE=1`; rewrite skipped on live |
Expand Down Expand Up @@ -59,6 +59,7 @@ for apply, pull, import, and backup recover (also in `shopware --help`).
| `sync apply` | `SHOPWARE_ALLOW_LIVE_RESTORE=1` only |
| `sync pull` | `SHOPWARE_ALLOW_LIVE_RESTORE=1` only |
| `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
Expand Down Expand Up @@ -96,7 +97,7 @@ fyrst-cli shopware env init [--shop-id SLUG] [--env live|staging|playground|dev]
## Exact deploy release CLI

```text
fyrst-cli shopware deploy release [--dry-run] [--skip-pull]
fyrst-cli shopware deploy release [--dry-run] [--skip-pull] [--allow-no-deploy-health]
```

## `shopware deploy release` (implemented)
Expand Down Expand Up @@ -125,11 +126,16 @@ compile flags stay in the setup helper image.
4. One-shot `--profile setup run --rm --pull never setup`.
5. `up -d --no-build` (optional `--pull never`) `--remove-orphans web`.
6. Extra `COMPOSE_PROFILES` (must not include `setup`).
7. Optional `SMOKE_URL` (curl, 30 attempts). Write `.deployed-tag` only after
setup/web succeed and smoke passes.
8. On smoke failure: print
7. Post-deploy health probe (`curl -fsS`, 30 attempts, 2s sleep). Default URL:
`APP_URL` with trailing slash stripped + `/api/_info/health-check`. Override
with `DEPLOY_HEALTH_URL` (full URL, used as-is). Write `.deployed-tag` only after
setup/web succeed and the probe passes (or is skipped).
Live (`SHOPWARE_DEPLOY_ENV=live`) **requires** a probe URL; refuse before
mutating unless `--allow-no-deploy-health` / `ALLOW_NO_DEPLOY_HEALTH=1` (ops
escape only). Non-live skips the probe when no URL can be resolved.
8. On deploy-health failure: print
`IMAGE_TAG=$(cat .previous-tag) fyrst-cli shopware deploy rollback`. Auto-run the
shared rollout helper at the previous tag when `ROLLBACK_ON_SMOKE_FAIL` is
shared rollout helper at the previous tag when `ROLLBACK_ON_FAIL` is
on (unset → **on for live**, off otherwise). Release still **exits 1** after
a successful auto-rollback. First deploy with no `.previous-tag` cannot
auto-rollback.
Expand All @@ -140,8 +146,9 @@ compile flags stay in the setup helper image.
Loud warning (does not auto-enable) when `SHOPWARE_DEPLOY_ENV=live` and
`COMPOSE_PROFILES` is empty. Recommended live: `redis,worker,scheduler`.

Passwords / `DATABASE_URL` are never logged. Auto-rollback on smoke uses the
shared compose/rollout helper (`fyrst-cli shopware deploy rollback`).
Passwords / `DATABASE_URL` are never logged. Auto-rollback on deploy-health
failure uses the shared compose/rollout helper
(`fyrst-cli shopware deploy rollback`).


## Exact import CLI
Expand Down Expand Up @@ -214,13 +221,13 @@ passwords).
## Exact deploy rollback CLI

```text
fyrst-cli shopware deploy rollback [--dry-run] [--skip-pull]
fyrst-cli shopware deploy rollback [--dry-run] [--skip-pull] [--allow-no-deploy-health]
```

## `shopware deploy rollback` (implemented)

Resolves shop root (`COMPOSE_DIR` or walk from cwd for `.env` + `deploy/`),
loads `.env` then `.env.local` then `.env.prod`. Process-env wins for `IMAGE`, `SMOKE_URL`,
loads `.env` then `.env.local` then `.env.prod`. Process-env wins for `IMAGE`, `DEPLOY_HEALTH_URL`,
`COMPOSE_PROFILES`, `SKIP_PULL`, `PULL_POLICY` when non-empty. **`IMAGE_TAG`
from the process environment is ignored** — the only tag is shop-root
`.previous-tag` (overlay `vps_read_previous_tag`). Missing or empty
Expand All @@ -239,8 +246,10 @@ Rollout order reuses the release compose/rollout helper (never `--build`;
3. One-shot `compose --profile setup run --rm --pull never setup`.
4. `up -d --no-build` (optional `--pull never`) `--remove-orphans web`.
5. Extra `COMPOSE_PROFILES` (must not include `setup`).
6. Optional `SMOKE_URL`. Write `.deployed-tag` **only after** success (and
smoke, if set). Smoke failure does not update `.deployed-tag`.
6. Post-deploy health probe (same URL rules as release). Write `.deployed-tag`
**only after** success (and the probe, if a URL was resolved). Probe failure
does not update `.deployed-tag`. Live requires a probe URL unless the ops
escape `--allow-no-deploy-health` / `ALLOW_NO_DEPLOY_HEALTH=1` is set.

`--dry-run` prints that sequence and does not pull or recreate containers.
`--skip-pull` sets `PULL_POLICY=never` (same-host / air-gap).
Expand Down Expand Up @@ -586,8 +595,8 @@ This CLI reads shop identity and secrets from the environment / shop-root
| Restore volumes | `SHOPWARE_DATA_ROOT`, `SHOPWARE_DATA_BASE` |
| Rewrite | `APP_URL`, `IMAGE` |
| Dump (shopware-cli only) | Use `shopware-cli project dump`. fyrst-cli does not dump. |
| Release | `IMAGE`, `IMAGE_TAG` (release / `.env`; **ignored on rollback**), `COMPOSE_PROFILES`, `SMOKE_URL`, `PULL_POLICY`, `SKIP_PULL`, `ROLLBACK_ON_SMOKE_FAIL` |
| Rollback | `.previous-tag` is the only `IMAGE_TAG`; same optional env as release except `ROLLBACK_ON_SMOKE_FAIL` |
| Release | `IMAGE`, `IMAGE_TAG` (release / `.env`; **ignored on rollback**), `COMPOSE_PROFILES`, `DEPLOY_HEALTH_URL` (default from `APP_URL` + `/api/_info/health-check`), `ALLOW_NO_DEPLOY_HEALTH`, `PULL_POLICY`, `SKIP_PULL`, `ROLLBACK_ON_FAIL` |
| Rollback | `.previous-tag` is the only `IMAGE_TAG`; same optional env as release except `ROLLBACK_ON_FAIL` |
| SSH / remote live data | `SHOPWARE_SSH_HOST`, `SHOPWARE_SSH_USER`, `SHOPWARE_SSH_KEY`, `SHOPWARE_REMOTE_DATA_ROOT` |
| Live gate | `SHOPWARE_ALLOW_LIVE_RESTORE` |
| Backup | `BACKUP_TARGET` (default `local`), `BACKUP_KEEP_DAYS` (default 14, `0` = forever), `BACKUP_DB_DUMP`, `BACKUP_CONFIRM_RESTORE` |
Expand Down
51 changes: 50 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Live policy (refuse a live consumer unless):
sync pull SHOPWARE_ALLOW_LIVE_RESTORE=1 only
backup recover confirm flag + SHOPWARE_ALLOW_LIVE_RESTORE=1
(--i-understand-this-restores-this-host or BACKUP_CONFIRM_RESTORE=1)
deploy release post-deploy health probe (DEPLOY_HEALTH_URL or APP_URL);
ops escape: --allow-no-deploy-health / ALLOW_NO_DEPLOY_HEALTH=1
deploy rollback same probe require as release

Dump = shopware-cli project dump only (fyrst-cli does not dump).
Import = fyrst-cli shopware db import (also used by sync apply --data db and sync pull).
Expand All @@ -49,6 +52,16 @@ backup recover = disaster recovery onto this host (confirmation required).
See docs/command-matrix.md.
";

pub const DEPLOY_HEALTH_AFTER_HELP: &str = "\
Post-deploy health probe (curl -fsS, 30 attempts, 2s sleep):\n \
Default: APP_URL with trailing slash stripped + /api/_info/health-check\n \
Override: DEPLOY_HEALTH_URL (full URL, used as-is)\n \
Live (SHOPWARE_DEPLOY_ENV=live): a probe URL is required.\n \
Ops escape only: --allow-no-deploy-health or ALLOW_NO_DEPLOY_HEALTH=1\n \
Non-live: skip the probe when no URL can be resolved.\n \
Probe failure auto-rollback still uses ROLLBACK_ON_FAIL\n \
(unset → on for live, off otherwise).\n";

#[derive(Debug, Parser)]
#[command(
name = "fyrst-cli",
Expand Down Expand Up @@ -113,7 +126,9 @@ import `db.sql.gz` from `--snapshot-dir` if `--data` includes db (does not dump)
database, never local SHOPWARE_DATA_ROOT). `--data all` is refused (all includes db on sync pull / backup create). \
Dumps stay with `shopware-cli project dump` — this CLI does not wrap dump.\n\n\
`deploy rollback` is implemented: same compose files and order as `vps-release.sh`, with \
IMAGE_TAG only from `.previous-tag` (process-env IMAGE_TAG is ignored).\n\n\
IMAGE_TAG only from `.previous-tag` (process-env IMAGE_TAG is ignored). Live requires a \
post-deploy health probe (`DEPLOY_HEALTH_URL` or `APP_URL` + `/api/_info/health-check`); \
`--allow-no-deploy-health` / `ALLOW_NO_DEPLOY_HEALTH=1` is an ops escape only.\n\n\
`backup create` copies bind-mount trees (and an operator-provided db.sql.gz) into \
BACKUP_TARGET; it is allowed on live. \
`backup prune` is implemented: stamp-based retention under BACKUP_TARGET \
Expand Down Expand Up @@ -220,6 +235,7 @@ pub struct InitEnvArgs {
}

#[derive(Debug, Args)]
#[command(after_help = DEPLOY_HEALTH_AFTER_HELP)]
pub struct ReleaseArgs {
/// Print the compose sequence; do not pull or recreate containers
#[arg(long)]
Expand All @@ -228,9 +244,14 @@ pub struct ReleaseArgs {
/// Same-host / air-gap: skip registry pull, PULL_POLICY=never
#[arg(long = "skip-pull")]
pub skip_pull: bool,

/// Ops escape only: skip the live require for a post-deploy health probe (or set ALLOW_NO_DEPLOY_HEALTH=1)
#[arg(long = "allow-no-deploy-health")]
pub allow_no_deploy_health: bool,
}

#[derive(Debug, Args)]
#[command(after_help = DEPLOY_HEALTH_AFTER_HELP)]
pub struct RollbackArgs {
/// Print the compose sequence; do not pull or recreate containers
#[arg(long)]
Expand All @@ -239,6 +260,10 @@ pub struct RollbackArgs {
/// Same-host / air-gap: skip registry pull, PULL_POLICY=never
#[arg(long = "skip-pull")]
pub skip_pull: bool,

/// Ops escape only: skip the live require for a post-deploy health probe (or set ALLOW_NO_DEPLOY_HEALTH=1)
#[arg(long = "allow-no-deploy-health")]
pub allow_no_deploy_health: bool,
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -588,6 +613,29 @@ mod tests {
}) => {
assert!(op.dry_run);
assert!(op.skip_pull);
assert!(!op.allow_no_deploy_health);
}
other => panic!("unexpected parse: {other:?}"),
}
}

#[test]
fn deploy_release_parses_allow_no_deploy_health() {
let cli = Cli::try_parse_from([
"fyrst-cli",
"shopware",
"deploy",
"release",
"--allow-no-deploy-health",
])
.unwrap();
match cli.command {
Command::Shopware(ShopwareArgs {
command: ShopwareCommand::Deploy(DeployCommand::Release(op)),
}) => {
assert!(op.allow_no_deploy_health);
assert!(!op.dry_run);
assert!(!op.skip_pull);
}
other => panic!("unexpected parse: {other:?}"),
}
Expand Down Expand Up @@ -635,6 +683,7 @@ mod tests {
}) => {
assert!(op.dry_run);
assert!(op.skip_pull);
assert!(!op.allow_no_deploy_health);
}
other => panic!("unexpected parse: {other:?}"),
}
Expand Down
21 changes: 14 additions & 7 deletions src/shopware/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ const PROCESS_WINS: &[&str] = &[
"SHOPWARE_SSH_KEY",
"SHOPWARE_ALLOW_LIVE_RESTORE",
"APP_URL",
"SMOKE_URL",
"DEPLOY_HEALTH_URL",
"ALLOW_NO_DEPLOY_HEALTH",
"COMPOSE_PROFILES",
"ROLLBACK_ON_SMOKE_FAIL",
"ROLLBACK_ON_FAIL",
"SKIP_PULL",
"PULL_POLICY",
"BACKUP_TARGET",
Expand Down Expand Up @@ -599,7 +600,7 @@ services:
.unwrap();
fs::write(
shop.join(".env.prod"),
"APP_URL=http://from-prod\nSMOKE_URL=http://smoke\n",
"APP_URL=http://from-prod\nDEPLOY_HEALTH_URL=http://health\n",
)
.unwrap();
let mut process = HashMap::new();
Expand All @@ -609,7 +610,7 @@ services:
assert_eq!(env.get("APP_URL"), Some("http://from-prod"));
assert_eq!(env.get("SHOPWARE_SSH_HOST"), Some("vps.local"));
assert_eq!(env.get("BACKUP_TARGET"), Some("/from-local"));
assert_eq!(env.get("SMOKE_URL"), Some("http://smoke"));
assert_eq!(env.get("DEPLOY_HEALTH_URL"), Some("http://health"));
let _ = fs::remove_dir_all(&shop);
}

Expand Down Expand Up @@ -649,19 +650,25 @@ SHOPWARE_SHOP_ID=acme
SHOPWARE_DEPLOY_ENV=live
IMAGE=ghcr.io/from-file/shop
IMAGE_TAG=latest
SMOKE_URL=http://from-file
DEPLOY_HEALTH_URL=http://from-file-health
COMPOSE_PROFILES=redis
",
)
.unwrap();
let mut process = HashMap::new();
process.insert("IMAGE".into(), "ghcr.io/from-ci/shop".into());
process.insert("IMAGE_TAG".into(), "abc123deadbeef".into());
process.insert("SMOKE_URL".into(), "http://127.0.0.1:8000".into());
process.insert(
"DEPLOY_HEALTH_URL".into(),
"http://127.0.0.1:8000/api/_info/health-check".into(),
);
let env = ShopEnv::load(shop.clone(), &process).unwrap();
assert_eq!(env.get("IMAGE"), Some("ghcr.io/from-ci/shop"));
assert_eq!(env.get("IMAGE_TAG"), Some("abc123deadbeef"));
assert_eq!(env.get("SMOKE_URL"), Some("http://127.0.0.1:8000"));
assert_eq!(
env.get("DEPLOY_HEALTH_URL"),
Some("http://127.0.0.1:8000/api/_info/health-check")
);
assert_eq!(env.get("COMPOSE_PROFILES"), Some("redis"));
let _ = fs::remove_dir_all(&shop);
}
Expand Down
26 changes: 16 additions & 10 deletions src/shopware/release.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! `fyrst-cli shopware deploy release` — VPS image pull + Compose recreate.
//!
//! Matches recipes `deploy/vps-release.sh`. Never builds images or compiles
//! themes/assets. Auto-rollback on smoke failure uses the shared rollout
//! themes/assets. Auto-rollback on deploy-health failure uses the shared rollout
//! helper (`fyrst-cli shopware deploy rollback` is the operator command).

use super::env::{resolve_compose_dir, ShopEnv};
use super::error::Error;
use super::rollout::{
bootstrap, docker_log_checked, ensure_env_prod, execute_rollout, read_tag_file,
record_previous_tag, rollout_to_tag, smoke, smoke_fail_message, write_tag_file,
bootstrap, deploy_health, deploy_health_fail_message, docker_log_checked, ensure_env_prod,
execute_rollout, read_tag_file, record_previous_tag, rollout_to_tag, write_tag_file,
ROLLBACK_ONE_LINER,
};
use crate::cli::ReleaseArgs;
Expand All @@ -21,6 +21,9 @@ pub fn run(args: ReleaseArgs) -> Result<(), Error> {
if args.skip_pull {
process_env.insert("SKIP_PULL".into(), "1".into());
}
if args.allow_no_deploy_health {
process_env.insert("ALLOW_NO_DEPLOY_HEALTH".into(), "1".into());
}
let cwd = std::env::current_dir().map_err(|e| Error::fail(format!("cannot read cwd: {e}")))?;
execute_release(&process_env, &cwd, args.skip_pull, args.dry_run)
}
Expand Down Expand Up @@ -78,12 +81,15 @@ pub fn execute_release(

execute_rollout(&ctx, &plan)?;

if let Err(_e) = smoke(&ctx) {
let url = ctx.smoke_url.as_deref().unwrap_or("SMOKE_URL");
let mut msg = smoke_fail_message(url);
if let Err(_e) = deploy_health(&ctx) {
let url = ctx
.deploy_health_url
.as_deref()
.unwrap_or("DEPLOY_HEALTH_URL");
let mut msg = deploy_health_fail_message(url);
if ctx.should_auto_rollback() {
println!(
"==> ROLLBACK_ON_SMOKE_FAIL on (SHOPWARE_DEPLOY_ENV={}; live default is on, others off unless ROLLBACK_ON_SMOKE_FAIL=1)",
"==> ROLLBACK_ON_FAIL on (SHOPWARE_DEPLOY_ENV={}; live default is on, others off unless ROLLBACK_ON_FAIL=1)",
ctx.deploy_env
);
let Some(tag) = previous.filter(|t| !t.is_empty()) else {
Expand All @@ -101,12 +107,12 @@ pub fn execute_release(
return Err(Error::fail(msg));
}
msg.push_str(
"\nERROR: Rolled back after smoke failure. Release still exits 1 so CI does not treat the new tag as live.",
"\nERROR: Rolled back after deploy health failure. Release still exits 1 so CI does not treat the new tag as live.",
);
return Err(Error::fail(msg));
}
println!(
"==> Auto-rollback skipped (SHOPWARE_DEPLOY_ENV={}; set ROLLBACK_ON_SMOKE_FAIL=1 to enable)",
"==> Auto-rollback skipped (SHOPWARE_DEPLOY_ENV={}; set ROLLBACK_ON_FAIL=1 to enable)",
ctx.deploy_env
);
return Err(Error::fail(msg));
Expand Down Expand Up @@ -175,7 +181,7 @@ fn print_dry_run(
format!("==> DRY-RUN extra profiles: {}", plan.profiles_raw),
)?;
}
if let Some(url) = &ctx.smoke_url {
if let Some(url) = &ctx.deploy_health_url {
emit(ctx, format!("==> DRY-RUN would GET {url}"))?;
}
Ok(())
Expand Down
Loading
Loading