Skip to content
Merged
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,28 @@ Identity: `SHOPWARE_SHOP_ID`, `SHOPWARE_DEPLOY_ENV`, optional

### env init

Does not overwrite the whole `.env`. Does not invent MYSQL passwords or
`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`. Uncommented `COMPOSE_PROJECT_NAME`
lines are always commented out (Compose SoT is `SHOPWARE_SHOP_ID` +
`SHOPWARE_DEPLOY_ENV`). `.env` may still be missing; missing keys are
merged from `.env.example`.
Shop-root `.env` is git-committed and shared. This command does not
overwrite the whole file, invent MYSQL passwords or `APP_URL`, or generate
`APP_SECRET` (`shopware-cli project create` already writes it). `--shop-id`
is required unless `SHOPWARE_SHOP_ID` is already set. `--env` writes
`SHOPWARE_DEPLOY_ENV` and `COMPOSE_PROJECT_NAME=<shop-id>-<env>` to
**`.env.local`** (gitignored; created if missing; default `live` when unset
and no host value). Uncommented `COMPOSE_PROJECT_NAME` (create writes
`sw-…`) and leftover `SHOPWARE_DEPLOY_ENV` in shared `.env` are
**commented out** — those keys stay out of the committed file.

Local Compose uses the same project name as VPS (`<shop-id>-<env>`, not the
folder basename). Compose and `shopware-cli project dev` only auto-read
`COMPOSE_PROJECT_NAME` from project-directory `.env`, so env init also
upserts top-level `name: <shop-id>-<env>` in gitignored
`compose.override.yaml` (create if missing; replace only that key).
shopware-cli regenerates `compose.yaml` and leaves `compose.override.yaml`
for local customization — gitignore it so the env-specific `name:` is not
committed. VPS interpolates `docker compose` `name: ${SHOPWARE_SHOP_ID}-${SHOPWARE_DEPLOY_ENV}`
from host env files (always `--env-file .env`, then `.env.local` / `.env.prod`
when present). There is no `-p`.
`.env` may still be missing; missing keys are merged from `.env.example`
(not `COMPOSE_PROJECT_NAME` / `SHOPWARE_DEPLOY_ENV`).

```bash
fyrst-cli shopware env init --shop-id acme --dry-run
Expand All @@ -167,7 +182,9 @@ fyrst-cli shopware env init --shop-id acme --env live --image ghcr.io/example/ac
### db import

Needs `SHOPWARE_SHOP_ID` and a Compose `mysql` service (preferred) or
`DATABASE_URL` to a real host.
`DATABASE_URL` to a real host. Bundled mysql uses the same Compose naming as
VPS: `name:` interpolating host env files (`--env-file .env`, then
`.env.local` / `.env.prod` when present). There is no `-p`.

```bash
fyrst-cli shopware db import --file /tmp/db.sql.gz --dry-run
Expand All @@ -182,6 +199,10 @@ Needs `IMAGE`, `IMAGE_TAG` (release), `SHOPWARE_SHOP_ID`, and
win over `.env` on release. Rollback ignores process-env `IMAGE_TAG` and reads
`.previous-tag` only. `--skip-pull` is for same-host / air-gap.

VPS Compose project name is `{shop-id}-{env}`. Source of truth is
`deploy/compose.yaml` `name:` interpolating host env files (`--env-file .env`,
then `.env.local` / `.env.prod` when present). There is no `-p`.

