templates/deployment.yaml を更新
This commit is contained in:
@@ -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'
|
||||
<?php
|
||||
/**
|
||||
* WordPress Configuration File
|
||||
* Generated by Helm Chart
|
||||
*/
|
||||
cat > /var/www/html/wp-config.php << 'EOF'
|
||||
<?php
|
||||
define('DB_NAME', getenv('WORDPRESS_DB_NAME'));
|
||||
define('DB_USER', getenv('WORDPRESS_DB_USER'));
|
||||
define('DB_PASSWORD', getenv('WORDPRESS_DB_PASSWORD'));
|
||||
define('DB_HOST', getenv('WORDPRESS_DB_HOST'));
|
||||
define('DB_CHARSET', 'utf8');
|
||||
define('DB_COLLATE', '');
|
||||
|
||||
// ** Database settings ** //
|
||||
define('DB_NAME', getenv('WORDPRESS_DB_NAME'));
|
||||
define('DB_USER', getenv('WORDPRESS_DB_USER'));
|
||||
define('DB_PASSWORD', getenv('WORDPRESS_DB_PASSWORD'));
|
||||
define('DB_HOST', getenv('WORDPRESS_DB_HOST'));
|
||||
define('DB_CHARSET', 'utf8');
|
||||
define('DB_COLLATE', '');
|
||||
$table_prefix = getenv('WORDPRESS_TABLE_PREFIX') ?: 'wp_';
|
||||
|
||||
// ** Table prefix ** //
|
||||
$table_prefix = getenv('WORDPRESS_TABLE_PREFIX') ?: 'wp_';
|
||||
define('AUTH_KEY', getenv('WP_AUTH_KEY'));
|
||||
define('SECURE_AUTH_KEY', getenv('WP_SECURE_AUTH_KEY'));
|
||||
define('LOGGED_IN_KEY', getenv('WP_LOGGED_IN_KEY'));
|
||||
define('NONCE_KEY', getenv('WP_NONCE_KEY'));
|
||||
define('AUTH_SALT', getenv('WP_AUTH_SALT'));
|
||||
define('SECURE_AUTH_SALT', getenv('WP_SECURE_AUTH_SALT'));
|
||||
define('LOGGED_IN_SALT', getenv('WP_LOGGED_IN_SALT'));
|
||||
define('NONCE_SALT', getenv('WP_NONCE_SALT'));
|
||||
|
||||
// ** Authentication Unique Keys and Salts ** //
|
||||
define('AUTH_KEY', getenv('WP_AUTH_KEY'));
|
||||
define('SECURE_AUTH_KEY', getenv('WP_SECURE_AUTH_KEY'));
|
||||
define('LOGGED_IN_KEY', getenv('WP_LOGGED_IN_KEY'));
|
||||
define('NONCE_KEY', getenv('WP_NONCE_KEY'));
|
||||
define('AUTH_SALT', getenv('WP_AUTH_SALT'));
|
||||
define('SECURE_AUTH_SALT', getenv('WP_SECURE_AUTH_SALT'));
|
||||
define('LOGGED_IN_SALT', getenv('WP_LOGGED_IN_SALT'));
|
||||
define('NONCE_SALT', getenv('WP_NONCE_SALT'));
|
||||
|
||||
// ** WordPress Site URLs - Dynamic based on HTTP_HOST ** //
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
$_SERVER['HTTP_HOST'] = '127.0.0.1';
|
||||
}
|
||||
}
|
||||
|
||||
// Determine protocol (HTTP or HTTPS)
|
||||
$protocol = 'http';
|
||||
if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
|
||||
$protocol = 'http';
|
||||
if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
|
||||
$protocol = 'https';
|
||||
} elseif ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ) {
|
||||
} elseif ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ) {
|
||||
$protocol = 'https';
|
||||
}
|
||||
}
|
||||
|
||||
define( 'WP_HOME', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' );
|
||||
define( 'WP_SITEURL', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' );
|
||||
define( 'WP_HOME', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' );
|
||||
define( 'WP_SITEURL', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' );
|
||||
define( 'WP_AUTO_UPDATE_CORE', false );
|
||||
define('WP_DEBUG', false);
|
||||
define('WP_DEBUG_LOG', false);
|
||||
define('WP_DEBUG_DISPLAY', false);
|
||||
define('FS_METHOD', 'direct');
|
||||
define('WP_MEMORY_LIMIT', '256M');
|
||||
define('WP_MAX_MEMORY_LIMIT', '512M');
|
||||
|
||||
// ** WordPress Core Updates ** //
|
||||
define( 'WP_AUTO_UPDATE_CORE', false );
|
||||
|
||||
// ** 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' ) ) {
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
define( 'ABSPATH', __DIR__ . '/' );
|
||||
}
|
||||
}
|
||||
|
||||
require_once ABSPATH . 'wp-settings.php';
|
||||
WPCONFIG
|
||||
require_once ABSPATH . 'wp-settings.php';
|
||||
EOF
|
||||
|
||||
echo "wp-config.php generated"
|
||||
|
||||
echo "wp-config.php generated"
|
||||
|
||||
# WordPress 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
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user