From 4cf8c1f35222eed95e360bb1a4de995831c53963 Mon Sep 17 00:00:00 2001 From: pieter Date: Fri, 21 Nov 2025 07:19:24 +0000 Subject: [PATCH] =?UTF-8?q?templates/deployment.yaml=20=E3=82=92=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/deployment.yaml | 59 ++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/templates/deployment.yaml b/templates/deployment.yaml index cf65215..ed4faa8 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml @@ -30,17 +30,26 @@ spec: echo "=== WordPress Initialization Started ===" - # WordPress ファイルのコピー - if [ ! -f /var/www/html/index.php ]; then - echo "Copying WordPress files..." - cp -rp /usr/src/wordpress/* /var/www/html/ 2>/dev/null || true - echo "WordPress files copied" + # 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 + cp -rp /usr/src/wordpress/wp-content/* /var/www/html-persistent/wp-content/ + else + echo "wp-content already exists, preserving user data" fi - # wp-config.php の生成 - if [ ! -f /var/www/html/wp-config.php ]; then - echo "Generating wp-config.php..." - cat > /var/www/html/wp-config.php <<'WPCONFIG' + # 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/.admin-password + # パスワードを永続化領域に保存(初回のみ) + echo "$WP_ADMIN_PASSWORD" > /var/www/html-persistent/.initial-admin-password fi # WordPressのインストール @@ -116,21 +126,22 @@ spec: echo "=== WordPress Installation Completed ===" echo "Admin User: $WP_ADMIN_USER" - if [ -f /var/www/html/.admin-password ]; then - echo "Admin Password: $(cat /var/www/html/.admin-password)" + if [ -f /var/www/html-persistent/.initial-admin-password ]; then + echo "Admin Password: $(cat /var/www/html-persistent/.initial-admin-password)" fi else echo "WordPress is already installed, skipping installation" # コアアップデートの確認 if /tmp/wp-cli.phar --path=/var/www/html core version 2>/dev/null; then - echo "Checking for WordPress updates..." - /tmp/wp-cli.phar --path=/var/www/html core update --version=$(cat /usr/src/wordpress/wp-includes/version.php | grep wp_version | cut -d "'" -f 2) 2>/dev/null || true + 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" + /tmp/wp-cli.phar --path=/var/www/html core update --version=$CURRENT_VERSION 2>/dev/null || true /tmp/wp-cli.phar --path=/var/www/html core update-db 2>/dev/null || true fi fi - # ads.txt の配置 + # ads.txt の配置(使い捨てファイル領域に) {{- if .Values.wordpress.adsTxt.enabled }} echo "Deploying ads.txt..." cat > /var/www/html/ads.txt <<'ADSTXT' @@ -141,8 +152,10 @@ spec: echo "=== WordPress Initialization Completed ===" volumeMounts: - - name: wordpress-data + - name: wordpress-core mountPath: /var/www/html + - name: wordpress-persistent + mountPath: /var/www/html-persistent env: - name: WORDPRESS_DB_HOST value: {{ .Values.wordpress.dbHost | quote }} @@ -223,7 +236,7 @@ spec: containerPort: 80 protocol: TCP volumeMounts: - - name: wordpress-data + - name: wordpress-core mountPath: /var/www/html - name: nginx-config mountPath: /etc/nginx/conf.d/default.conf @@ -257,12 +270,14 @@ spec: - name: WORDPRESS_TABLE_PREFIX value: {{ .Values.wordpress.tablePrefix | quote }} volumeMounts: - - name: wordpress-data + - name: wordpress-core mountPath: /var/www/html resources: {{- toYaml .Values.resources.wordpress | nindent 12 }} volumes: - - name: wordpress-data + - name: wordpress-core + emptyDir: {} + - name: wordpress-persistent {{- if .Values.persistence.enabled }} persistentVolumeClaim: claimName: {{ include "wordpress-nginx.fullname" . }}-pvc