templates/deployment.yaml を更新
This commit is contained in:
@@ -27,6 +27,9 @@ spec:
|
||||
set -e
|
||||
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
|
||||
echo "Initializing wp-content directory..."
|
||||
mkdir -p /var/www/html/wp-content
|
||||
@@ -36,8 +39,12 @@ spec:
|
||||
echo "wp-content already exists, preserving user data"
|
||||
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..."
|
||||
cat > /usr/src/wordpress/wp-config.php << 'EOF'
|
||||
cat > /wordpress/wp-config.php << 'EOF'
|
||||
<?php
|
||||
define('DB_NAME', getenv('WORDPRESS_DB_NAME'));
|
||||
define('DB_USER', getenv('WORDPRESS_DB_USER'));
|
||||
@@ -71,8 +78,6 @@ spec:
|
||||
define( 'WP_HOME', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' );
|
||||
define( 'WP_SITEURL', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' );
|
||||
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_LOG', false);
|
||||
define('WP_DEBUG_DISPLAY', false);
|
||||
@@ -81,7 +86,7 @@ spec:
|
||||
define('WP_MAX_MEMORY_LIMIT', '512M');
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
define( 'ABSPATH', '/usr/src/wordpress/' );
|
||||
define( 'ABSPATH', __DIR__ . '/' );
|
||||
}
|
||||
|
||||
require_once ABSPATH . 'wp-settings.php';
|
||||
@@ -89,9 +94,6 @@ spec:
|
||||
|
||||
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..."
|
||||
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
|
||||
@@ -140,7 +142,7 @@ spec:
|
||||
INSTALL_URL="http://127.0.0.1"
|
||||
|
||||
echo "Installing WordPress..."
|
||||
/tmp/wp-cli.phar --path=/usr/src/wordpress core install \
|
||||
/tmp/wp-cli.phar --path=/wordpress core install \
|
||||
--url="$INSTALL_URL" \
|
||||
--title="$WP_SITE_TITLE" \
|
||||
--admin_user="$WP_ADMIN_USER" \
|
||||
@@ -157,17 +159,17 @@ spec:
|
||||
else
|
||||
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)
|
||||
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=/usr/src/wordpress core update-db 2>/dev/null || true
|
||||
/tmp/wp-cli.phar --path=/wordpress core update --version=$CURRENT_VERSION 2>/dev/null || true
|
||||
/tmp/wp-cli.phar --path=/wordpress core update-db 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
|
||||
{{- if .Values.wordpress.adsTxt.enabled }}
|
||||
echo "Deploying ads.txt..."
|
||||
cat > /var/www/html/ads.txt << 'ADSTXT'
|
||||
cat > /wordpress/ads.txt << 'ADSTXT'
|
||||
{{ .Values.wordpress.adsTxt.content }}
|
||||
ADSTXT
|
||||
echo "ads.txt deployed"
|
||||
@@ -175,6 +177,8 @@ spec:
|
||||
|
||||
echo "=== WordPress Initialization Completed ==="
|
||||
volumeMounts:
|
||||
- name: wordpress-core
|
||||
mountPath: /wordpress
|
||||
- name: wordpress-persistent
|
||||
mountPath: /var/www/html
|
||||
env:
|
||||
@@ -254,12 +258,8 @@ spec:
|
||||
containerPort: 80
|
||||
protocol: TCP
|
||||
volumeMounts:
|
||||
- name: wordpress-persistent
|
||||
mountPath: /usr/src/wordpress/wp-content
|
||||
subPath: wp-content
|
||||
- name: wordpress-persistent
|
||||
mountPath: /usr/src/wordpress/wp-config.php
|
||||
subPath: wp-config.php
|
||||
- name: wordpress-core
|
||||
mountPath: /wordpress
|
||||
- name: nginx-config
|
||||
mountPath: /etc/nginx/conf.d/default.conf
|
||||
subPath: default.conf
|
||||
@@ -293,15 +293,13 @@ spec:
|
||||
- name: WORDPRESS_TABLE_PREFIX
|
||||
value: {{ .Values.wordpress.tablePrefix | quote }}
|
||||
volumeMounts:
|
||||
- name: wordpress-persistent
|
||||
mountPath: /usr/src/wordpress/wp-content
|
||||
subPath: wp-content
|
||||
- name: wordpress-persistent
|
||||
mountPath: /usr/src/wordpress/wp-config.php
|
||||
subPath: wp-config.php
|
||||
- name: wordpress-core
|
||||
mountPath: /wordpress
|
||||
resources:
|
||||
{{- toYaml .Values.resources.wordpress | nindent 12 }}
|
||||
volumes:
|
||||
- name: wordpress-core
|
||||
emptyDir: {}
|
||||
- name: wordpress-persistent
|
||||
{{- if .Values.persistence.enabled }}
|
||||
persistentVolumeClaim:
|
||||
|
||||
Reference in New Issue
Block a user