templates/deployment.yaml を更新
This commit is contained in:
@@ -27,24 +27,21 @@ spec:
|
|||||||
set -e
|
set -e
|
||||||
echo "=== WordPress Initialization Started ==="
|
echo "=== WordPress Initialization Started ==="
|
||||||
|
|
||||||
echo "Copying WordPress files to writable location..."
|
echo "Copying WordPress to emptyDir..."
|
||||||
cp -rp /usr/src/wordpress/* /wordpress/
|
cp -rp /usr/src/wordpress/* /opt/bitnami/wordpress/
|
||||||
|
|
||||||
if [ ! -d /var/www/html/wp-content ]; then
|
if [ ! -d /bitnami/wordpress/wp-content ]; then
|
||||||
echo "Initializing wp-content directory..."
|
echo "Initializing wp-content..."
|
||||||
mkdir -p /var/www/html/wp-content
|
mkdir -p /bitnami/wordpress/wp-content
|
||||||
cp -rp /usr/src/wordpress/wp-content/* /var/www/html/wp-content/
|
cp -rp /usr/src/wordpress/wp-content/* /bitnami/wordpress/wp-content/
|
||||||
echo "wp-content initialized"
|
|
||||||
else
|
|
||||||
echo "wp-content already exists, preserving user data"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Removing default wp-content and creating symlink..."
|
echo "Removing default wp-content and linking to PVC..."
|
||||||
rm -rf /wordpress/wp-content
|
rm -rf /opt/bitnami/wordpress/wp-content
|
||||||
ln -sf /var/www/html/wp-content /wordpress/wp-content
|
ln -sf /bitnami/wordpress/wp-content /opt/bitnami/wordpress/wp-content
|
||||||
|
|
||||||
echo "Generating wp-config.php..."
|
echo "Generating wp-config.php..."
|
||||||
cat > /wordpress/wp-config.php << 'EOF'
|
cat > /opt/bitnami/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'));
|
||||||
@@ -121,14 +118,11 @@ spec:
|
|||||||
|
|
||||||
if [ $attempt -eq $max_attempts ]; then
|
if [ $attempt -eq $max_attempts ]; then
|
||||||
echo "ERROR: Database connection timeout"
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Checking if WordPress is already installed..."
|
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
|
if [ -z "$TABLES" ]; then
|
||||||
echo "=== Starting WordPress Installation ==="
|
echo "=== Starting WordPress Installation ==="
|
||||||
@@ -136,13 +130,13 @@ spec:
|
|||||||
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/.initial-admin-password
|
echo "$WP_ADMIN_PASSWORD" > /bitnami/wordpress/.initial-admin-password
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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=/wordpress core install \
|
/tmp/wp-cli.phar --path=/opt/bitnami/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" \
|
||||||
@@ -152,24 +146,16 @@ spec:
|
|||||||
|
|
||||||
echo "=== WordPress Installation Completed ==="
|
echo "=== WordPress Installation Completed ==="
|
||||||
echo "Admin User: $WP_ADMIN_USER"
|
echo "Admin User: $WP_ADMIN_USER"
|
||||||
if [ -f /var/www/html/.initial-admin-password ]; then
|
if [ -f /bitnami/wordpress/.initial-admin-password ]; then
|
||||||
echo "Admin Password: $(cat /var/www/html/.initial-admin-password)"
|
echo "Admin Password: $(cat /bitnami/wordpress/.initial-admin-password)"
|
||||||
fi
|
fi
|
||||||
echo "Note: Site URL is dynamic and will be set based on HTTP_HOST"
|
|
||||||
else
|
else
|
||||||
echo "WordPress is already installed, skipping installation"
|
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
|
fi
|
||||||
|
|
||||||
{{- if .Values.wordpress.adsTxt.enabled }}
|
{{- if .Values.wordpress.adsTxt.enabled }}
|
||||||
echo "Deploying ads.txt..."
|
echo "Deploying ads.txt..."
|
||||||
cat > /wordpress/ads.txt << 'ADSTXT'
|
cat > /opt/bitnami/wordpress/ads.txt << 'ADSTXT'
|
||||||
{{ .Values.wordpress.adsTxt.content }}
|
{{ .Values.wordpress.adsTxt.content }}
|
||||||
ADSTXT
|
ADSTXT
|
||||||
echo "ads.txt deployed"
|
echo "ads.txt deployed"
|
||||||
@@ -177,10 +163,12 @@ spec:
|
|||||||
|
|
||||||
echo "=== WordPress Initialization Completed ==="
|
echo "=== WordPress Initialization Completed ==="
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: wordpress-core
|
- name: empty-dir
|
||||||
mountPath: /wordpress
|
mountPath: /opt/bitnami/wordpress
|
||||||
- name: wordpress-persistent
|
subPath: app-base-dir
|
||||||
mountPath: /var/www/html
|
- name: wordpress-data
|
||||||
|
mountPath: /bitnami/wordpress
|
||||||
|
subPath: wordpress
|
||||||
env:
|
env:
|
||||||
- name: WORDPRESS_DB_HOST
|
- name: WORDPRESS_DB_HOST
|
||||||
value: {{ .Values.wordpress.dbHost | quote }}
|
value: {{ .Values.wordpress.dbHost | quote }}
|
||||||
@@ -258,8 +246,12 @@ spec:
|
|||||||
containerPort: 80
|
containerPort: 80
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: wordpress-core
|
- name: empty-dir
|
||||||
mountPath: /wordpress
|
mountPath: /opt/bitnami/wordpress
|
||||||
|
subPath: app-base-dir
|
||||||
|
- name: wordpress-data
|
||||||
|
mountPath: /bitnami/wordpress
|
||||||
|
subPath: wordpress
|
||||||
- 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
|
||||||
@@ -274,13 +266,7 @@ spec:
|
|||||||
- name: wordpress
|
- name: wordpress
|
||||||
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:
|
command: ["php-fpm"]
|
||||||
- /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
|
|
||||||
securityContext:
|
securityContext:
|
||||||
runAsUser: 82
|
runAsUser: 82
|
||||||
runAsGroup: 82
|
runAsGroup: 82
|
||||||
@@ -299,14 +285,18 @@ spec:
|
|||||||
- name: WORDPRESS_TABLE_PREFIX
|
- name: WORDPRESS_TABLE_PREFIX
|
||||||
value: {{ .Values.wordpress.tablePrefix | quote }}
|
value: {{ .Values.wordpress.tablePrefix | quote }}
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: wordpress-core
|
- name: empty-dir
|
||||||
mountPath: /wordpress
|
mountPath: /opt/bitnami/wordpress
|
||||||
|
subPath: app-base-dir
|
||||||
|
- name: wordpress-data
|
||||||
|
mountPath: /bitnami/wordpress
|
||||||
|
subPath: wordpress
|
||||||
resources:
|
resources:
|
||||||
{{- toYaml .Values.resources.wordpress | nindent 12 }}
|
{{- toYaml .Values.resources.wordpress | nindent 12 }}
|
||||||
volumes:
|
volumes:
|
||||||
- name: wordpress-core
|
- name: empty-dir
|
||||||
emptyDir: {}
|
emptyDir: {}
|
||||||
- name: wordpress-persistent
|
- name: wordpress-data
|
||||||
{{- if .Values.persistence.enabled }}
|
{{- if .Values.persistence.enabled }}
|
||||||
persistentVolumeClaim:
|
persistentVolumeClaim:
|
||||||
claimName: {{ include "wordpress-nginx.fullname" . }}-pvc
|
claimName: {{ include "wordpress-nginx.fullname" . }}-pvc
|
||||||
|
|||||||
Reference in New Issue
Block a user