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: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,15 @@ Identity: `SHOPWARE_SHOP_ID`, `SHOPWARE_DEPLOY_ENV`, optional
### env init

Does not overwrite the whole `.env`. Does not invent MYSQL passwords or
`APP_URL`. `--shop-id` is required unless `SHOPWARE_SHOP_ID` is already set.
`--env` defaults to `live`. `--vps` comments out `COMPOSE_PROJECT_NAME`.
`.env` may still be missing; missing keys are merged from `.env.example`.
`APP_URL`. Does not generate `APP_SECRET` (`shopware-cli project create`
already writes it). `--shop-id` is required unless `SHOPWARE_SHOP_ID` is
already set. `--env` defaults to `live`. `--vps` comments out
`COMPOSE_PROJECT_NAME`. `.env` may still be missing; missing keys are
merged from `.env.example`.

```bash
fyrst-cli shopware env init --shop-id acme --vps --dry-run
fyrst-cli shopware env init --shop-id acme --env live --vps --image ghcr.io/example/acme
fyrst-cli shopware env init --shop-id acme --generate-app-secret
```

### db import
Expand Down
22 changes: 11 additions & 11 deletions docs/command-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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`, `--vps`, `--generate-app-secret`, `--dry-run` | **implemented** |
| `deploy/init-env.sh` | `fyrst-cli shopware env init` | `init` | `--shop-id`, `--env`, `--image`, `--vps`, `--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** |
| `restore_db_*` (sync-runtime) | `fyrst-cli shopware db import` | `import` | `--file`, `--dry-run`, `--allow-live` | **implemented** |
Expand Down Expand Up @@ -90,7 +90,7 @@ Rewrite: `APP_URL` only. CI `VPS_*` secrets stay secrets — they are not shop
## Exact env init CLI

```text
fyrst-cli shopware env init [--shop-id SLUG] [--env live|staging|playground|dev] [--image REPO] [--vps] [--generate-app-secret] [--dry-run]
fyrst-cli shopware env init [--shop-id SLUG] [--env live|staging|playground|dev] [--image REPO] [--vps] [--dry-run]
```

## Exact deploy release CLI
Expand Down Expand Up @@ -164,7 +164,8 @@ volumes (`media`, `files`, `thumbnail`, `theme`, `sitemap`) restore from

Finish shop-root `.env` after `shopware-cli project create` + Flex. Historically
mapped to overlay `deploy/init-env.sh` (removed). Does **not** overwrite the
whole file, invent `MYSQL_*` passwords, or set `APP_URL`. This is **not** a
whole file, invent `MYSQL_*` passwords, set `APP_URL`, or generate
`APP_SECRET` (`shopware-cli project create` writes that). This is **not** a
dump command.

Resolves shop root (`COMPOSE_DIR` if set, else walk from cwd for `.env` or
Expand All @@ -180,14 +181,13 @@ shell expansion**), same parser as import (`src/shopware/envfile.rs`).
4. `--image` sets `IMAGE` (no whitespace). Unset leaves `IMAGE` as-is.
5. `--vps` comments out uncommented `COMPOSE_PROJECT_NAME=…` lines (create
footgun on a VPS). Does not leave an empty `COMPOSE_PROJECT_NAME=`.
6. `--generate-app-secret`: `openssl rand -hex 32` only if `APP_SECRET` is
empty; the value is never printed.
7. `--dry-run` prints the summary and does not write `.env`.
8. After a real write: `chmod 600 .env`.
6. `--dry-run` prints the summary and does not write `.env`.
7. After a real write: `chmod 600 .env`.

Refuses a bash xtrace equivalent (`SHELLOPTS=xtrace` / `BASH_XTRACEFD`) so
credentials in `.env` cannot leak via trace. Summary never prints secret
values (MYSQL passwords, `APP_SECRET`).
Does not generate `APP_SECRET` (no dedicated read/write of that key). Refuses a
bash xtrace equivalent (`SHELLOPTS=xtrace` / `BASH_XTRACEFD`) so credentials
in `.env` cannot leak via trace. Summary never prints secret values (MYSQL
passwords).

## Exact deploy rollback CLI

