templates/deployment.yaml を更新

This commit is contained in:
2025-11-26 02:14:37 +00:00
parent 20d309950a
commit 52693e8f6e

View File

@@ -27,6 +27,9 @@ spec:
set -e set -e
echo "=== WordPress Initialization Started ===" echo "=== WordPress Initialization Started ==="
echo "Copying WordPress files to writable location..."
cp -rp /usr/src/wordpress/* /wordpress/
if [ ! -d /var/www/html/wp-content ]; then if [ ! -d /var/www/html/wp-content ]; then
echo "Initializing wp-content directory..." echo "Initializing wp-content directory..."
mkdir -p /var/www/html/wp-content mkdir -p /var/www/html/wp-content
@@ -36,8 +39,12 @@ spec:
echo "wp-content already exists, preserving user data" echo "wp-content already exists, preserving user data"
fi fi
echo "Removing default wp-content and creating symlink..."
rm -rf /wordpress/wp-content
ln -sf /var/www/html/wp-content /wordpress/wp-content
echo "Generating wp-config.php..." echo "Generating wp-config.php..."
cat > /usr/src/wordpress/wp-config.php << 'EOF' cat > /wordpress/wp-config.php << 'EOF'
<?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'));
@@ -71,8 +78,6 @@ spec:
define( 'WP_HOME', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' ); define( 'WP_HOME', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' );
define( 'WP_SITEURL', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' ); define( 'WP_SITEURL', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' );
define( 'WP_AUTO_UPDATE_CORE', false ); define( 'WP_AUTO_UPDATE_CORE', false );
define( 'WP_CONTENT_DIR', '/var/www/html/wp-content' );
define( 'WP_CONTENT_URL', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/wp-content' );
define('WP_DEBUG', false); define('WP_DEBUG', false);
define('WP_DEBUG_LOG', false); define('WP_DEBUG_LOG', false);
define('WP_DEBUG_DISPLAY', false); define('WP_DEBUG_DISPLAY', false);
@@ -81,7 +86,7 @@ spec:
define('WP_MAX_MEMORY_LIMIT', '512M'); define('WP_MAX_MEMORY_LIMIT', '512M');
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', '/usr/src/wordpress/' ); define( 'ABSPATH', __DIR__ . '/' );
} }
require_once ABSPATH . 'wp-settings.php'; require_once ABSPATH . 'wp-settings.php';
@@ -89,9 +94,6 @@ spec:
echo "wp-config.php generated" echo "wp-config.php generated"
echo "Copying wp-config.php to persistent storage..."
cp /usr/src/wordpress/wp-config.php /var/www/html/wp-config.php
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
@@ -140,7 +142,7 @@ spec:
INSTALL_URL="http://127.0.0.1" INSTALL_URL="http://127.0.0.1"
echo "Installing WordPress..." echo "Installing WordPress..."
/tmp/wp-cli.phar --path=/usr/src/wordpress core install \ /tmp/wp-cli.phar --path=/wordpress core install \
--url="$INSTALL_URL" \ --url="$INSTALL_URL" \
--title="$WP_SITE_TITLE" \ --title="$WP_SITE_TITLE" \
--admin_user="$WP_ADMIN_USER" \ --admin_user="$WP_ADMIN_USER" \
@@ -157,17 +159,17 @@ spec:
else else
echo "WordPress is already installed, skipping installation" echo "WordPress is already installed, skipping installation"
if /tmp/wp-cli.phar --path=/usr/src/wordpress core version 2>/dev/null; then if /tmp/wp-cli.phar --path=/wordpress 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"
/tmp/wp-cli.phar --path=/usr/src/wordpress core update --version=$CURRENT_VERSION 2>/dev/null || true /tmp/wp-cli.phar --path=/wordpress core update --version=$CURRENT_VERSION 2>/dev/null || true
/tmp/wp-cli.phar --path=/usr/src/wordpress core update-db 2>/dev/null || true /tmp/wp-cli.phar --path=/wordpress core update-db 2>/dev/null || true
fi fi
fi fi
{{- 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 > /wordpress/ads.txt << 'ADSTXT'
{{ .Values.wordpress.adsTxt.content }} {{ .Values.wordpress.adsTxt.content }}
ADSTXT ADSTXT
echo "ads.txt deployed" echo "ads.txt deployed"
@@ -175,6 +177,8 @@ spec:
echo "=== WordPress Initialization Completed ===" echo "=== WordPress Initialization Completed ==="
volumeMounts: volumeMounts:
- name: wordpress-core
mountPath: /wordpress
- name: wordpress-persistent - name: wordpress-persistent
mountPath: /var/www/html mountPath: /var/www/html
env: env:
@@ -254,12 +258,8 @@ spec:
containerPort: 80 containerPort: 80
protocol: TCP protocol: TCP
volumeMounts: volumeMounts:
- name: wordpress-persistent - name: wordpress-core
mountPath: /usr/src/wordpress/wp-content mountPath: /wordpress
subPath: wp-content
- name: wordpress-persistent
mountPath: /usr/src/wordpress/wp-config.php
subPath: wp-config.php
- name: nginx-config - name: nginx-config
mountPath: /etc/nginx/conf.d/default.conf mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf subPath: default.conf
@@ -293,15 +293,13 @@ spec:
- name: WORDPRESS_TABLE_PREFIX - name: WORDPRESS_TABLE_PREFIX
value: {{ .Values.wordpress.tablePrefix | quote }} value: {{ .Values.wordpress.tablePrefix | quote }}
volumeMounts: volumeMounts:
- name: wordpress-persistent - name: wordpress-core
mountPath: /usr/src/wordpress/wp-content mountPath: /wordpress
subPath: wp-content
- name: wordpress-persistent
mountPath: /usr/src/wordpress/wp-config.php
subPath: wp-config.php
resources: resources:
{{- toYaml .Values.resources.wordpress | nindent 12 }} {{- toYaml .Values.resources.wordpress | nindent 12 }}
volumes: volumes:
- name: wordpress-core
emptyDir: {}
- name: wordpress-persistent - name: wordpress-persistent
{{- if .Values.persistence.enabled }} {{- if .Values.persistence.enabled }}
persistentVolumeClaim: persistentVolumeClaim: