templates/deployment.yaml を更新
This commit is contained in:
@@ -27,24 +27,21 @@ spec:
|
||||
set -e
|
||||
echo "=== WordPress Initialization Started ==="
|
||||
|
||||
echo "Copying WordPress files to writable location..."
|
||||
cp -rp /usr/src/wordpress/* /wordpress/
|
||||
echo "Copying WordPress to emptyDir..."
|
||||
cp -rp /usr/src/wordpress/* /opt/bitnami/wordpress/
|
||||
|
||||
if [ ! -d /var/www/html/wp-content ]; then
|
||||
echo "Initializing wp-content directory..."
|
||||
mkdir -p /var/www/html/wp-content
|
||||
cp -rp /usr/src/wordpress/wp-content/* /var/www/html/wp-content/
|
||||
echo "wp-content initialized"
|
||||
else
|
||||
echo "wp-content already exists, preserving user data"
|
||||
if [ ! -d /bitnami/wordpress/wp-content ]; then
|
||||
echo "Initializing wp-content..."
|
||||
mkdir -p /bitnami/wordpress/wp-content
|
||||
cp -rp /usr/src/wordpress/wp-content/* /bitnami/wordpress/wp-content/
|
||||
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 "Removing default wp-content and linking to PVC..."
|
||||
rm -rf /opt/bitnami/wordpress/wp-content
|
||||
ln -sf /bitnami/wordpress/wp-content /opt/bitnami/wordpress/wp-content
|
||||
|
||||
echo "Generating wp-config.php..."
|
||||
cat > /wordpress/wp-config.php << 'EOF'
|
||||
cat > /opt/bitnami/wordpress/wp-config.php << 'EOF'
|
||||
<?php
|
||||
define('DB_NAME', getenv('WORDPRESS_DB_NAME'));
|
||||
define('DB_USER', getenv('WORDPRESS_DB_USER'));
|
||||
@@ -121,14 +118,11 @@ spec:
|
||||
|
||||
if [ $attempt -eq $max_attempts ]; then
|
||||
echo "ERROR: Database connection timeout"
|
||||
echo "DB_HOST: ${WORDPRESS_DB_HOST}"
|
||||
echo "DB_NAME: ${WORDPRESS_DB_NAME}"
|
||||
echo "DB_USER: ${WORDPRESS_DB_USER}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Checking if WordPress is already installed..."
|
||||
TABLES=$(/tmp/wp-cli.phar --path=/usr/src/wordpress db query "SHOW TABLES LIKE '${WORDPRESS_TABLE_PREFIX}options';" 2>/dev/null || echo "")
|
||||
TABLES=$(/tmp/wp-cli.phar --path=/opt/bitnami/wordpress db query "SHOW TABLES LIKE '${WORDPRESS_TABLE_PREFIX}options';" 2>/dev/null || echo "")
|
||||
|
||||
if [ -z "$TABLES" ]; then
|
||||
echo "=== Starting WordPress Installation ==="
|
||||
@@ -136,13 +130,13 @@ spec:
|
||||
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/.initial-admin-password
|
||||
echo "$WP_ADMIN_PASSWORD" > /bitnami/wordpress/.initial-admin-password
|
||||
fi
|
||||
|
||||
INSTALL_URL="http://127.0.0.1"
|
||||
|
||||
echo "Installing WordPress..."
|
||||
/tmp/wp-cli.phar --path=/wordpress core install \
|
||||
/tmp/wp-cli.phar --path=/opt/bitnami/wordpress core install \
|
||||
--url="$INSTALL_URL" \
|
||||
--title="$WP_SITE_TITLE" \
|
||||
--admin_user="$WP_ADMIN_USER" \
|
||||
@@ -152,24 +146,16 @@ spec:
|
||||
|
||||
echo "=== WordPress Installation Completed ==="
|
||||
echo "Admin User: $WP_ADMIN_USER"
|
||||
if [ -f /var/www/html/.initial-admin-password ]; then
|
||||
echo "Admin Password: $(cat /var/www/html/.initial-admin-password)"
|
||||
if [ -f /bitnami/wordpress/.initial-admin-password ]; then
|
||||
echo "Admin Password: $(cat /bitnami/wordpress/.initial-admin-password)"
|
||||
fi
|
||||
echo "Note: Site URL is dynamic and will be set based on HTTP_HOST"
|
||||
else
|
||||
echo "WordPress is already installed, skipping installation"
|
||||
|
||||
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=/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 > /wordpress/ads.txt << 'ADSTXT'
|
||||
cat > /opt/bitnami/wordpress/ads.txt << 'ADSTXT'
|
||||
{{ .Values.wordpress.adsTxt.content }}
|
||||
ADSTXT
|
||||
echo "ads.txt deployed"
|
||||
@@ -177,10 +163,12 @@ spec:
|
||||
|
||||
echo "=== WordPress Initialization Completed ==="
|
||||
volumeMounts:
|
||||
- name: wordpress-core
|
||||
mountPath: /wordpress
|
||||
- name: wordpress-persistent
|
||||
mountPath: /var/www/html
|
||||
- name: empty-dir
|
||||
mountPath: /opt/bitnami/wordpress
|
||||
subPath: app-base-dir
|
||||
- name: wordpress-data
|
||||
mountPath: /bitnami/wordpress
|
||||
subPath: wordpress
|
||||
env:
|
||||
- name: WORDPRESS_DB_HOST
|
||||
value: {{ .Values.wordpress.dbHost | quote }}
|
||||
@@ -258,8 +246,12 @@ spec:
|
||||
containerPort: 80
|
||||
protocol: TCP
|
||||
volumeMounts:
|
||||
- name: wordpress-core
|
||||
mountPath: /wordpress
|
||||
- name: empty-dir
|
||||
mountPath: /opt/bitnami/wordpress
|
||||
subPath: app-base-dir
|
||||
- name: wordpress-data
|
||||
mountPath: /bitnami/wordpress
|
||||
subPath: wordpress
|
||||
- name: nginx-config
|
||||
mountPath: /etc/nginx/conf.d/default.conf
|
||||
subPath: default.conf
|
||||
@@ -274,13 +266,7 @@ spec:
|
||||
- name: wordpress
|
||||
image: "{{ .Values.image.wordpress.registry }}/{{ .Values.image.wordpress.repository }}:{{ .Values.image.wordpress.tag }}"
|
||||
imagePullPolicy: {{ .Values.image.wordpress.pullPolicy }}
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- |
|
||||
# PHP-FPMの設定を確認・修正
|
||||
sed -i 's|chdir = /var/www/html|chdir = /wordpress|g' /usr/local/etc/php-fpm.d/www.conf || true
|
||||
exec php-fpm
|
||||
command: ["php-fpm"]
|
||||
securityContext:
|
||||
runAsUser: 82
|
||||
runAsGroup: 82
|
||||
@@ -299,14 +285,18 @@ spec:
|
||||
- name: WORDPRESS_TABLE_PREFIX
|
||||
value: {{ .Values.wordpress.tablePrefix | quote }}
|
||||
volumeMounts:
|
||||
- name: wordpress-core
|
||||
mountPath: /wordpress
|
||||
- name: empty-dir
|
||||
mountPath: /opt/bitnami/wordpress
|
||||
subPath: app-base-dir
|
||||
- name: wordpress-data
|
||||
mountPath: /bitnami/wordpress
|
||||
subPath: wordpress
|
||||
resources:
|
||||
{{- toYaml .Values.resources.wordpress | nindent 12 }}
|
||||
volumes:
|
||||
- name: wordpress-core
|
||||
- name: empty-dir
|
||||
emptyDir: {}
|
||||
- name: wordpress-persistent
|
||||
- name: wordpress-data
|
||||
{{- if .Values.persistence.enabled }}
|
||||
persistentVolumeClaim:
|
||||
claimName: {{ include "wordpress-nginx.fullname" . }}-pvc
|
||||
|
||||
Reference in New Issue
Block a user