@codigodoleo/wp-kit 5.3.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -96
- package/lib/commands/init.js +28 -26
- package/lib/config/versions.js +27 -1
- package/lib/core/cloud-allowlist.js +38 -0
- package/lib/core/generator.js +56 -50
- package/lib/core/infer-ci-capabilities.js +17 -5
- package/lib/prompts/index.js +105 -8
- package/lib/utils/auth-template.js +18 -0
- package/lib/utils/env-example.js +18 -6
- package/lib/utils/git.js +5 -188
- package/modules/blank-theme/index.js +1 -1
- package/modules/deploy/index.js +15 -0
- package/modules/deploy/scripts/check-exposure.sh +63 -0
- package/modules/deploy/templates/.github/workflows/ci.yml.hbs +28 -0
- package/modules/docs/index.js +18 -18
- package/modules/docs/templates/README.md.hbs +1 -1
- package/modules/docs/templates/docs/Arquitetura.md.hbs +2 -2
- package/modules/docs/templates/docs/Deploy-Pipeline.md.hbs +21 -1
- package/modules/docs/templates/docs/Development.md.hbs +236 -0
- package/modules/docs/templates/docs/Getting-Started.md.hbs +75 -4
- package/modules/docs/templates/docs/Infraestrutura.md.hbs +1 -1
- package/modules/docs/templates/docs/Troubleshooting.md.hbs +34 -1
- package/modules/git/.husky/kivo-wp/commit-msg +3 -0
- package/modules/git/.husky/kivo-wp/pre-commit +25 -0
- package/modules/git/.husky/pre-commit +3 -7
- package/modules/git/.lintstagedrc.json +5 -2
- package/modules/git/index.js +19 -2
- package/modules/git/templates/.lando.yml.hbs +5 -0
- package/modules/git/templates/package.json.hbs +1 -1
- package/modules/kivo-wp/fixtures/menus.json +11 -0
- package/modules/kivo-wp/fixtures/options.json +10 -0
- package/modules/kivo-wp/fixtures/posts.json +58 -0
- package/modules/kivo-wp/fixtures/seed.php +152 -0
- package/modules/kivo-wp/fixtures/terms.json +6 -0
- package/modules/kivo-wp/fixtures/users.json +26 -0
- package/modules/kivo-wp/index.js +193 -0
- package/modules/kivo-wp/prompts.js +1 -0
- package/modules/kivo-wp/templates/.devcontainer/devcontainer.json.hbs +40 -0
- package/modules/kivo-wp/templates/.dockerignore.hbs +15 -0
- package/modules/kivo-wp/templates/Dockerfile.hbs +83 -0
- package/modules/kivo-wp/templates/bin/_lib.sh.hbs +137 -0
- package/modules/kivo-wp/templates/bin/build.hbs +13 -0
- package/modules/kivo-wp/templates/bin/composer.hbs +6 -0
- package/modules/kivo-wp/templates/bin/db-export.hbs +18 -0
- package/modules/kivo-wp/templates/bin/db-import.hbs +26 -0
- package/modules/kivo-wp/templates/bin/db.hbs +6 -0
- package/modules/kivo-wp/templates/bin/dev.hbs +7 -0
- package/modules/kivo-wp/templates/bin/down.hbs +34 -0
- package/modules/kivo-wp/templates/bin/e2e.hbs +48 -0
- package/modules/kivo-wp/templates/bin/flush.hbs +11 -0
- package/modules/kivo-wp/templates/bin/info.hbs +15 -0
- package/modules/kivo-wp/templates/bin/logs.hbs +6 -0
- package/modules/kivo-wp/templates/bin/mago.hbs +8 -0
- package/modules/kivo-wp/templates/bin/node.hbs +6 -0
- package/modules/kivo-wp/templates/bin/npm.hbs +6 -0
- package/modules/kivo-wp/templates/bin/php.hbs +6 -0
- package/modules/kivo-wp/templates/bin/reset-deps.hbs +11 -0
- package/modules/kivo-wp/templates/bin/seed.hbs +21 -0
- package/modules/kivo-wp/templates/bin/setup.hbs +283 -0
- package/modules/kivo-wp/templates/bin/shell.hbs +14 -0
- package/modules/kivo-wp/templates/bin/stan.hbs +8 -0
- package/modules/kivo-wp/templates/bin/test.hbs +6 -0
- package/modules/kivo-wp/templates/bin/trust-cert.hbs +21 -0
- package/modules/kivo-wp/templates/bin/up.hbs +6 -0
- package/modules/kivo-wp/templates/bin/wp.hbs +6 -0
- package/modules/kivo-wp/templates/bin/xdebug.hbs +22 -0
- package/modules/kivo-wp/templates/compose.yaml.hbs +117 -0
- package/modules/kivo-wp/templates/content/mu-plugins/kivo-wp-local-mail.php.hbs +29 -0
- package/modules/kivo-wp/templates/docs/cloud-sessions.md.hbs +34 -0
- package/modules/kivo-wp/templates/server/caddy/Caddyfile.hbs +44 -0
- package/modules/kivo-wp/templates/server/nginx/deny.conf.hbs +26 -0
- package/modules/lint/index.js +22 -14
- package/modules/lint/templates/package.json.hbs +6 -0
- package/modules/php/index.js +18 -1
- package/modules/php/kivo-wp/php-wrapper.sh +3 -0
- package/modules/php/kivo-wp/pint-wrapper.sh +3 -0
- package/modules/php/templates/phpstan.neon.dist.hbs +27 -0
- package/modules/sage/index.js +4 -26
- package/modules/sage/templates/bin/theme-lint.hbs +6 -0
- package/modules/sage/templates/server/cmd/setup-sage-node.sh.hbs +3 -1
- package/modules/sage/templates/server/cmd/setup-sage-php.sh.hbs +3 -1
- package/modules/sage/templates/theme/vite.config.js.hbs +20 -2
- package/modules/sage/templates/workspace.json.hbs +0 -57
- package/modules/skills/index.js +56 -11
- package/modules/skills/prompts.js +3 -16
- package/modules/test/index.js +13 -11
- package/modules/test/phpunit.xml +18 -0
- package/modules/test/templates/playwright.config.js.hbs +23 -0
- package/modules/test/tests/SmokeTest.php +8 -9
- package/modules/test/tests/e2e/smoke.spec.js +28 -0
- package/package.json +3 -2
- package/templates/.env.hbs +16 -5
- package/templates/.gitignore.hbs +8 -1
- package/templates/.lando.yml.hbs +3 -9
- package/templates/CLAUDE.md.hbs +33 -15
- package/templates/README.md.hbs +38 -12
- package/templates/composer.json.hbs +1 -1
- package/templates/package.json.hbs +8 -1
- package/templates/server/cmd/install-wp.sh.hbs +1 -1
- package/templates/server/cmd/setup-node.sh.hbs +3 -1
- package/templates/server/cmd/setup-php.sh.hbs +63 -9
- package/templates/workspace.json.hbs +0 -56
- package/{wp-config.php → templates/wp-config.php.hbs} +56 -14
- package/modules/docs/templates/docs/Desenvolvimento.md.hbs +0 -127
- package/modules/lint/templates/.lando.yml.hbs +0 -5
- package/modules/sage/templates/.devcontainer/devcontainer.json.hbs +0 -7
- package/modules/sage/templates/.devcontainer/docker-compose.override.yml.hbs +0 -4
- package/modules/sage/templates/.devcontainer/post-create.sh.hbs +0 -11
- package/templates/.devcontainer/Dockerfile.hbs +0 -24
- package/templates/.devcontainer/config/nginx.conf +0 -23
- package/templates/.devcontainer/config/nginx.conf.hbs +0 -23
- package/templates/.devcontainer/devcontainer.json.hbs +0 -29
- package/templates/.devcontainer/docker-compose.yml.hbs +0 -76
- package/templates/.devcontainer/setup.sh.hbs +0 -17
- package/templates/auth.json.hbs +0 -8
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# One-command, idempotent onboarding of the kivo-wp environment (local, CI, Codespaces, cloud).
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
PROJECT_NAME="{{projectName}}"
|
|
7
|
+
ACF_PLACEHOLDER="op://<vault>/<item>"
|
|
8
|
+
|
|
9
|
+
usage() {
|
|
10
|
+
cat <<'USAGE'
|
|
11
|
+
Usage: bin/setup [--ci] [--cloud] [--quick] [--fresh]
|
|
12
|
+
|
|
13
|
+
Builds and starts the kivo-wp stack, installs dependencies, installs WordPress, seeds synthetic
|
|
14
|
+
fixtures into an empty database and prints the URLs. Safe to run again.
|
|
15
|
+
|
|
16
|
+
--ci non-interactive: never prompts, skips the certificate trust step, stops at the first error
|
|
17
|
+
--cloud cloud agent session: no auth.json is created (licensed packages come from the session proxy)
|
|
18
|
+
--quick only start the stack and verify a previous setup
|
|
19
|
+
--fresh reset the database and reseed the fixtures
|
|
20
|
+
--help show this help
|
|
21
|
+
USAGE
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
ci=false
|
|
25
|
+
cloud=false
|
|
26
|
+
quick=false
|
|
27
|
+
fresh=false
|
|
28
|
+
for arg in "$@"; do
|
|
29
|
+
case "${arg}" in
|
|
30
|
+
--ci) ci=true ;;
|
|
31
|
+
--cloud) cloud=true ;;
|
|
32
|
+
--quick) quick=true ;;
|
|
33
|
+
--fresh) fresh=true ;;
|
|
34
|
+
-h | --help)
|
|
35
|
+
usage
|
|
36
|
+
exit 0
|
|
37
|
+
;;
|
|
38
|
+
*)
|
|
39
|
+
usage >&2
|
|
40
|
+
exit 2
|
|
41
|
+
;;
|
|
42
|
+
esac
|
|
43
|
+
done
|
|
44
|
+
[ "${CLAUDE_CODE_REMOTE:-}" = "true" ] && cloud=true
|
|
45
|
+
[ "${CI:-}" = "true" ] && ci=true
|
|
46
|
+
|
|
47
|
+
step() {
|
|
48
|
+
printf '\n==> %s\n' "$*" >&2
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
port_in_use() {
|
|
52
|
+
(exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# Port published by this project's proxy for a container port, empty when not running.
|
|
56
|
+
published_port() {
|
|
57
|
+
local mapping
|
|
58
|
+
mapping="$(kivo_wp_compose port proxy "$1" 2>/dev/null | head -n 1 || true)"
|
|
59
|
+
printf '%s\n' "${mapping##*:}"
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
# Where the search for a replacement starts: 8443/8080 for the standard ports (the ports right
|
|
63
|
+
# above them are often reserved, for example 445 by SMB), otherwise the next port.
|
|
64
|
+
first_alternative() {
|
|
65
|
+
case "$1" in
|
|
66
|
+
443) echo 8443 ;;
|
|
67
|
+
80) echo 8080 ;;
|
|
68
|
+
*) echo $(($1 + 1)) ;;
|
|
69
|
+
esac
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# First port from $1 that no local listener holds, within 100 ports.
|
|
73
|
+
next_free_port() {
|
|
74
|
+
local candidate
|
|
75
|
+
for candidate in $(seq "$1" $(($1 + 100))); do
|
|
76
|
+
if ! port_in_use "${candidate}"; then
|
|
77
|
+
printf '%s\n' "${candidate}"
|
|
78
|
+
return
|
|
79
|
+
fi
|
|
80
|
+
done
|
|
81
|
+
kivo_wp_die "no free port found between $1 and $(($1 + 100))"
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Keep the configured port when it is free or already ours; otherwise pick the next free one.
|
|
85
|
+
choose_port() {
|
|
86
|
+
local key="$1" container_port="$2" fallback="$3" current ours
|
|
87
|
+
current="$(kivo_wp_env_get "${key}")"
|
|
88
|
+
current="${current:-${fallback}}"
|
|
89
|
+
ours="$(published_port "${container_port}")"
|
|
90
|
+
if [ "${ours}" = "${current}" ] || ! port_in_use "${current}"; then
|
|
91
|
+
printf '%s\n' "${current}"
|
|
92
|
+
return
|
|
93
|
+
fi
|
|
94
|
+
local candidate
|
|
95
|
+
candidate="$(next_free_port "$(first_alternative "${current}")")"
|
|
96
|
+
kivo_wp_err "port ${current} is busy; using ${candidate} for ${key}"
|
|
97
|
+
printf '%s\n' "${candidate}"
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
site_url_for() {
|
|
101
|
+
local https_port="$1" http_port="$2"
|
|
102
|
+
if [ "${CODESPACES:-}" = "true" ]; then
|
|
103
|
+
# The forwarder terminates TLS and reaches Caddy on the HTTP port (see the Caddyfile).
|
|
104
|
+
printf 'https://%s-%s.%s\n' "${CODESPACE_NAME:?}" "${http_port}" "${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN:?}"
|
|
105
|
+
elif [ "${https_port}" = "443" ]; then
|
|
106
|
+
printf 'https://%s.localhost\n' "${PROJECT_NAME}"
|
|
107
|
+
else
|
|
108
|
+
printf 'https://%s.localhost:%s\n' "${PROJECT_NAME}" "${https_port}"
|
|
109
|
+
fi
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
# 1. Tooling and .env ----------------------------------------------------------------------
|
|
113
|
+
step "Checking Docker"
|
|
114
|
+
command -v docker >/dev/null 2>&1 || kivo_wp_die "docker not found; install Docker Engine or Docker Desktop"
|
|
115
|
+
docker compose version >/dev/null 2>&1 || kivo_wp_die "docker compose v2 not found"
|
|
116
|
+
|
|
117
|
+
env_file="${KIVO_WP_ROOT}/.env"
|
|
118
|
+
if [ ! -f "${env_file}" ]; then
|
|
119
|
+
[ -f "${KIVO_WP_ROOT}/.env.example" ] || kivo_wp_die ".env.example not found"
|
|
120
|
+
(umask 077 && cp "${KIVO_WP_ROOT}/.env.example" "${env_file}")
|
|
121
|
+
kivo_wp_err "created .env from .env.example"
|
|
122
|
+
fi
|
|
123
|
+
# Local, per-environment values (D-006): not secrets.
|
|
124
|
+
[ -n "$(kivo_wp_env_get WORDPRESS_DB_PASSWORD)" ] || kivo_wp_env_set WORDPRESS_DB_PASSWORD '"wordpress"'
|
|
125
|
+
[ -n "$(kivo_wp_env_get USER_ID)" ] || kivo_wp_env_set USER_ID "$(id -u)"
|
|
126
|
+
[ -n "$(kivo_wp_env_get GROUP_ID)" ] || kivo_wp_env_set GROUP_ID "$(id -g)"
|
|
127
|
+
|
|
128
|
+
if [ "${quick}" = true ]; then
|
|
129
|
+
step "Starting the stack"
|
|
130
|
+
kivo_wp_compose up -d --wait
|
|
131
|
+
kivo_wp_exec app wp core is-installed --path=wp >/dev/null 2>&1 ||
|
|
132
|
+
kivo_wp_die "WordPress is not installed; run bin/setup without --quick"
|
|
133
|
+
"${KIVO_WP_ROOT}/bin/info"
|
|
134
|
+
exit 0
|
|
135
|
+
fi
|
|
136
|
+
|
|
137
|
+
# 2. Ports and site URL (D-013) ---------------------------------------------------------------
|
|
138
|
+
step "Choosing ports"
|
|
139
|
+
https_port="$(choose_port HTTPS_PORT 443 443)"
|
|
140
|
+
http_port="$(choose_port HTTP_PORT 80 80)"
|
|
141
|
+
[ "$(kivo_wp_env_get HTTPS_PORT)" = "${https_port}" ] || kivo_wp_env_set HTTPS_PORT "${https_port}"
|
|
142
|
+
[ "$(kivo_wp_env_get HTTP_PORT)" = "${http_port}" ] || kivo_wp_env_set HTTP_PORT "${http_port}"
|
|
143
|
+
site_url="$(site_url_for "${https_port}" "${http_port}")"
|
|
144
|
+
[ "$(kivo_wp_env_get WORDPRESS_SITE_URL)" = "${site_url}" ] || kivo_wp_env_set WORDPRESS_SITE_URL "\"${site_url}\""
|
|
145
|
+
|
|
146
|
+
# Codespaces: requests to the private forwarded URL fail GitHub's authentication, so WP-Cron
|
|
147
|
+
# leaves the request path; the devcontainer postStartCommand runs due events every minute.
|
|
148
|
+
if [ "${CODESPACES:-}" = "true" ]; then
|
|
149
|
+
[ "$(kivo_wp_env_get WORDPRESS_DISABLE_WP_CRON)" = "true" ] || kivo_wp_env_set WORDPRESS_DISABLE_WP_CRON true
|
|
150
|
+
else
|
|
151
|
+
kivo_wp_env_unset WORDPRESS_DISABLE_WP_CRON
|
|
152
|
+
fi
|
|
153
|
+
|
|
154
|
+
# 3. Licensed Composer credentials (D-014) ----------------------------------------------------
|
|
155
|
+
template="${KIVO_WP_ROOT}/auth.json.tpl"
|
|
156
|
+
auth="${KIVO_WP_ROOT}/auth.json"
|
|
157
|
+
if [ -f "${template}" ] && [ "${cloud}" = false ]; then
|
|
158
|
+
if [ ! -f "${auth}" ] || [ "${template}" -nt "${auth}" ]; then
|
|
159
|
+
step "Rendering auth.json from 1Password references"
|
|
160
|
+
grep -qF "${ACF_PLACEHOLDER}" "${template}" &&
|
|
161
|
+
kivo_wp_die "auth.json.tpl still has the placeholder ${ACF_PLACEHOLDER}; set the acf_op_reference prompt value (op://<vault>/<item>) in auth.json.tpl"
|
|
162
|
+
command -v op >/dev/null 2>&1 ||
|
|
163
|
+
kivo_wp_die "1Password CLI (op) not found; install it (https://developer.1password.com/docs/cli/get-started/) and sign in"
|
|
164
|
+
op whoami >/dev/null 2>&1 || kivo_wp_die "1Password CLI is not signed in; run: eval \"\$(op signin)\""
|
|
165
|
+
(umask 077 && op inject --force -i "${template}" -o "${auth}" >/dev/null)
|
|
166
|
+
chmod 600 "${auth}"
|
|
167
|
+
fi
|
|
168
|
+
fi
|
|
169
|
+
|
|
170
|
+
# 4. Build and start --------------------------------------------------------------------------
|
|
171
|
+
step "Building the images"
|
|
172
|
+
kivo_wp_compose build
|
|
173
|
+
|
|
174
|
+
if ! grep -qE '^WORDPRESS_AUTH_KEY=.+' "${env_file}"; then
|
|
175
|
+
step "Generating WordPress salts"
|
|
176
|
+
for key in AUTH_KEY SECURE_AUTH_KEY LOGGED_IN_KEY NONCE_KEY AUTH_SALT SECURE_AUTH_SALT LOGGED_IN_SALT NONCE_SALT; do
|
|
177
|
+
salt="$(kivo_wp_compose run --rm --no-deps -T app php -r 'echo base64_encode(random_bytes(48));')"
|
|
178
|
+
kivo_wp_env_set "WORDPRESS_${key}" "${salt}"
|
|
179
|
+
done
|
|
180
|
+
fi
|
|
181
|
+
|
|
182
|
+
step "Starting the stack"
|
|
183
|
+
# A port can be free for this shell and still refused by Docker (for example a port held on the
|
|
184
|
+
# Windows side of WSL); then both ports move up and the start is retried.
|
|
185
|
+
for attempt in 1 2 3; do
|
|
186
|
+
if up_output="$(kivo_wp_compose up -d --wait 2>&1)"; then
|
|
187
|
+
printf '%s\n' "${up_output}" >&2
|
|
188
|
+
break
|
|
189
|
+
fi
|
|
190
|
+
printf '%s\n' "${up_output}" >&2
|
|
191
|
+
if [ "${attempt}" -lt 3 ] && grep -qiE 'ports are not available|address already in use|port is already allocated' <<<"${up_output}"; then
|
|
192
|
+
https_port="$(next_free_port $((https_port + 1)))"
|
|
193
|
+
http_port="$(next_free_port $((http_port + 1)))"
|
|
194
|
+
kivo_wp_err "Docker refused the host ports; retrying with ${https_port} and ${http_port}"
|
|
195
|
+
kivo_wp_env_set HTTPS_PORT "${https_port}"
|
|
196
|
+
kivo_wp_env_set HTTP_PORT "${http_port}"
|
|
197
|
+
site_url="$(site_url_for "${https_port}" "${http_port}")"
|
|
198
|
+
kivo_wp_env_set WORDPRESS_SITE_URL "\"${site_url}\""
|
|
199
|
+
continue
|
|
200
|
+
fi
|
|
201
|
+
kivo_wp_die "the stack did not start"
|
|
202
|
+
done
|
|
203
|
+
|
|
204
|
+
# Cloud sessions: trust Caddy's root CA in the VM so curl, PHP and Playwright accept the site.
|
|
205
|
+
if [ "${cloud}" = true ]; then
|
|
206
|
+
step "Trusting Caddy's local CA in the VM"
|
|
207
|
+
ca_tmp="$(mktemp)"
|
|
208
|
+
KIVO_WP_CERT_OUT="${ca_tmp}" "${KIVO_WP_ROOT}/bin/trust-cert" >/dev/null
|
|
209
|
+
ca_target="${KIVO_WP_CA_DIR:-/usr/local/share/ca-certificates}/kivo-wp-${PROJECT_NAME}.crt"
|
|
210
|
+
if ! cmp -s "${ca_tmp}" "${ca_target}"; then
|
|
211
|
+
sudo install -m 0644 "${ca_tmp}" "${ca_target}"
|
|
212
|
+
sudo update-ca-certificates >/dev/null
|
|
213
|
+
fi
|
|
214
|
+
rm -f "${ca_tmp}"
|
|
215
|
+
fi
|
|
216
|
+
|
|
217
|
+
# 5. Dependencies -----------------------------------------------------------------------------
|
|
218
|
+
npm_install() {
|
|
219
|
+
local dir="$1"
|
|
220
|
+
if [ -f "${KIVO_WP_ROOT}/${dir}/package-lock.json" ]; then
|
|
221
|
+
kivo_wp_exec_in node "${dir}" npm ci --no-audit --no-fund
|
|
222
|
+
else
|
|
223
|
+
kivo_wp_exec_in node "${dir}" npm install --no-audit --no-fund
|
|
224
|
+
fi
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
step "Installing dependencies"
|
|
228
|
+
kivo_wp_exec_in app . composer install --no-interaction --no-progress
|
|
229
|
+
{{#if enable_sage}}
|
|
230
|
+
kivo_wp_exec_in app . bash server/cmd/setup-sage-php.sh
|
|
231
|
+
{{/if}}
|
|
232
|
+
npm_install .
|
|
233
|
+
for dir in ${KIVO_WP_THEME_DIRS[@]+"${KIVO_WP_THEME_DIRS[@]}"}; do
|
|
234
|
+
npm_install "${dir}"
|
|
235
|
+
done
|
|
236
|
+
"${KIVO_WP_ROOT}/bin/build"
|
|
237
|
+
|
|
238
|
+
# 6. WordPress --------------------------------------------------------------------------------
|
|
239
|
+
step "Installing WordPress"
|
|
240
|
+
installed=false
|
|
241
|
+
kivo_wp_exec app wp core is-installed --path=wp >/dev/null 2>&1 && installed=true
|
|
242
|
+
if [ "${installed}" = true ]; then
|
|
243
|
+
old_url="$(kivo_wp_exec app wp option get home --path=wp)"
|
|
244
|
+
if [ -n "${old_url}" ] && [ "${old_url}" != "${site_url}" ]; then
|
|
245
|
+
kivo_wp_err "site URL changed: ${old_url} -> ${site_url}"
|
|
246
|
+
kivo_wp_exec app wp search-replace "${old_url}" "${site_url}" --all-tables --path=wp
|
|
247
|
+
fi
|
|
248
|
+
else
|
|
249
|
+
kivo_wp_exec_in app . bash server/cmd/install-wp.sh
|
|
250
|
+
fi
|
|
251
|
+
{{#if enable_sage}}
|
|
252
|
+
kivo_wp_exec app wp theme activate "${PROJECT_NAME}" --path=wp
|
|
253
|
+
kivo_wp_exec app wp acorn optimize:clear --path=wp
|
|
254
|
+
{{/if}}
|
|
255
|
+
|
|
256
|
+
# 7. Fixtures (D-002) -------------------------------------------------------------------------
|
|
257
|
+
if [ "${fresh}" = true ]; then
|
|
258
|
+
step "Resetting the database and reseeding"
|
|
259
|
+
"${KIVO_WP_ROOT}/bin/seed" --reset
|
|
260
|
+
else
|
|
261
|
+
fixtures="$(kivo_wp_exec app wp post list --post_type=any --post_status=any --meta_key=_kivo_wp_fixture --format=count --path=wp)"
|
|
262
|
+
posts="$(kivo_wp_exec app wp post list --post_type=post,page --post_status=any --format=count --path=wp)"
|
|
263
|
+
# A fresh install has at most WordPress's own sample post, sample page and privacy page.
|
|
264
|
+
if [ "${fixtures}" = "0" ] && [ "${posts}" -le 3 ]; then
|
|
265
|
+
step "Seeding synthetic fixtures"
|
|
266
|
+
"${KIVO_WP_ROOT}/bin/seed"
|
|
267
|
+
fi
|
|
268
|
+
fi
|
|
269
|
+
|
|
270
|
+
# 8. Certificate trust and summary ------------------------------------------------------------
|
|
271
|
+
if [ "${ci}" = false ] && [ "${cloud}" = false ]; then
|
|
272
|
+
step "Certificate trust (run the command printed for your system once)"
|
|
273
|
+
"${KIVO_WP_ROOT}/bin/trust-cert"
|
|
274
|
+
fi
|
|
275
|
+
|
|
276
|
+
step "Ready"
|
|
277
|
+
"${KIVO_WP_ROOT}/bin/info"
|
|
278
|
+
admin_user="$(kivo_wp_env_get WORDPRESS_ADMIN_USER)"
|
|
279
|
+
if [ -n "$(kivo_wp_env_get WORDPRESS_ADMIN_PASSWORD)" ]; then
|
|
280
|
+
printf '\nAdmin login: %s (password from WORDPRESS_ADMIN_PASSWORD in .env)\n' "${admin_user:-admin}"
|
|
281
|
+
else
|
|
282
|
+
printf '\nAdmin login: %s / admin (synthetic local user)\n' "${admin_user:-admin}"
|
|
283
|
+
fi
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Open a shell in a service (default app), or run a command there: bin/shell cache valkey-cli
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
service="${1:-app}"
|
|
7
|
+
[ "$#" -gt 0 ] && shift
|
|
8
|
+
if [ "$#" -eq 0 ]; then
|
|
9
|
+
case "${service}" in
|
|
10
|
+
app | node) set -- bash ;;
|
|
11
|
+
*) set -- sh ;;
|
|
12
|
+
esac
|
|
13
|
+
fi
|
|
14
|
+
kivo_wp_exec "${service}" "$@"
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# PHPStan in the app service, configured by phpstan.neon.dist. Without arguments it runs
|
|
3
|
+
# `phpstan analyse` with room for the WordPress stubs; any arguments pass through.
|
|
4
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
5
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
6
|
+
|
|
7
|
+
[ "$#" -gt 0 ] || set -- analyse --memory-limit=1G
|
|
8
|
+
kivo_wp_exec app vendor/bin/phpstan "$@"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Export Caddy's local root CA and print the command that trusts it on this OS (never runs it).
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
kivo_wp_require_running proxy
|
|
7
|
+
out="${KIVO_WP_CERT_OUT:-${TMPDIR:-/tmp}/kivo-wp-{{projectName}}-root.crt}"
|
|
8
|
+
kivo_wp_compose cp proxy:/data/caddy/pki/authorities/local/root.crt "${out}" >/dev/null
|
|
9
|
+
printf "Caddy root CA exported to %s\n\n" "${out}"
|
|
10
|
+
|
|
11
|
+
printf 'Linux (Debian/Ubuntu):\n'
|
|
12
|
+
printf ' sudo cp "%s" /usr/local/share/ca-certificates/kivo-wp-{{projectName}}.crt && sudo update-ca-certificates\n\n' "${out}"
|
|
13
|
+
printf 'macOS:\n'
|
|
14
|
+
printf ' sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "%s"\n\n' "${out}"
|
|
15
|
+
|
|
16
|
+
if [ -n "${WSL_DISTRO_NAME:-}" ]; then
|
|
17
|
+
windows_path="\\\\wsl.localhost\\${WSL_DISTRO_NAME}${out//\//\\}"
|
|
18
|
+
printf 'Windows (browsers on the Windows side), from an elevated Command Prompt:\n'
|
|
19
|
+
printf ' certutil.exe -addstore -f ROOT "%s"\n' "${windows_path}"
|
|
20
|
+
printf ' Firefox also needs security.enterprise_roots.enabled = true in about:config.\n'
|
|
21
|
+
fi
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Toggle Xdebug without a rebuild: bin/xdebug on [mode] | off | status
|
|
3
|
+
# shellcheck source=_lib.sh source-path=SCRIPTDIR
|
|
4
|
+
source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
|
|
5
|
+
|
|
6
|
+
case "${1:-status}" in
|
|
7
|
+
on)
|
|
8
|
+
mode="${2:-debug,develop}"
|
|
9
|
+
kivo_wp_env_set XDEBUG_MODE "${mode}"
|
|
10
|
+
kivo_wp_compose up -d --no-build app
|
|
11
|
+
kivo_wp_err "Xdebug on (XDEBUG_MODE=${mode})"
|
|
12
|
+
;;
|
|
13
|
+
off)
|
|
14
|
+
kivo_wp_env_set XDEBUG_MODE off
|
|
15
|
+
kivo_wp_compose up -d --no-build app
|
|
16
|
+
kivo_wp_err "Xdebug off"
|
|
17
|
+
;;
|
|
18
|
+
status)
|
|
19
|
+
printf 'XDEBUG_MODE=%s\n' "$(kivo_wp_env_get XDEBUG_MODE)"
|
|
20
|
+
;;
|
|
21
|
+
*) kivo_wp_die "usage: bin/xdebug on [mode] | off | status" ;;
|
|
22
|
+
esac
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
name: kivo-wp-{{projectName}}
|
|
2
|
+
|
|
3
|
+
x-kivo-wp:
|
|
4
|
+
contract: 1
|
|
5
|
+
|
|
6
|
+
services:
|
|
7
|
+
app:
|
|
8
|
+
build:
|
|
9
|
+
context: .
|
|
10
|
+
target: development
|
|
11
|
+
args:
|
|
12
|
+
PHP_VERSION: "{{phpVersion}}"
|
|
13
|
+
USER_ID: "${USER_ID:-1000}"
|
|
14
|
+
GROUP_ID: "${GROUP_ID:-1000}"
|
|
15
|
+
labels:
|
|
16
|
+
dev.hekivo.environment: kivo-wp
|
|
17
|
+
env_file:
|
|
18
|
+
- .env
|
|
19
|
+
environment:
|
|
20
|
+
XDEBUG_MODE: "${XDEBUG_MODE:-off}"
|
|
21
|
+
KIVO_WP_SMTP_HOST: mail
|
|
22
|
+
# Set by GitHub Codespaces in the workspace container; wp-config.php trusts forwarded headers.
|
|
23
|
+
CODESPACES: "${CODESPACES:-}"
|
|
24
|
+
volumes:
|
|
25
|
+
- .:/var/www/html
|
|
26
|
+
extra_hosts:
|
|
27
|
+
- "host.docker.internal:host-gateway"
|
|
28
|
+
depends_on:
|
|
29
|
+
db:
|
|
30
|
+
condition: service_healthy
|
|
31
|
+
cache:
|
|
32
|
+
condition: service_healthy
|
|
33
|
+
healthcheck:
|
|
34
|
+
test: ["CMD", "curl", "-fsS", "http://localhost:8080/healthcheck"]
|
|
35
|
+
interval: 10s
|
|
36
|
+
timeout: 5s
|
|
37
|
+
retries: 12
|
|
38
|
+
start_period: 20s
|
|
39
|
+
|
|
40
|
+
db:
|
|
41
|
+
image: {{kivoWp.images.db}}
|
|
42
|
+
labels:
|
|
43
|
+
dev.hekivo.environment: kivo-wp
|
|
44
|
+
# Local, per-environment database: non-secret defaults (D-006).
|
|
45
|
+
environment:
|
|
46
|
+
MYSQL_DATABASE: "${WORDPRESS_DB_NAME:-wordpress}"
|
|
47
|
+
MYSQL_USER: "${WORDPRESS_DB_USER:-wordpress}"
|
|
48
|
+
MYSQL_PASSWORD: "${WORDPRESS_DB_PASSWORD:-wordpress}"
|
|
49
|
+
MYSQL_ROOT_PASSWORD: root
|
|
50
|
+
volumes:
|
|
51
|
+
- db-data:/var/lib/mysql
|
|
52
|
+
healthcheck:
|
|
53
|
+
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "--silent"]
|
|
54
|
+
interval: 5s
|
|
55
|
+
timeout: 5s
|
|
56
|
+
retries: 30
|
|
57
|
+
start_period: 20s
|
|
58
|
+
|
|
59
|
+
cache:
|
|
60
|
+
image: {{kivoWp.images.cache}}
|
|
61
|
+
labels:
|
|
62
|
+
dev.hekivo.environment: kivo-wp
|
|
63
|
+
healthcheck:
|
|
64
|
+
test: ["CMD", "valkey-cli", "ping"]
|
|
65
|
+
interval: 5s
|
|
66
|
+
timeout: 3s
|
|
67
|
+
retries: 10
|
|
68
|
+
|
|
69
|
+
proxy:
|
|
70
|
+
image: {{kivoWp.images.proxy}}
|
|
71
|
+
labels:
|
|
72
|
+
dev.hekivo.environment: kivo-wp
|
|
73
|
+
# Caddy listens on the same port numbers as the host, so the site URL (with its port) works
|
|
74
|
+
# from the host and from the other services alike.
|
|
75
|
+
environment:
|
|
76
|
+
HTTPS_PORT: "${HTTPS_PORT:-443}"
|
|
77
|
+
HTTP_PORT: "${HTTP_PORT:-80}"
|
|
78
|
+
CODESPACES: "${CODESPACES:-}"
|
|
79
|
+
ports:
|
|
80
|
+
- "${HTTPS_PORT:-443}:${HTTPS_PORT:-443}"
|
|
81
|
+
- "${HTTP_PORT:-80}:${HTTP_PORT:-80}"
|
|
82
|
+
volumes:
|
|
83
|
+
- ./server/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
|
|
84
|
+
- caddy-data:/data
|
|
85
|
+
depends_on:
|
|
86
|
+
- app
|
|
87
|
+
networks:
|
|
88
|
+
default:
|
|
89
|
+
# *.localhost resolves to loopback inside containers; these aliases send it to Caddy.
|
|
90
|
+
aliases:
|
|
91
|
+
- {{projectName}}.localhost
|
|
92
|
+
- vite.{{projectName}}.localhost
|
|
93
|
+
- mail.{{projectName}}.localhost
|
|
94
|
+
|
|
95
|
+
node:
|
|
96
|
+
image: node:{{nodeVersion}}-bookworm
|
|
97
|
+
labels:
|
|
98
|
+
dev.hekivo.environment: kivo-wp
|
|
99
|
+
user: "${USER_ID:-1000}:${GROUP_ID:-1000}"
|
|
100
|
+
working_dir: /var/www/html
|
|
101
|
+
environment:
|
|
102
|
+
npm_config_cache: /tmp/.npm
|
|
103
|
+
# Read by the theme Vite config for the HMR client (served through Caddy).
|
|
104
|
+
HTTPS_PORT: "${HTTPS_PORT:-443}"
|
|
105
|
+
KIVO_WP_VITE_HOST: vite.{{projectName}}.localhost
|
|
106
|
+
command: ["sleep", "infinity"]
|
|
107
|
+
volumes:
|
|
108
|
+
- .:/var/www/html
|
|
109
|
+
|
|
110
|
+
mail:
|
|
111
|
+
image: {{kivoWp.images.mail}}
|
|
112
|
+
labels:
|
|
113
|
+
dev.hekivo.environment: kivo-wp
|
|
114
|
+
|
|
115
|
+
volumes:
|
|
116
|
+
db-data: {}
|
|
117
|
+
caddy-data: {}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Plugin Name: kivo-wp local mail
|
|
5
|
+
* Description: Sends mail to the local Mailpit service. Active only in the local kivo-wp environment.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
defined('ABSPATH') || exit;
|
|
9
|
+
|
|
10
|
+
(function () {
|
|
11
|
+
$environment = function_exists('wp_get_environment_type') ? wp_get_environment_type() : 'production';
|
|
12
|
+
$host = getenv('KIVO_WP_SMTP_HOST');
|
|
13
|
+
if ($host === false || $host === '') {
|
|
14
|
+
$host = $_ENV['KIVO_WP_SMTP_HOST'] ?? '';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if ($environment !== 'local' || $host === '') {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
add_action('phpmailer_init', function ($phpmailer) use ($host) {
|
|
22
|
+
$phpmailer->isSMTP();
|
|
23
|
+
$phpmailer->Host = $host;
|
|
24
|
+
$phpmailer->Port = 1025;
|
|
25
|
+
$phpmailer->SMTPAuth = false;
|
|
26
|
+
$phpmailer->SMTPSecure = '';
|
|
27
|
+
$phpmailer->SMTPAutoTLS = false;
|
|
28
|
+
});
|
|
29
|
+
})();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Cloud agent sessions
|
|
2
|
+
|
|
3
|
+
How to run **{{projectName}}** in a Claude Code cloud session (an Ubuntu VM with Docker). The
|
|
4
|
+
session gets the repository and synthetic fixtures only; production data never reaches it.
|
|
5
|
+
|
|
6
|
+
## Environment setup script
|
|
7
|
+
|
|
8
|
+
Configure the cloud environment with this single line as its setup script:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
bin/setup --cloud
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
It starts the kivo-wp stack, serves the site at `https://{{projectName}}.localhost` through Caddy,
|
|
15
|
+
installs Caddy's local root CA in the VM trust store (so `curl`, PHP and Playwright trust it without
|
|
16
|
+
`-k`) and seeds the fixtures. It never creates `auth.json`.
|
|
17
|
+
|
|
18
|
+
## Network access
|
|
19
|
+
|
|
20
|
+
In **Limited** network mode, add these hosts to the allowlist:
|
|
21
|
+
|
|
22
|
+
{{#each cloudAllowlist}}
|
|
23
|
+
- `{{this}}`
|
|
24
|
+
{{/each}}
|
|
25
|
+
|
|
26
|
+
## Secrets
|
|
27
|
+
|
|
28
|
+
No secret is stored in the repository, in `devcontainer.json` or in an environment variable of the
|
|
29
|
+
cloud environment: those variables are visible to everyone who can use the environment.
|
|
30
|
+
{{#if enable_acf_pro}}
|
|
31
|
+
ACF Pro's Composer credential is configured by the project owner as a **network secret** for
|
|
32
|
+
`connect.advancedcustomfields.com`; the session proxy attaches it to those requests and the value
|
|
33
|
+
never enters the VM.
|
|
34
|
+
{{/if}}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# kivo-wp proxy (D-012, D-013): TLS with Caddy's local CA for the project hostnames.
|
|
2
|
+
# The root CA lives in the caddy-data volume (/data/caddy/pki/authorities/local/root.crt);
|
|
3
|
+
# bin/trust-cert exports it. Caddy listens on HTTPS_PORT and HTTP_PORT, the same numbers the host
|
|
4
|
+
# publishes, so the site URL is valid inside the Compose network too.
|
|
5
|
+
{
|
|
6
|
+
https_port {$HTTPS_PORT:443}
|
|
7
|
+
http_port {$HTTP_PORT:80}
|
|
8
|
+
# The automatic redirect would drop a non-443 host port; the http:// block below keeps it.
|
|
9
|
+
auto_https disable_redirects
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
{{projectName}}.localhost {
|
|
13
|
+
tls internal
|
|
14
|
+
reverse_proxy app:8080
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
vite.{{projectName}}.localhost {
|
|
18
|
+
tls internal
|
|
19
|
+
reverse_proxy node:5173
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
mail.{{projectName}}.localhost {
|
|
23
|
+
tls internal
|
|
24
|
+
reverse_proxy mail:8025
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
http://{{projectName}}.localhost, http://vite.{{projectName}}.localhost, http://mail.{{projectName}}.localhost {
|
|
28
|
+
redir https://{host}:{$HTTPS_PORT:443}{uri} permanent
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# GitHub Codespaces: the port forwarder terminates TLS and reaches this port over plain HTTP with
|
|
32
|
+
# its own host name, which Caddy's local certificates cannot serve. Only in Codespaces is that
|
|
33
|
+
# traffic passed to WordPress; anywhere else other hosts get 404.
|
|
34
|
+
:{$HTTP_PORT:80} {
|
|
35
|
+
@codespaces expression `{env.CODESPACES} == "true"`
|
|
36
|
+
handle @codespaces {
|
|
37
|
+
reverse_proxy app:8080 {
|
|
38
|
+
header_up X-Forwarded-Proto https
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
handle {
|
|
42
|
+
respond 404
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# kivo-wp: paths under the project root that are never served (the root is the web root).
|
|
2
|
+
# Included in the server block as /etc/nginx/server-opts.d/00-kivo-wp-deny.conf, before the
|
|
3
|
+
# image's own security.conf, so these rules answer 404 instead of its 403.
|
|
4
|
+
# Directory rules use ^~ so they win over every regex location, including the PHP handler.
|
|
5
|
+
|
|
6
|
+
# Directories at the project root.
|
|
7
|
+
location ^~ /vendor/ { return 404; }
|
|
8
|
+
location ^~ /node_modules/ { return 404; }
|
|
9
|
+
location ^~ /server/ { return 404; }
|
|
10
|
+
location ^~ /fixtures/ { return 404; }
|
|
11
|
+
location ^~ /bin/ { return 404; }
|
|
12
|
+
location ^~ /scripts/ { return 404; }
|
|
13
|
+
|
|
14
|
+
# Files at the project root.
|
|
15
|
+
location = /Dockerfile { return 404; }
|
|
16
|
+
location = /wp-cli.yml { return 404; }
|
|
17
|
+
location = /mago.toml { return 404; }
|
|
18
|
+
location ~ ^/(auth\.json|auth\.json\.tpl)$ { return 404; }
|
|
19
|
+
location ~ ^/composer\.[^/]*$ { return 404; }
|
|
20
|
+
location ~ ^/package[^/]*\.json$ { return 404; }
|
|
21
|
+
location ~ ^/compose[^/]*\.ya?ml$ { return 404; }
|
|
22
|
+
location ~ ^/[^/]+\.md$ { return 404; }
|
|
23
|
+
location ~ \.code-workspace$ { return 404; }
|
|
24
|
+
|
|
25
|
+
# Dotfiles and dot-directories anywhere, except /.well-known/ (RFC 8615).
|
|
26
|
+
location ~ /\.(?!well-known/) { return 404; }
|