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