fix: Support random password generation on initial WordPress install
Some checks failed
Helm Chart Release / release-chart (push) Failing after 11s
Update Docker Images and Helm Chart / update (push) Successful in 57s

- Allow empty WP_ADMIN_PASSWORD on initial install for backward compatibility
- Generate secure random password (20 chars) when password is not specified
- During Helm upgrades: Skip installation (WordPress already installed)
- Prevents password mismatch between Kubernetes Secret and WordPress database

Changes:
- Use INSTALL_PASSWORD variable for flexible password handling
- Generate random password with: openssl rand -base64 32 | tr -d "=+/" | cut -c1-20
- Improve logging to distinguish between random generation and manual specification
- Preserve existing database content during upgrades (no password reset)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-12 18:40:36 +09:00
parent b8ed763062
commit 256fc293a6

View File

@@ -145,10 +145,12 @@ spec:
if [ -z "$TABLES" ]; then
echo "=== Starting WordPress Installation ==="
if [ -z "$WP_ADMIN_PASSWORD" ]; then
echo "ERROR: WP_ADMIN_PASSWORD is not set. WordPress installation requires an admin password."
echo "Skipping WordPress installation. Please set WP_ADMIN_PASSWORD in values.yaml"
exit 1
# 初回インストール時のパスワード処理
INSTALL_PASSWORD="$WP_ADMIN_PASSWORD"
if [ -z "$INSTALL_PASSWORD" ]; then
# パスワードが空の場合は、ランダムに生成する
INSTALL_PASSWORD=$(openssl rand -base64 32 | tr -d "=+/" | cut -c1-20)
echo "INFO: WP_ADMIN_PASSWORD is not set. Generated random password."
fi
INSTALL_URL="http://127.0.0.1"
@@ -158,13 +160,17 @@ spec:
--url="$INSTALL_URL" \
--title="$WP_SITE_TITLE" \
--admin_user="$WP_ADMIN_USER" \
--admin_password="$WP_ADMIN_PASSWORD" \
--admin_password="$INSTALL_PASSWORD" \
--admin_email="$WP_ADMIN_EMAIL" \
--skip-email
echo "=== WordPress Installation Completed ==="
echo "Admin User: $WP_ADMIN_USER"
if [ -z "$WP_ADMIN_PASSWORD" ]; then
echo "INFO: Generated admin password. Check Secret for details."
else
echo "Admin password was set from values.yaml"
fi
else
echo "WordPress is already installed, skipping installation"
if [ -f /tmp/wp-cli.phar ]; then