```bash
fyrst-cli shopware deploy release --dry-run
fyrst-cli shopware deploy release --skip-pull
Expand Down
65 changes: 45 additions & 20 deletions docs/command-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ Resolves shop root (`COMPOSE_DIR` or walk from cwd), loads `.env` then
Compose is always:

```text
docker compose --env-file .env -f deploy/compose.yaml -f deploy/compose.prod.yaml -f deploy/compose.vps.yaml
docker compose --env-file .env [--env-file .env.local] [--env-file .env.prod] -f deploy/compose.yaml -f deploy/compose.prod.yaml -f deploy/compose.vps.yaml
```

Source of truth is `deploy/compose.yaml` `name: "${SHOPWARE_SHOP_ID:?…}-${SHOPWARE_DEPLOY_ENV:?…}"` plus host env files in identity-load order (always `.env`, then `.env.local` / `.env.prod` when those files exist under the shop root). There is no `-p`. Leftover `COMPOSE_PROJECT_NAME` in committed `.env` is ignored (commented out by env init).

Never `--build`. `compose run` uses `--pull never` (not `--no-build`). `compose up`
uses `--no-build` (and `--pull never` when skipping registry pull). Theme/asset
compile flags stay in the setup helper image.
Expand Down Expand Up @@ -162,28 +164,47 @@ volumes (`media`, `files`, `thumbnail`, `theme`, `sitemap`) restore from

## `shopware env init` (implemented)

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, set `APP_URL`, or generate
`APP_SECRET` (`shopware-cli project create` writes that). This is **not** a
dump command.
Finish committed shop-root `.env` after `shopware-cli project create` + Flex,
host `.env.local` for `SHOPWARE_DEPLOY_ENV` and
`COMPOSE_PROJECT_NAME=<shop-id>-<env>`, and gitignored `compose.override.yaml`
(`name: <shop-id>-<env>`) so local `shopware-cli project dev` uses the same
Compose project as VPS. Historically mapped to overlay `deploy/init-env.sh`
(removed). Does **not** overwrite the whole file, invent `MYSQL_*` passwords,
set `APP_URL`, or generate `APP_SECRET` (`shopware-cli project create` writes
that). Shared `.env` must not hold env-specific values. This is **not** a dump
command.

Resolves shop root (`COMPOSE_DIR` if set, else walk from cwd for `.env` or
`.env.example` + `deploy/`). `.env` is `KEY=VALUE` (quotes stripped, **no
shell expansion**), same parser as import (`src/shopware/envfile.rs`).

1. Copy `.env.example` → `.env` when `.env` is missing; merge **missing** keys
from `.env.example` without clobbering existing values.
from `.env.example` without clobbering existing values (skips
`COMPOSE_PROJECT_NAME` and `SHOPWARE_DEPLOY_ENV`).
2. `--shop-id` is required unless `SHOPWARE_SHOP_ID` is already non-empty in
`.env`. Slug: lowercase `[a-z0-9]([a-z0-9-]*[a-z0-9])?`.
3. `--env` is `live` | `staging` | `playground` | `dev`. Default `live` when
unset/empty; keep an existing non-empty value.
3. `--env` is `live` | `staging` | `playground` | `dev`. Written to
**`.env.local`** (gitignored; created if missing) together with
`COMPOSE_PROJECT_NAME=<shop-id>-<env>` (same string as VPS, e.g. `acme-dev`).
Default `live` when unset and `.env.local` / `.env.prod` have no value;
leftover uncommented `SHOPWARE_DEPLOY_ENV` in shared `.env` is migrated then
commented out.
4. `--image` sets `IMAGE` (no whitespace). Unset leaves `IMAGE` as-is.
5. Always comments out uncommented `COMPOSE_PROJECT_NAME=…` lines (create
writes `COMPOSE_PROJECT_NAME=sw-…`; Compose SoT is `SHOPWARE_SHOP_ID` +
`SHOPWARE_DEPLOY_ENV`). Does not leave an empty `COMPOSE_PROJECT_NAME=`.
6. `--dry-run` prints the summary and does not write `.env`.
7. After a real write: `chmod 600 .env`.
5. **Comments out** uncommented `COMPOSE_PROJECT_NAME=…` in shared `.env`
(create writes `COMPOSE_PROJECT_NAME=sw-…`). Does **not** write
`COMPOSE_PROJECT_NAME` or `SHOPWARE_DEPLOY_ENV` into committed `.env`.
Already-commented lines are left as-is.
6. Upserts top-level Compose `name: <shop-id>-<env>` in gitignored
`compose.override.yaml` (create if missing; if the file exists, set/replace
only that key). Compose and `shopware-cli project dev` auto-read
`COMPOSE_PROJECT_NAME` only from project-directory `.env`, not `.env.local`,
so the YAML `name:` is what names the local stack. shopware-cli regenerates
`compose.yaml` and leaves `compose.override.yaml` for local customization.
VPS compose interpolates the same `<shop-id>-<env>` from `deploy/compose.yaml`
`name:` plus host env files (no `-p`).
7. `--dry-run` prints the summary and does not write `.env`, `.env.local`, or
`compose.override.yaml`.
8. After a real write: `chmod 600 .env` and `.env.local` (not the override).

Does not generate `APP_SECRET` (no dedicated read/write of that key). Refuses a
bash xtrace equivalent (`SHELLOPTS=xtrace` / `BASH_XTRACEFD`) so credentials
Expand Down Expand Up @@ -255,8 +276,10 @@ from the process environment win when non-empty). Requires `SHOPWARE_SHOP_ID`.

1. If a compose `mysql` service is present: on execute,
`docker compose … up -d --no-build mysql`, wait until pingable, then
`gzip -dc FILE | docker compose --env-file .env -f … exec -T mysql sh -c
'<mysql|mariadb>'` (plain `.sql` is stdin, not gzip).
`gzip -dc FILE | docker compose --env-file .env [--env-file .env.local] [--env-file .env.prod] -f … exec -T mysql sh -c
'<mysql|mariadb>'` (plain `.sql` is stdin, not gzip). There is no `-p`;
project name is compose `name:` (VPS `deploy/compose.yaml` or local
`compose.override.yaml`) interpolating host env files.
2. Else `DATABASE_URL` to a real host: `gzip -dc FILE | docker run --rm -i
--network host <mysql:8.4|mariadb:11.4> mysql <database>`. Host `mysql`
without a bundled service is refused.
Expand Down Expand Up @@ -350,8 +373,9 @@ Local: rsync (or a tree copy if rsync is missing) from
`$SHOPWARE_DATA_ROOT` / derived
`$SHOPWARE_DATA_BASE/$SHOPWARE_SHOP_ID/$SHOPWARE_DEPLOY_ENV/<item>`
into `--snapshot-dir/data/<item>/`. If the bind-mount directory is missing,
named-volume fallback `${COMPOSE_PROJECT_NAME}_<item>` via
`alpine:3.20` writes `--snapshot-dir/volumes/<item>.tar.gz`.
named-volume fallback `{SHOPWARE_SHOP_ID}-{SHOPWARE_DEPLOY_ENV}_<item>` via
`alpine:3.20` writes `--snapshot-dir/volumes/<item>.tar.gz` (identity
project name, matching Compose `name:`).

Remote `--from <alias>`: SSH + rsync (or tar over SSH) from
`SHOPWARE_REMOTE_DATA_ROOT` or derived
Expand Down Expand Up @@ -491,7 +515,8 @@ shopware-cli.
`$SHOPWARE_DATA_ROOT/<item>/` (or derived
`$SHOPWARE_DATA_BASE/$SHOPWARE_SHOP_ID/$SHOPWARE_DEPLOY_ENV`) into
`data/<item>/`. Missing bind-mounts fall back to a named-volume tar
(`${COMPOSE_PROJECT_NAME}_<item>`, `alpine:3.20`). Local target writes the
(`{SHOPWARE_SHOP_ID}-{SHOPWARE_DEPLOY_ENV}_<item>`, `alpine:3.20`;
identity name matching Compose `name:`). Local target writes the
timestamped dir in place; SSH target builds under
`<shop>/var/backup-work/<stamp>` then rsyncs (`SHOPWARE_SSH_KEY`).
4. If `--data` includes `db`: **do not dump**. `--dry-run` prints
Expand Down Expand Up @@ -555,7 +580,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` |
| Shop identity | `COMPOSE_DIR`, `SHOPWARE_SHOP_ID` (shared `.env`), `SHOPWARE_DEPLOY_ENV` and `COMPOSE_PROJECT_NAME=<shop-id>-<env>` (`.env.local` / `.env.prod`), `SHOPWARE_DATA_BASE`, `SHOPWARE_DATA_ROOT`. Do not put `COMPOSE_PROJECT_NAME` or `SHOPWARE_DEPLOY_ENV` in committed `.env`. Local Compose project is `<shop-id>-<env>` via host `.env.local` plus gitignored `compose.override.yaml` `name:` (not the folder basename). Compose SoT for VPS, db import, and rewrite is `name:` interpolating host env files (no `-p`). |
| 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` |
Expand Down
22 changes: 15 additions & 7 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ 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; always comments out \
COMPOSE_PROJECT_NAME). Does not generate APP_SECRET. `--dry-run` prints the \
keys from `.env.example`, shop id, optional IMAGE). Comments out COMPOSE_PROJECT_NAME \
and leftover SHOPWARE_DEPLOY_ENV in committed `.env`; writes SHOPWARE_DEPLOY_ENV and \
COMPOSE_PROJECT_NAME=<shop-id>-<env> to `.env.local` and upserts Compose `name:` in \
gitignored `compose.override.yaml`. 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, \
Expand Down Expand Up @@ -183,9 +185,15 @@ impl DeployEnv {
#[command(
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). \
Always comments out uncommented COMPOSE_PROJECT_NAME=… lines (create writes \
COMPOSE_PROJECT_NAME=sw-…; Compose SoT is SHOPWARE_SHOP_ID + SHOPWARE_DEPLOY_ENV). \
Does not leave an empty COMPOSE_PROJECT_NAME=.\n\n\
Shared .env is git-committed: comments out uncommented COMPOSE_PROJECT_NAME=… \
(create writes COMPOSE_PROJECT_NAME=sw-…) and leftover SHOPWARE_DEPLOY_ENV. \
Does not set COMPOSE_PROJECT_NAME or SHOPWARE_DEPLOY_ENV in shared .env. \
Writes SHOPWARE_DEPLOY_ENV and COMPOSE_PROJECT_NAME=<shop-id>-<env> to .env.local \
(gitignored; created if missing). Upserts top-level Compose name: <shop-id>-<env> \
in gitignored compose.override.yaml so shopware-cli project dev uses that name \
(Compose reads COMPOSE_PROJECT_NAME only from project-directory .env, not .env.local). \
VPS compose interpolates the same <shop-id>-<env> from deploy/compose.yaml name: plus host \
env files (no -p).\n\n\
Environment:\n \
COMPOSE_DIR Shop checkout (default: walk from cwd for .env / .env.example + deploy/)\n\n\
Examples:\n \
Expand All @@ -198,15 +206,15 @@ pub struct InitEnvArgs {
#[arg(long = "shop-id", value_name = "SLUG")]
pub shop_id: Option<String>,

/// live | staging | playground | dev (default live when unset/empty; keep existing non-empty)
/// live | staging | playground | dev (written to .env.local with COMPOSE_PROJECT_NAME; default live when unset and no host value)
#[arg(long = "env", value_enum, value_name = "NAME")]
pub env: Option<DeployEnv>,

/// Set IMAGE (registry/repo). Unset leaves IMAGE as-is
#[arg(long = "image", value_name = "REPO")]
pub image: Option<String>,

/// Print the summary; do not write .env
/// Print the summary; do not write .env, .env.local, or compose.override.yaml
#[arg(long)]
pub dry_run: bool,
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! fyrst.dev global CLI (`fyrst-cli`).
//!
//! Database dumps are owned by `shopware-cli project dump`. This binary does
//! not wrap dump. `shopware env init` finishes shop-root `.env`. Database
//! not wrap dump. `shopware env init` finishes committed `.env` (shop id / IMAGE)
//! and host `.env.local` (`SHOPWARE_DEPLOY_ENV`, `COMPOSE_PROJECT_NAME`) plus
//! gitignored `compose.override.yaml` (`name: <shop-id>-<env>`). Database
//! import is `fyrst-cli shopware db import` (MySQL client via Compose exec or
//! a one-shot client image). VPS release is `fyrst-cli shopware deploy release`.
//! Rollback is `fyrst-cli shopware deploy rollback` (IMAGE_TAG from
Expand Down
10 changes: 5 additions & 5 deletions src/shopware/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn stop_app_containers(
return Ok(Vec::new());
}
require_docker()?;
let mut args = compose_argv(files);
let mut args = compose_argv(compose_dir, files);
args.extend([
"--profile".into(),
"worker".into(),
Expand Down Expand Up @@ -52,7 +52,7 @@ pub fn stop_app_containers(
}
println!("==> Stopping {svc} for restore");
if !compose_stop(compose_dir, files, svc) {
let mut with_profile = compose_argv(files);
let mut with_profile = compose_argv(compose_dir, files);
with_profile.extend([
"--profile".into(),
(*svc).into(),
Expand All @@ -72,7 +72,7 @@ pub fn stop_app_containers(
}

fn compose_stop(compose_dir: &Path, files: &[String], svc: &str) -> bool {
let mut args = compose_argv(files);
let mut args = compose_argv(compose_dir, files);
args.extend(["stop".into(), svc.into()]);
Command::new("docker")
.args(&args)
Expand All @@ -99,7 +99,7 @@ pub fn start_stopped_app(
continue;
}
println!("==> Starting {svc}");
let mut args = compose_argv(files);
let mut args = compose_argv(compose_dir, files);
match svc.as_str() {
"worker" => {
args.extend([
Expand Down Expand Up @@ -176,7 +176,7 @@ pub fn post_restore_hints(
}
if env.get("IMAGE").is_some() && !files.is_empty() {
println!("==> Trying cache:clear (non-fatal if the image/console is unavailable)");
let mut args = compose_argv(files);
let mut args = compose_argv(compose_dir, files);
args.extend([
"run".into(),
"--rm".into(),
Expand Down
Loading
Loading