diff --git a/templates/deployment.yaml b/templates/deployment.yaml index 350b39a..1303d22 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml @@ -21,20 +21,15 @@ spec: - name: wordpress-init image: "{{ .Values.image.wordpress.registry }}/{{ .Values.image.wordpress.repository }}:{{ .Values.image.wordpress.tag }}" imagePullPolicy: {{ .Values.image.wordpress.pullPolicy }} - command: ["/bin/sh"] + command: ["/bin/sh", "-c"] args: - - -c - | - #!/bin/sh set -e - echo "=== WordPress Initialization Started ===" - # WordPress本体ファイルをemptyDirにコピー(使い捨て) echo "Copying WordPress core files to ephemeral storage..." cp -rp /usr/src/wordpress/* /var/www/html/ - # wp-content ディレクトリをPVCに配置(永続化) if [ ! -d /var/www/html-persistent/wp-content ]; then echo "Initializing wp-content directory..." mkdir -p /var/www/html-persistent/wp-content @@ -43,90 +38,64 @@ spec: echo "wp-content already exists, preserving user data" fi - # wp-content をシンボリックリンクで接続 rm -rf /var/www/html/wp-content ln -sf /var/www/html-persistent/wp-content /var/www/html/wp-content - # wp-config.php を Secretから生成(毎回再作成) echo "Generating wp-config.php from Secret..." - cat > /var/www/html/wp-config.php <<'WPCONFIG' - /var/www/html/wp-config.php << 'EOF' + /dev/null || true chmod +x /tmp/wp-cli.phar - # データベース接続待機 echo "Waiting for database connection..." max_attempts=30 attempt=0 @@ -140,24 +109,20 @@ WPCONFIG sleep 2 done - # データベーステーブルの確認 echo "Checking if WordPress is already installed..." TABLES=$(/tmp/wp-cli.phar --path=/var/www/html db query "SHOW TABLES LIKE '${WORDPRESS_TABLE_PREFIX}options';" 2>/dev/null || echo "") if [ -z "$TABLES" ]; then echo "=== Starting WordPress Installation ===" - # 管理者パスワードの処理 if [ -z "$WP_ADMIN_PASSWORD" ]; then WP_ADMIN_PASSWORD=$(tr -dc 'A-Za-z0-9!@#$%^&*' < /dev/urandom | head -c 16) echo "Generated admin password: $WP_ADMIN_PASSWORD" echo "$WP_ADMIN_PASSWORD" > /var/www/html-persistent/.initial-admin-password fi - # 初回インストール用の一時的なURL(後で動的に変更される) INSTALL_URL="http://127.0.0.1" - # WordPressのインストール echo "Installing WordPress..." /tmp/wp-cli.phar --path=/var/www/html core install \ --url="$INSTALL_URL" \ @@ -176,7 +141,6 @@ WPCONFIG else echo "WordPress is already installed, skipping installation" - # コアアップデートの確認 if /tmp/wp-cli.phar --path=/var/www/html core version 2>/dev/null; then CURRENT_VERSION=$(cat /usr/src/wordpress/wp-includes/version.php | grep "wp_version = " | cut -d "'" -f 2) echo "Checking for WordPress updates... Target version: $CURRENT_VERSION" @@ -187,7 +151,7 @@ WPCONFIG {{- if .Values.wordpress.adsTxt.enabled }} echo "Deploying ads.txt..." - cat > /var/www/html/ads.txt <<'ADSTXT' + cat > /var/www/html/ads.txt << 'ADSTXT' {{ .Values.wordpress.adsTxt.content }} ADSTXT echo "ads.txt deployed"