From 58c02e47a9f74bed0bc0289cfb3af972462d486c Mon Sep 17 00:00:00 2001 From: pieter Date: Fri, 6 Feb 2026 02:03:52 +0000 Subject: [PATCH] =?UTF-8?q?Composer=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/deployment.yaml | 134 +++++++++++++++++++++++++++++++++----- 1 file changed, 118 insertions(+), 16 deletions(-) diff --git a/templates/deployment.yaml b/templates/deployment.yaml index ea0735e..11db36d 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml @@ -34,23 +34,116 @@ spec: - sh - -c - | - echo "Starting PHP-FPM with conditional logic..." - {{- if or .Values.selenium.enabled .Values.externalDatabase.enabled }} - ( - {{- if .Values.selenium.enabled }} - echo "Installing selenium dependencies..." - apk add --no-cache curl zip libzip-dev && \ - docker-php-ext-install zip && \ - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \ - composer require php-webdriver/webdriver - {{- end }} - {{- if .Values.externalDatabase.enabled }} - echo "Installing pdo_mysql for PHP 8.4 Alpine..." - apk add --no-cache mysql-client mysql-dev - docker-php-ext-install pdo_mysql - {{- end }} - ) + echo "Starting PHP-FPM setup process..." + + {{- if or .Values.composer.enabled .Values.selenium.enabled .Values.externalDatabase.enabled }} + # ======================================== + # APKパッケージのインストール + # ======================================== + APK_PACKAGES="" + + {{- if or .Values.composer.enabled .Values.selenium.enabled }} + # Composer本体に必要なパッケージ + APK_PACKAGES="$APK_PACKAGES curl zip libzip-dev" {{- end }} + + {{- if .Values.externalDatabase.enabled }} + # MySQL/MariaDB接続に必要なパッケージ + APK_PACKAGES="$APK_PACKAGES mysql-client mysql-dev" + {{- end }} + + {{- if .Values.composer.additionalApkPackages }} + # ユーザー指定の追加APKパッケージ + {{- range .Values.composer.additionalApkPackages }} + APK_PACKAGES="$APK_PACKAGES {{ . }}" + {{- end }} + {{- end }} + + if [ -n "$APK_PACKAGES" ]; then + echo "Installing APK packages: $APK_PACKAGES" + apk add --no-cache $APK_PACKAGES + fi + + # ======================================== + # PHP拡張のインストール + # ======================================== + {{- if or .Values.composer.enabled .Values.selenium.enabled }} + echo "Installing PHP zip extension..." + docker-php-ext-install zip + {{- end }} + + {{- if .Values.externalDatabase.enabled }} + echo "Installing pdo_mysql extension..." + docker-php-ext-install pdo_mysql + {{- end }} + + {{- if .Values.composer.additionalPhpExtensions }} + echo "Installing additional PHP extensions..." + {{- range .Values.composer.additionalPhpExtensions }} + docker-php-ext-install {{ . }} + {{- end }} + {{- end }} + + # ======================================== + # Composerのインストールと実行 + # ======================================== + {{- if or .Values.composer.enabled .Values.selenium.enabled }} + echo "Installing Composer..." + curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + + cd /var/www/html + + {{- if .Values.composer.enabled }} + # ユーザー定義のComposer設定 + {{- if .Values.composer.useComposerJson }} + # composer.jsonファイルを使用 + echo "Creating composer.json from values..." + cat > composer.json << 'COMPOSER_JSON_EOF' + {{ .Values.composer.composerJson }} + COMPOSER_JSON_EOF + + {{- if .Values.composer.composerLock }} + echo "Creating composer.lock from values..." + cat > composer.lock << 'COMPOSER_LOCK_EOF' + {{ .Values.composer.composerLock }} + COMPOSER_LOCK_EOF + {{- end }} + + echo "Running composer install..." + composer install {{ .Values.composer.installOptions }} + + {{- else if .Values.composer.packages }} + # パッケージリストから直接インストール + echo "Installing Composer packages..." + {{- range .Values.composer.packages }} + composer require {{ . }} + {{- end }} + + {{- if .Values.composer.installOptions }} + # オプティマイズ実行 + composer install {{ .Values.composer.installOptions }} + {{- end }} + + {{- else }} + # composer.jsonが既に存在する場合はそれを使用 + if [ -f composer.json ]; then + echo "Found existing composer.json, running composer install..." + composer install {{ .Values.composer.installOptions }} + else + echo "No composer configuration found, skipping package installation" + fi + {{- end }} + {{- end }} + + {{- if .Values.selenium.enabled }} + # Selenium用のパッケージインストール(レガシー互換性) + echo "Installing Selenium WebDriver package..." + composer require php-webdriver/webdriver + {{- end }} + {{- end }} + {{- end }} + + echo "Setup complete, starting PHP-FPM..." php-fpm ports: - containerPort: 9000 # PHP-FPMは9000ポートでリッスン @@ -58,6 +151,10 @@ spec: - name: app-storage mountPath: /var/www/html subPath: html + {{- if and .Values.composer.enabled .Values.composer.useComposerJson }} + - name: composer-config + mountPath: /tmp/composer-init + {{- end }} env: {{- if .Values.externalDatabase.enabled }} - name: DB_HOST @@ -101,3 +198,8 @@ spec: - name: nginx-config configMap: name: {{ include "phpfpm.fullname" . }}-nginx-config + {{- if and .Values.composer.enabled .Values.composer.useComposerJson }} + - name: composer-config + configMap: + name: {{ include "phpfpm.fullname" . }}-composer-config + {{- end }} \ No newline at end of file