diff --git a/README.md b/README.md index 2ce3748..b8e6e2a 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ composer require shopware/docker shopware/deployment-helper fyrst/shopware-cd - **Local:** `shopware-cli project dev` and the CLI-managed shop-root `compose.yaml`. Live → laptop uploads: `fyrst-cli shopware sync local` (`--data all` is refused). - **VPS/CD:** files under `deploy/` (Compose templates, edge). CI runs `fyrst-cli shopware deploy release`. Dump stays `shopware-cli project dump`. Create and image build stay out of this recipe. -Flex copies CI, `deploy/` (CD Compose, edge), `.dockerignore`, and `.env.example` from the package `overlay/` into the shop root. The Flex `env` configurator may append a `###> fyrst/shopware-cd ###` block to `.env` (empty shop id, `SHOPWARE_DEPLOY_ENV=live`, `SHOPWARE_DATA_BASE=/var/lib/shopware/data`). It does not overwrite create’s whole `.env` and does not put secrets in that block. Then run `fyrst-cli shopware env init --shop-id ` (VPS: add `--vps`; see `deploy/README.md`). That command does not generate `APP_SECRET` (`shopware-cli project create` already writes it). Install [fyrst-cli](https://github.com/fyrst-dev/cli) 0.1.0+ on each VPS. Commit the copied files; `vendor/` stays gitignored. +Flex copies CI, `deploy/` (CD Compose, edge), `.dockerignore`, and `.env.example` from the package `overlay/` into the shop root. The Flex `env` configurator may append a `###> fyrst/shopware-cd ###` block to `.env` (empty shop id, `SHOPWARE_DEPLOY_ENV=live`, `SHOPWARE_DATA_BASE=/var/lib/shopware/data`). It does not overwrite create’s whole `.env` and does not put secrets in that block. Then run `fyrst-cli shopware env init --shop-id ` (see `deploy/README.md`). That command always comments out create’s `COMPOSE_PROJECT_NAME` (laptop and VPS same). It does not generate `APP_SECRET` (`shopware-cli project create` already writes it). Install [fyrst-cli](https://github.com/fyrst-dev/cli) 0.1.0+ on each VPS. Commit the copied files; `vendor/` stays gitignored. ## Update recipes diff --git a/fyrst/shopware-cd/1.0/README.md b/fyrst/shopware-cd/1.0/README.md index 6815fdf..fab5cc3 100644 --- a/fyrst/shopware-cd/1.0/README.md +++ b/fyrst/shopware-cd/1.0/README.md @@ -24,9 +24,9 @@ docker compose --env-file .env -f deploy/compose.yaml -f deploy/compose.prod.yam CI runs `fyrst-cli shopware deploy release` (existing `IMAGE` / `IMAGE_TAG` / `COMPOSE_DIR`). Rollback is `fyrst-cli shopware deploy rollback`. -Flex `env` may append a `###> fyrst/shopware-cd ###` block to shop-root `.env` (empty `SHOPWARE_SHOP_ID`, `SHOPWARE_DEPLOY_ENV=live`, `SHOPWARE_DATA_BASE=/var/lib/shopware/data`). It does not overwrite create’s whole `.env`. Then run `fyrst-cli shopware env init --shop-id ` (see the copied `deploy/README.md`). That command does not generate `APP_SECRET` (`shopware-cli project create` already writes it). Install fyrst-cli 0.1.0+ on each VPS. +Flex `env` may append a `###> fyrst/shopware-cd ###` block to shop-root `.env` (empty `SHOPWARE_SHOP_ID`, `SHOPWARE_DEPLOY_ENV=live`, `SHOPWARE_DATA_BASE=/var/lib/shopware/data`). It does not overwrite create’s whole `.env`. Then run `fyrst-cli shopware env init --shop-id ` (see the copied `deploy/README.md`). That command always comments out create’s `COMPOSE_PROJECT_NAME=sw-shop-…` line (laptop and VPS same; it overrides Compose `name:`). It does not generate `APP_SECRET` (`shopware-cli project create` already writes it). Install fyrst-cli 0.1.0+ on each VPS. -VPS runtime DB + bind-mount pull (no object storage): `fyrst-cli shopware sync {capture|apply|pull}` — see `deploy/sync-runtime.md`. **Dump stays `shopware-cli project dump`.** **Sync is not a backup** — live backups are `fyrst-cli shopware backup {create|prune|recover}`. Compose source of truth is `SHOPWARE_SHOP_ID` + `SHOPWARE_DEPLOY_ENV` (project name `acme-live`, uploads under `/var/lib/shopware/data/${SHOPWARE_SHOP_ID}/${SHOPWARE_DEPLOY_ENV}`). `COMPOSE_PROJECT_NAME` / `SHOPWARE_DATA_ROOT` are optional script overrides. **VPS:** comment out create’s `COMPOSE_PROJECT_NAME=sw-shop-…` line (`fyrst-cli shopware env init --vps` or by hand; it overrides Compose `name:`). Flex does not delete it on `composer require`. Same-host tag-and-load: `PULL_POLICY=never` / `SKIP_PULL=1`. +VPS runtime DB + bind-mount pull (no object storage): `fyrst-cli shopware sync {capture|apply|pull}` — see `deploy/sync-runtime.md`. **Dump stays `shopware-cli project dump`.** **Sync is not a backup** — live backups are `fyrst-cli shopware backup {create|prune|recover}`. Compose source of truth is `SHOPWARE_SHOP_ID` + `SHOPWARE_DEPLOY_ENV` (project name `acme-live`, uploads under `/var/lib/shopware/data/${SHOPWARE_SHOP_ID}/${SHOPWARE_DEPLOY_ENV}`). `COMPOSE_PROJECT_NAME` / `SHOPWARE_DATA_ROOT` are optional script overrides. Flex does not delete it on `composer require`. Same-host tag-and-load: `PULL_POLICY=never` / `SKIP_PULL=1`. Prod HTTP is loopback-only; host TLS is `deploy/edge/Caddyfile`. `web` healthcheck is `GET /api/_info/health-check` on `127.0.0.1:8000` inside the container. diff --git a/fyrst/shopware-cd/1.0/post-install.txt b/fyrst/shopware-cd/1.0/post-install.txt index 6e2c126..b85f50e 100644 --- a/fyrst/shopware-cd/1.0/post-install.txt +++ b/fyrst/shopware-cd/1.0/post-install.txt @@ -46,7 +46,9 @@ and does not put secrets in that block. Then run fyrst-cli shopware env init --shop-id … (see deploy/README). - That command does not generate APP_SECRET + That command always comments out create’s + COMPOSE_PROJECT_NAME (laptop and VPS same). + It does not generate APP_SECRET (shopware-cli project create already writes it). VPS .env source of truth (required): SHOPWARE_SHOP_ID (same slug on live + staging + laptop), @@ -65,8 +67,8 @@ .env for local project dev. That env var overrides Compose name: (${SHOPWARE_SHOP_ID}-${SHOPWARE_DEPLOY_ENV}). - On the VPS, comment out that line - (fyrst-cli shopware env init --vps or by hand). + fyrst-cli shopware env init always comments out + that line (laptop and VPS same). Flex does not delete it on composer require (create owns the local flow). Bootstrap: @@ -95,7 +97,7 @@ Flex may append SoT keys to .env; it does not overwrite create’s whole .env. Then run fyrst-cli shopware env init --shop-id … - (VPS: add --vps; see deploy/README). + (see deploy/README). If .env is missing, that command copies .env.example first. Commit the copied files; vendor/ is gitignored. diff --git a/fyrst/shopware-cd/1.0/tests/init-env.test.sh b/fyrst/shopware-cd/1.0/tests/init-env.test.sh index 2f7034b..7248bdf 100755 --- a/fyrst/shopware-cd/1.0/tests/init-env.test.sh +++ b/fyrst/shopware-cd/1.0/tests/init-env.test.sh @@ -21,23 +21,34 @@ out="$(fyrst-cli shopware env init --help 2>&1)" rc=$? set -e if [[ "$rc" -eq 0 ]] && printf '%s' "$out" | grep -q -- '--shop-id' \ - && printf '%s' "$out" | grep -q -- '--vps' \ && printf '%s' "$out" | grep -q -- '--dry-run' \ && printf '%s' "$out" | grep -q 'APP_SECRET' \ + && printf '%s' "$out" | grep -q 'COMPOSE_PROJECT_NAME' \ + && ! printf '%s' "$out" | grep -q -- '--vps' \ && ! printf '%s' "$out" | grep -q 'generate-app-secret'; then - pass "--help lists identity flags; APP_SECRET is not generated" + pass "--help lists identity flags; always-strip; no --vps" else fail "--help rc=$rc out=$out" fi -echo "==> recipe docs omit --generate-app-secret" +echo "==> recipe docs omit --vps / --generate-app-secret; always-strip" +REPO_README="$(cd "$ROOT/../../.." && pwd)/README.md" if ! grep -q 'generate-app-secret' "$ROOT/post-install.txt" \ && ! grep -q 'generate-app-secret' "$ROOT/README.md" \ + && ! grep -q -- '--vps' "$ROOT/post-install.txt" \ + && ! grep -q -- '--vps' "$ROOT/README.md" \ + && ! grep -q -- '--vps' "$REPO_README" \ && grep -q 'APP_SECRET' "$ROOT/post-install.txt" \ - && grep -q 'APP_SECRET' "$ROOT/README.md"; then - pass "recipe docs say env init leaves APP_SECRET alone" + && grep -q 'APP_SECRET' "$ROOT/README.md" \ + && grep -q 'always comments out' "$ROOT/post-install.txt" \ + && grep -q 'always comments out' "$ROOT/README.md" \ + && grep -q 'always comments out' "$REPO_README" \ + && grep -q 'laptop and VPS same' "$ROOT/post-install.txt" \ + && grep -q 'laptop and VPS same' "$ROOT/README.md" \ + && grep -q 'laptop and VPS same' "$REPO_README"; then + pass "recipe docs: always-strip COMPOSE_PROJECT_NAME; laptop and VPS same" else - fail "recipe docs missing APP_SECRET contract or still mention --generate-app-secret" + fail "recipe docs still mention --vps / --generate-app-secret or miss always-strip" fi echo "==> manifest Flex env (safe defaults) + copy-from-package" @@ -78,7 +89,7 @@ else fail "missing both files rc=$rc out=$out" fi -echo "==> dry-run does not write; real run merges + sets shop id + --vps" +echo "==> dry-run does not write; real run always comments COMPOSE_PROJECT_NAME" SHOP="$TMP/acme" mkdir -p "$SHOP" write_stub_env_example "$SHOP" @@ -99,7 +110,7 @@ EOF cp "$SHOP/.env" "$SHOP/.env.before" set +e -out="$(COMPOSE_DIR="$SHOP" fyrst-cli shopware env init --shop-id acme --env live --vps --image ghcr.io/example/acme --dry-run 2>&1)" +out="$(COMPOSE_DIR="$SHOP" fyrst-cli shopware env init --shop-id acme --env live --image ghcr.io/example/acme --dry-run 2>&1)" rc=$? set -e if [[ "$rc" -eq 0 ]] && printf '%s' "$out" | grep -q 'DRY-RUN' \ @@ -107,10 +118,11 @@ if [[ "$rc" -eq 0 ]] && printf '%s' "$out" | grep -q 'DRY-RUN' \ && printf '%s' "$out" | grep -q 'COMPOSE_PROJECT_NAME' \ && printf '%s' "$out" | grep -q 'IMAGE=ghcr.io/example/acme' \ && printf '%s' "$out" | grep -q 'APP_SECRET' \ + && ! printf '%s' "$out" | grep -q -- '--vps' \ && ! printf '%s' "$out" | grep -q 'generate-app-secret' \ && ! printf '%s' "$out" | grep -q 'set APP_SECRET' \ && ! printf '%s' "$out" | grep -q 'oldsecret'; then - pass "dry-run summary sets shop id, image, and leaves APP_SECRET alone" + pass "dry-run summary sets shop id, image, and always-strip without --vps" else fail "dry-run rc=$rc out=$out" fi @@ -121,13 +133,14 @@ else fi set +e -out="$(COMPOSE_DIR="$SHOP" fyrst-cli shopware env init --shop-id acme --env live --vps --image ghcr.io/example/acme 2>&1)" +out="$(COMPOSE_DIR="$SHOP" fyrst-cli shopware env init --shop-id acme --env live --image ghcr.io/example/acme 2>&1)" rc=$? set -e if [[ "$rc" -eq 0 ]] && printf '%s' "$out" | grep -q 'SHOPWARE_SHOP_ID=acme' \ && printf '%s' "$out" | grep -q 'commented' \ - && printf '%s' "$out" | grep -q 'COMPOSE_PROJECT_NAME'; then - pass "real run summary sets shop id and comments COMPOSE_PROJECT_NAME" + && printf '%s' "$out" | grep -q 'COMPOSE_PROJECT_NAME' \ + && ! printf '%s' "$out" | grep -q -- '--vps'; then + pass "real run summary sets shop id and always comments COMPOSE_PROJECT_NAME" else fail "real run rc=$rc out=$out" fi @@ -148,12 +161,12 @@ else fail "clobbered operator secrets" fi if grep -q '^# COMPOSE_PROJECT_NAME=sw-shop-acme' "$envf" \ - && grep -q 'restore for local project dev' "$envf" \ + && ! grep -q -- '--vps' "$envf" \ && ! grep -q '^COMPOSE_PROJECT_NAME=' "$envf" \ && ! grep -q '^COMPOSE_PROJECT_NAME=$' "$envf"; then - pass "--vps comments COMPOSE_PROJECT_NAME and does not leave COMPOSE_PROJECT_NAME=" + pass "always comments COMPOSE_PROJECT_NAME and does not leave COMPOSE_PROJECT_NAME=" else - fail "--vps did not comment COMPOSE_PROJECT_NAME correctly: $(grep COMPOSE_PROJECT_NAME "$envf" || true)" + fail "did not comment COMPOSE_PROJECT_NAME correctly: $(grep COMPOSE_PROJECT_NAME "$envf" || true)" fi if grep -q '^HTTP_PORT=' "$envf" && grep -q '^MYSQL_DATABASE=' "$envf"; then pass "merged missing keys from .env.example" @@ -259,16 +272,51 @@ else fail "generate-app-secret still accepted rc=$rc secret2=$secret2 out=$out" fi -echo "==> --vps is idempotent (already commented)" +echo "==> laptop env init also comments COMPOSE_PROJECT_NAME" +LAP="$TMP/laptop" +mkdir -p "$LAP" +write_stub_env_example "$LAP" +cat >"$LAP/.env" <<'EOF' +SHOPWARE_SHOP_ID= +SHOPWARE_DEPLOY_ENV=dev +COMPOSE_PROJECT_NAME=sw-shop-widgets +EOF +set +e +out="$(COMPOSE_DIR="$LAP" fyrst-cli shopware env init --shop-id widgets 2>&1)" +rc=$? +set -e +if [[ "$rc" -eq 0 ]] && grep -q '^# COMPOSE_PROJECT_NAME=sw-shop-widgets' "$LAP/.env" \ + && grep -q '^SHOPWARE_DEPLOY_ENV=dev$' "$LAP/.env" \ + && ! grep -q '^COMPOSE_PROJECT_NAME=' "$LAP/.env" \ + && printf '%s' "$out" | grep -q 'commented' \ + && ! printf '%s' "$out" | grep -q -- '--vps'; then + pass "laptop env init comments COMPOSE_PROJECT_NAME (same as VPS)" +else + fail "laptop always-strip rc=$rc out=$out env=$(grep COMPOSE_PROJECT_NAME "$LAP/.env" || true)" +fi + +echo "==> --vps is rejected" set +e out="$(COMPOSE_DIR="$SHOP" fyrst-cli shopware env init --shop-id acme --vps 2>&1)" rc=$? set -e -count="$(grep -c 'commented by deploy/init-env.sh --vps' "$SHOP/.env" || true)" -if [[ "$rc" -eq 0 && "$count" -eq 1 ]] && printf '%s' "$out" | grep -q 'no uncommented COMPOSE_PROJECT_NAME'; then - pass "second --vps does not double-comment" +if [[ "$rc" -ne 0 ]] && printf '%s' "$out" | grep -qiE 'unexpected argument|unexpected'; then + pass "--vps is rejected" +else + fail "--vps still accepted rc=$rc out=$out" +fi + +echo "==> always-strip is idempotent (already commented)" +set +e +out="$(COMPOSE_DIR="$SHOP" fyrst-cli shopware env init --shop-id acme 2>&1)" +rc=$? +set -e +count="$(grep -c '^# COMPOSE_PROJECT_NAME=sw-shop-acme' "$SHOP/.env" || true)" +if [[ "$rc" -eq 0 && "$count" -eq 1 ]] && printf '%s' "$out" | grep -q 'no uncommented COMPOSE_PROJECT_NAME' \ + && ! printf '%s' "$out" | grep -q -- '--vps'; then + pass "second env init does not double-comment COMPOSE_PROJECT_NAME" else - fail "idempotent --vps rc=$rc count=$count out=$out" + fail "idempotent always-strip rc=$rc count=$count out=$out" fi if [[ "$FAILS" -ne 0 ]]; then diff --git a/fyrst/shopware-cd/1.0/tests/vps-hardening.test.sh b/fyrst/shopware-cd/1.0/tests/vps-hardening.test.sh index c713f31..5b2dc44 100755 --- a/fyrst/shopware-cd/1.0/tests/vps-hardening.test.sh +++ b/fyrst/shopware-cd/1.0/tests/vps-hardening.test.sh @@ -264,11 +264,19 @@ if grep -q 'does not delete it' "$ROOT/post-install.txt" \ else fail "docs missing do-not-auto-delete wording" fi -if grep -q 'env init --vps' "$ROOT/post-install.txt" \ - && grep -q 'env init --vps' "$ROOT/README.md"; then - pass "docs point at fyrst-cli shopware env init --vps for the VPS footgun" +if ! grep -q -- '--vps' "$ROOT/post-install.txt" \ + && ! grep -q -- '--vps' "$ROOT/README.md"; then + pass "docs do not mention --vps" else - fail "docs missing env init --vps" + fail "docs still mention --vps" +fi +if grep -q 'always comments out' "$ROOT/post-install.txt" \ + && grep -q 'always comments out' "$ROOT/README.md" \ + && grep -q 'laptop and VPS same' "$ROOT/post-install.txt" \ + && grep -q 'laptop and VPS same' "$ROOT/README.md"; then + pass "docs say env init always comments COMPOSE_PROJECT_NAME (laptop and VPS same)" +else + fail "docs missing always-strip COMPOSE_PROJECT_NAME wording" fi if grep -q 'env init --shop-id' "$ROOT/post-install.txt"; then pass "post-install documents Flex env + env init --shop-id" diff --git a/fyrst/shopware-cd/1.0/tests/wrappers.test.sh b/fyrst/shopware-cd/1.0/tests/wrappers.test.sh index 43134b2..0797713 100755 --- a/fyrst/shopware-cd/1.0/tests/wrappers.test.sh +++ b/fyrst/shopware-cd/1.0/tests/wrappers.test.sh @@ -96,6 +96,27 @@ do fi done +echo "==> env init always-strip; --vps gone" +set +e +out="$(fyrst-cli shopware env init --help 2>&1)" +rc=$? +set -e +if [[ "$rc" -eq 0 ]] && ! printf '%s' "$out" | grep -q -- '--vps' \ + && printf '%s' "$out" | grep -q 'COMPOSE_PROJECT_NAME'; then + pass "env init --help has no --vps; documents COMPOSE_PROJECT_NAME" +else + fail "env init --help still lists --vps rc=$rc out=$out" +fi +set +e +out="$(fyrst-cli shopware env init --vps 2>&1)" +rc=$? +set -e +if [[ "$rc" -ne 0 ]] && printf '%s' "$out" | grep -qiE 'unexpected argument|unexpected'; then + pass "env init rejects --vps" +else + fail "env init still accepts --vps rc=$rc out=$out" +fi + echo "==> sync local --data all stays rejected" TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT @@ -135,11 +156,13 @@ if grep -q 'fyrst-cli shopware deploy release' "$ROOT/post-install.txt" \ && ! grep -q 'bash deploy/sync-runtime.sh' "$ROOT/post-install.txt" \ && ! grep -q 'generate-app-secret' "$ROOT/post-install.txt" \ && ! grep -q 'generate-app-secret' "$ROOT/README.md" \ + && ! grep -q -- '--vps' "$ROOT/post-install.txt" \ + && ! grep -q -- '--vps' "$ROOT/README.md" \ && ! grep -q 'copy-from-recipe' "$ROOT/manifest.json" \ && grep -q 'copy-from-package' "$ROOT/README.md"; then - pass "recipe docs are fyrst-cli lifecycle verbs (no wrappers / copy-from-recipe)" + pass "recipe docs are fyrst-cli lifecycle verbs (no wrappers / --vps / copy-from-recipe)" else - fail "recipe docs still document bash wrappers, copy-from-recipe, or --generate-app-secret" + fail "recipe docs still document bash wrappers, copy-from-recipe, --vps, or --generate-app-secret" fi if [[ "$FAILS" -ne 0 ]]; then