Expand Down Expand Up @@ -555,7 +555,7 @@ This CLI reads shop identity and secrets from the environment / shop-root
| Area | Variables |
| --- | --- |
| Shop identity | `COMPOSE_DIR`, `SHOPWARE_SHOP_ID`, `SHOPWARE_DEPLOY_ENV`, `SHOPWARE_DATA_BASE`, `SHOPWARE_DATA_ROOT`, `COMPOSE_PROJECT_NAME` |
| Env init | `APP_SECRET` (optional `--generate-app-secret`; never logged), `IMAGE` |
| Env init | `IMAGE` (`APP_SECRET` is Shopware's; `shopware-cli project create` writes it) |
| Import | `MYSQL_DATABASE`, `DATABASE_URL`, `SHOPWARE_ALLOW_LIVE_RESTORE` |
| Restore volumes | `SHOPWARE_DATA_ROOT`, `SHOPWARE_DATA_BASE` |
| Rewrite | `APP_URL`, `IMAGE` |
Expand Down
35 changes: 24 additions & 11 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ pub enum Command {
deploy (VPS compose), db (SQL import), sync (between environments / workdir), \
backup (off-host disaster recovery).\n\n\
`env init` is implemented: finish shop-root `.env` after create + Flex (merge missing \
keys from `.env.example`, shop id / deploy env, optional IMAGE / APP_SECRET, `--vps` \
comments COMPOSE_PROJECT_NAME). `--dry-run` prints the plan and does not write. \
Passwords and APP_SECRET are never printed.\n\n\
keys from `.env.example`, shop id / deploy env, optional IMAGE, `--vps` \
comments COMPOSE_PROJECT_NAME). Does not generate APP_SECRET. `--dry-run` prints the \
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 \
Expand Down Expand Up @@ -181,13 +181,13 @@ impl DeployEnv {

#[derive(Debug, Args)]
#[command(
after_help = "Does not overwrite the whole .env. Does not invent MYSQL passwords or APP_URL.\n\n\
after_help = "Does not overwrite the whole .env. Does not invent MYSQL passwords or APP_URL. \
Does not generate APP_SECRET (shopware-cli project create writes that).\n\n\
Environment:\n \
COMPOSE_DIR Shop checkout (default: walk from cwd for .env / .env.example + deploy/)\n\n\
Examples:\n \
fyrst-cli shopware env init --shop-id acme\n \
fyrst-cli shopware env init --shop-id acme --env live --vps --image ghcr.io/example/acme\n \
fyrst-cli shopware env init --shop-id acme --generate-app-secret\n \
fyrst-cli shopware env init --shop-id acme --vps --dry-run\n"
)]
pub struct InitEnvArgs {
Expand All @@ -207,10 +207,6 @@ pub struct InitEnvArgs {
#[arg(long)]
pub vps: bool,

/// Set APP_SECRET with openssl rand -hex 32 if empty (value is never printed)
#[arg(long = "generate-app-secret")]
pub generate_app_secret: bool,

/// Print the summary; do not write .env
#[arg(long)]
pub dry_run: bool,
Expand Down Expand Up @@ -515,7 +511,6 @@ mod tests {
"--image",
"ghcr.io/example/acme",
"--vps",
"--generate-app-secret",
"--dry-run",
])
.unwrap();
Expand All @@ -527,13 +522,31 @@ mod tests {
assert_eq!(op.env, Some(DeployEnv::Staging));
assert_eq!(op.image.as_deref(), Some("ghcr.io/example/acme"));
assert!(op.vps);
assert!(op.generate_app_secret);
assert!(op.dry_run);
}
other => panic!("unexpected parse: {other:?}"),
}
}

#[test]
fn env_init_rejects_generate_app_secret() {
let err = Cli::try_parse_from([
"fyrst-cli",
"shopware",
"env",
"init",
"--shop-id",
"acme",
"--generate-app-secret",
])
.unwrap_err();
let text = err.to_string();
assert!(
text.contains("unexpected argument") || text.contains("unexpected"),
"{text}"
);
}

#[test]
fn deploy_rollback_parses_flags() {
let cli = Cli::try_parse_from([
Expand Down
Loading
Loading