templates/deployment.yaml を更新
This commit is contained in:
@@ -21,20 +21,15 @@ spec:
|
|||||||
- name: wordpress-init
|
- name: wordpress-init
|
||||||
image: "{{ .Values.image.wordpress.registry }}/{{ .Values.image.wordpress.repository }}:{{ .Values.image.wordpress.tag }}"
|
image: "{{ .Values.image.wordpress.registry }}/{{ .Values.image.wordpress.repository }}:{{ .Values.image.wordpress.tag }}"
|
||||||
imagePullPolicy: {{ .Values.image.wordpress.pullPolicy }}
|
imagePullPolicy: {{ .Values.image.wordpress.pullPolicy }}
|
||||||
command: ["/bin/sh"]
|
command: ["/bin/sh", "-c"]
|
||||||
args:
|
args:
|
||||||
- -c
|
|
||||||
- |
|
- |
|
||||||
#!/bin/sh
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "=== WordPress Initialization Started ==="
|
echo "=== WordPress Initialization Started ==="
|
||||||
|
|
||||||
# WordPress本体ファイルをemptyDirにコピー(使い捨て)
|
|
||||||
echo "Copying WordPress core files to ephemeral storage..."
|
echo "Copying WordPress core files to ephemeral storage..."
|
||||||
cp -rp /usr/src/wordpress/* /var/www/html/
|
cp -rp /usr/src/wordpress/* /var/www/html/
|
||||||
|
|
||||||
# wp-content ディレクトリをPVCに配置(永続化)
|
|
||||||
if [ ! -d /var/www/html-persistent/wp-content ]; then
|
if [ ! -d /var/www/html-persistent/wp-content ]; then
|
||||||
echo "Initializing wp-content directory..."
|
echo "Initializing wp-content directory..."
|
||||||
mkdir -p /var/www/html-persistent/wp-content
|
mkdir -p /var/www/html-persistent/wp-content
|
||||||
@@ -43,90 +38,64 @@ spec:
|
|||||||
echo "wp-content already exists, preserving user data"
|
echo "wp-content already exists, preserving user data"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# wp-content をシンボリックリンクで接続
|
|
||||||
rm -rf /var/www/html/wp-content
|
rm -rf /var/www/html/wp-content
|
||||||
ln -sf /var/www/html-persistent/wp-content /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..."
|
echo "Generating wp-config.php from Secret..."
|
||||||
cat > /var/www/html/wp-config.php <<'WPCONFIG'
|
cat > /var/www/html/wp-config.php << 'EOF'
|
||||||
<?php
|
<?php
|
||||||
/**
|
define('DB_NAME', getenv('WORDPRESS_DB_NAME'));
|
||||||
* WordPress Configuration File
|
define('DB_USER', getenv('WORDPRESS_DB_USER'));
|
||||||
* Generated by Helm Chart
|
define('DB_PASSWORD', getenv('WORDPRESS_DB_PASSWORD'));
|
||||||
*/
|
define('DB_HOST', getenv('WORDPRESS_DB_HOST'));
|
||||||
|
define('DB_CHARSET', 'utf8');
|
||||||
// ** Database settings ** //
|
define('DB_COLLATE', '');
|
||||||
define('DB_NAME', getenv('WORDPRESS_DB_NAME'));
|
|
||||||
define('DB_USER', getenv('WORDPRESS_DB_USER'));
|
$table_prefix = getenv('WORDPRESS_TABLE_PREFIX') ?: 'wp_';
|
||||||
define('DB_PASSWORD', getenv('WORDPRESS_DB_PASSWORD'));
|
|
||||||
define('DB_HOST', getenv('WORDPRESS_DB_HOST'));
|
define('AUTH_KEY', getenv('WP_AUTH_KEY'));
|
||||||
define('DB_CHARSET', 'utf8');
|
define('SECURE_AUTH_KEY', getenv('WP_SECURE_AUTH_KEY'));
|
||||||
define('DB_COLLATE', '');
|
define('LOGGED_IN_KEY', getenv('WP_LOGGED_IN_KEY'));
|
||||||
|
define('NONCE_KEY', getenv('WP_NONCE_KEY'));
|
||||||
// ** Table prefix ** //
|
define('AUTH_SALT', getenv('WP_AUTH_SALT'));
|
||||||
$table_prefix = getenv('WORDPRESS_TABLE_PREFIX') ?: 'wp_';
|
define('SECURE_AUTH_SALT', getenv('WP_SECURE_AUTH_SALT'));
|
||||||
|
define('LOGGED_IN_SALT', getenv('WP_LOGGED_IN_SALT'));
|
||||||
// ** Authentication Unique Keys and Salts ** //
|
define('NONCE_SALT', getenv('WP_NONCE_SALT'));
|
||||||
define('AUTH_KEY', getenv('WP_AUTH_KEY'));
|
|
||||||
define('SECURE_AUTH_KEY', getenv('WP_SECURE_AUTH_KEY'));
|
if ( defined( 'WP_CLI' ) ) {
|
||||||
define('LOGGED_IN_KEY', getenv('WP_LOGGED_IN_KEY'));
|
$_SERVER['HTTP_HOST'] = '127.0.0.1';
|
||||||
define('NONCE_KEY', getenv('WP_NONCE_KEY'));
|
}
|
||||||
define('AUTH_SALT', getenv('WP_AUTH_SALT'));
|
|
||||||
define('SECURE_AUTH_SALT', getenv('WP_SECURE_AUTH_SALT'));
|
$protocol = 'http';
|
||||||
define('LOGGED_IN_SALT', getenv('WP_LOGGED_IN_SALT'));
|
if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
|
||||||
define('NONCE_SALT', getenv('WP_NONCE_SALT'));
|
$protocol = 'https';
|
||||||
|
} elseif ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ) {
|
||||||
// ** WordPress Site URLs - Dynamic based on HTTP_HOST ** //
|
$protocol = 'https';
|
||||||
if ( defined( 'WP_CLI' ) ) {
|
}
|
||||||
$_SERVER['HTTP_HOST'] = '127.0.0.1';
|
|
||||||
}
|
define( 'WP_HOME', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' );
|
||||||
|
define( 'WP_SITEURL', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' );
|
||||||
// Determine protocol (HTTP or HTTPS)
|
define( 'WP_AUTO_UPDATE_CORE', false );
|
||||||
$protocol = 'http';
|
define('WP_DEBUG', false);
|
||||||
if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
|
define('WP_DEBUG_LOG', false);
|
||||||
$protocol = 'https';
|
define('WP_DEBUG_DISPLAY', false);
|
||||||
} elseif ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ) {
|
define('FS_METHOD', 'direct');
|
||||||
$protocol = 'https';
|
define('WP_MEMORY_LIMIT', '256M');
|
||||||
}
|
define('WP_MAX_MEMORY_LIMIT', '512M');
|
||||||
|
|
||||||
define( 'WP_HOME', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' );
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
define( 'WP_SITEURL', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' );
|
define( 'ABSPATH', __DIR__ . '/' );
|
||||||
|
}
|
||||||
// ** WordPress Core Updates ** //
|
|
||||||
define( 'WP_AUTO_UPDATE_CORE', false );
|
require_once ABSPATH . 'wp-settings.php';
|
||||||
|
EOF
|
||||||
// ** WordPress Debug Mode ** //
|
|
||||||
define('WP_DEBUG', false);
|
|
||||||
define('WP_DEBUG_LOG', false);
|
|
||||||
define('WP_DEBUG_DISPLAY', false);
|
|
||||||
|
|
||||||
// ** File System Method ** //
|
|
||||||
define('FS_METHOD', 'direct');
|
|
||||||
|
|
||||||
// ** Memory Limits ** //
|
|
||||||
define('WP_MEMORY_LIMIT', '256M');
|
|
||||||
define('WP_MAX_MEMORY_LIMIT', '512M');
|
|
||||||
|
|
||||||
/* That's all, stop editing! Happy publishing. */
|
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
define( 'ABSPATH', __DIR__ . '/' );
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once ABSPATH . 'wp-settings.php';
|
|
||||||
WPCONFIG
|
|
||||||
|
|
||||||
echo "wp-config.php generated"
|
echo "wp-config.php generated"
|
||||||
|
|
||||||
echo "wp-config.php generated"
|
|
||||||
|
|
||||||
# WordPress CLI のセットアップ
|
|
||||||
echo "Setting up WP-CLI..."
|
echo "Setting up WP-CLI..."
|
||||||
curl -o /tmp/wp-cli.phar https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar 2>/dev/null || true
|
curl -o /tmp/wp-cli.phar https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar 2>/dev/null || true
|
||||||
chmod +x /tmp/wp-cli.phar
|
chmod +x /tmp/wp-cli.phar
|
||||||
|
|
||||||
# データベース接続待機
|
|
||||||
echo "Waiting for database connection..."
|
echo "Waiting for database connection..."
|
||||||
max_attempts=30
|
max_attempts=30
|
||||||
attempt=0
|
attempt=0
|
||||||
@@ -140,24 +109,20 @@ WPCONFIG
|
|||||||
sleep 2
|
sleep 2
|
||||||
done
|
done
|
||||||
|
|
||||||
# データベーステーブルの確認
|
|
||||||
echo "Checking if WordPress is already installed..."
|
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 "")
|
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
|
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-persistent/.initial-admin-password
|
echo "$WP_ADMIN_PASSWORD" > /var/www/html-persistent/.initial-admin-password
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 初回インストール用の一時的なURL(後で動的に変更される)
|
|
||||||
INSTALL_URL="http://127.0.0.1"
|
INSTALL_URL="http://127.0.0.1"
|
||||||
|
|
||||||
# WordPressのインストール
|
|
||||||
echo "Installing WordPress..."
|
echo "Installing WordPress..."
|
||||||
/tmp/wp-cli.phar --path=/var/www/html core install \
|
/tmp/wp-cli.phar --path=/var/www/html core install \
|
||||||
--url="$INSTALL_URL" \
|
--url="$INSTALL_URL" \
|
||||||
@@ -176,7 +141,6 @@ WPCONFIG
|
|||||||
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
|
||||||
CURRENT_VERSION=$(cat /usr/src/wordpress/wp-includes/version.php | grep "wp_version = " | cut -d "'" -f 2)
|
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"
|
echo "Checking for WordPress updates... Target version: $CURRENT_VERSION"
|
||||||
@@ -187,7 +151,7 @@ WPCONFIG
|
|||||||
|
|
||||||
{{- 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'
|
||||||
{{ .Values.wordpress.adsTxt.content }}
|
{{ .Values.wordpress.adsTxt.content }}
|
||||||
ADSTXT
|
ADSTXT
|
||||||
echo "ads.txt deployed"
|
echo "ads.txt deployed"
|
||||||
|
|||||||
Reference in New Issue
Block a user