templates/deployment.yaml を更新
This commit is contained in:
@@ -30,17 +30,26 @@ spec:
|
|||||||
|
|
||||||
echo "=== WordPress Initialization Started ==="
|
echo "=== WordPress Initialization Started ==="
|
||||||
|
|
||||||
# WordPress ファイルのコピー
|
# WordPress本体ファイルをemptyDirにコピー(使い捨て)
|
||||||
if [ ! -f /var/www/html/index.php ]; then
|
echo "Copying WordPress core files to ephemeral storage..."
|
||||||
echo "Copying WordPress files..."
|
cp -rp /usr/src/wordpress/* /var/www/html/
|
||||||
cp -rp /usr/src/wordpress/* /var/www/html/ 2>/dev/null || true
|
|
||||||
echo "WordPress files copied"
|
# 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
|
fi
|
||||||
|
|
||||||
# wp-config.php の生成
|
# wp-content をシンボリックリンクで接続
|
||||||
if [ ! -f /var/www/html/wp-config.php ]; then
|
rm -rf /var/www/html/wp-content
|
||||||
echo "Generating wp-config.php..."
|
ln -sf /var/www/html-persistent/wp-content /var/www/html/wp-content
|
||||||
cat > /var/www/html/wp-config.php <<'WPCONFIG'
|
|
||||||
|
# wp-config.php を Secretから生成(毎回再作成)
|
||||||
|
echo "Generating wp-config.php from Secret..."
|
||||||
|
cat > /var/www/html/wp-config.php <<'WPCONFIG'
|
||||||
<?php
|
<?php
|
||||||
define('DB_NAME', getenv('WORDPRESS_DB_NAME'));
|
define('DB_NAME', getenv('WORDPRESS_DB_NAME'));
|
||||||
define('DB_USER', getenv('WORDPRESS_DB_USER'));
|
define('DB_USER', getenv('WORDPRESS_DB_USER'));
|
||||||
@@ -68,8 +77,8 @@ spec:
|
|||||||
|
|
||||||
require_once ABSPATH . 'wp-settings.php';
|
require_once ABSPATH . 'wp-settings.php';
|
||||||
WPCONFIG
|
WPCONFIG
|
||||||
echo "wp-config.php generated"
|
|
||||||
fi
|
echo "wp-config.php generated"
|
||||||
|
|
||||||
# WordPress CLI のセットアップ
|
# WordPress CLI のセットアップ
|
||||||
echo "Setting up WP-CLI..."
|
echo "Setting up WP-CLI..."
|
||||||
@@ -97,11 +106,12 @@ spec:
|
|||||||
if [ -z "$TABLES" ]; then
|
if [ -z "$TABLES" ]; then
|
||||||
echo "=== Starting WordPress Installation ==="
|
echo "=== Starting WordPress Installation ==="
|
||||||
|
|
||||||
# 管理者パスワードの生成または使用
|
# 管理者パスワードの処理
|
||||||
if [ -z "$WP_ADMIN_PASSWORD" ]; then
|
if [ -z "$WP_ADMIN_PASSWORD" ]; then
|
||||||
WP_ADMIN_PASSWORD=$(tr -dc 'A-Za-z0-9!@#$%^&*' < /dev/urandom | head -c 16)
|
WP_ADMIN_PASSWORD=$(tr -dc 'A-Za-z0-9!@#$%^&*' < /dev/urandom | head -c 16)
|
||||||
echo "Generated admin password: $WP_ADMIN_PASSWORD"
|
echo "Generated admin password: $WP_ADMIN_PASSWORD"
|
||||||
echo "$WP_ADMIN_PASSWORD" > /var/www/html/.admin-password
|
# パスワードを永続化領域に保存(初回のみ)
|
||||||
|
echo "$WP_ADMIN_PASSWORD" > /var/www/html-persistent/.initial-admin-password
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# WordPressのインストール
|
# WordPressのインストール
|
||||||
@@ -116,21 +126,22 @@ spec:
|
|||||||
|
|
||||||
echo "=== WordPress Installation Completed ==="
|
echo "=== WordPress Installation Completed ==="
|
||||||
echo "Admin User: $WP_ADMIN_USER"
|
echo "Admin User: $WP_ADMIN_USER"
|
||||||
if [ -f /var/www/html/.admin-password ]; then
|
if [ -f /var/www/html-persistent/.initial-admin-password ]; then
|
||||||
echo "Admin Password: $(cat /var/www/html/.admin-password)"
|
echo "Admin Password: $(cat /var/www/html-persistent/.initial-admin-password)"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "WordPress is already installed, skipping installation"
|
echo "WordPress is already installed, skipping installation"
|
||||||
|
|
||||||
# コアアップデートの確認
|
# コアアップデートの確認
|
||||||
if /tmp/wp-cli.phar --path=/var/www/html core version 2>/dev/null; then
|
if /tmp/wp-cli.phar --path=/var/www/html core version 2>/dev/null; then
|
||||||
echo "Checking for WordPress updates..."
|
CURRENT_VERSION=$(cat /usr/src/wordpress/wp-includes/version.php | grep "wp_version = " | cut -d "'" -f 2)
|
||||||
/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
|
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
|
/tmp/wp-cli.phar --path=/var/www/html core update-db 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ads.txt の配置
|
# ads.txt の配置(使い捨てファイル領域に)
|
||||||
{{- if .Values.wordpress.adsTxt.enabled }}
|
{{- if .Values.wordpress.adsTxt.enabled }}
|
||||||
echo "Deploying ads.txt..."
|
echo "Deploying ads.txt..."
|
||||||
cat > /var/www/html/ads.txt <<'ADSTXT'
|
cat > /var/www/html/ads.txt <<'ADSTXT'
|
||||||
@@ -141,8 +152,10 @@ spec:
|
|||||||
|
|
||||||
echo "=== WordPress Initialization Completed ==="
|
echo "=== WordPress Initialization Completed ==="
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: wordpress-data
|
- name: wordpress-core
|
||||||
mountPath: /var/www/html
|
mountPath: /var/www/html
|
||||||
|
- name: wordpress-persistent
|
||||||
|
mountPath: /var/www/html-persistent
|
||||||
env:
|
env:
|
||||||
- name: WORDPRESS_DB_HOST
|
- name: WORDPRESS_DB_HOST
|
||||||
value: {{ .Values.wordpress.dbHost | quote }}
|
value: {{ .Values.wordpress.dbHost | quote }}
|
||||||
@@ -223,7 +236,7 @@ spec:
|
|||||||
containerPort: 80
|
containerPort: 80
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: wordpress-data
|
- name: wordpress-core
|
||||||
mountPath: /var/www/html
|
mountPath: /var/www/html
|
||||||
- name: nginx-config
|
- name: nginx-config
|
||||||
mountPath: /etc/nginx/conf.d/default.conf
|
mountPath: /etc/nginx/conf.d/default.conf
|
||||||
@@ -257,12 +270,14 @@ spec:
|
|||||||
- name: WORDPRESS_TABLE_PREFIX
|
- name: WORDPRESS_TABLE_PREFIX
|
||||||
value: {{ .Values.wordpress.tablePrefix | quote }}
|
value: {{ .Values.wordpress.tablePrefix | quote }}
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: wordpress-data
|
- name: wordpress-core
|
||||||
mountPath: /var/www/html
|
mountPath: /var/www/html
|
||||||
resources:
|
resources:
|
||||||
{{- toYaml .Values.resources.wordpress | nindent 12 }}
|
{{- toYaml .Values.resources.wordpress | nindent 12 }}
|
||||||
volumes:
|
volumes:
|
||||||
- name: wordpress-data
|
- name: wordpress-core
|
||||||
|
emptyDir: {}
|
||||||
|
- name: wordpress-persistent
|
||||||
{{- if .Values.persistence.enabled }}
|
{{- if .Values.persistence.enabled }}
|
||||||
persistentVolumeClaim:
|
persistentVolumeClaim:
|
||||||
claimName: {{ include "wordpress-nginx.fullname" . }}-pvc
|
claimName: {{ include "wordpress-nginx.fullname" . }}-pvc
|
||||||
|
|||||||
Reference in New Issue
Block a user