diff --git a/templates/configmap.yaml b/templates/configmap.yaml new file mode 100644 index 0000000..cae0df2 --- /dev/null +++ b/templates/configmap.yaml @@ -0,0 +1,60 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "phpfpm.fullname" . }}-nginx-config + labels: + {{- include "phpfpm.labels" . | nindent 4 }} +data: + nginx.conf: | + user nginx; + worker_processes 1; + + error_log /var/log/nginx/error.log warn; + pid /var/run/nginx.pid; + + events { + worker_connections 1024; + } + + http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + keepalive_timeout 65; + + server { + listen 80; + server_name localhost; + + root /var/www/html; + index index.php index.html index.htm; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ \.php$ { + include fastcgi_params; + fastcgi_pass 127.0.0.1:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + {{- if .Values.nginx.customConfig.enabled }} + {{ .Values.nginx.customConfig.snippet | indent 12 }} + {{- end }} + + } + } diff --git a/templates/deployment.yaml b/templates/deployment.yaml new file mode 100644 index 0000000..6fb38bb --- /dev/null +++ b/templates/deployment.yaml @@ -0,0 +1,102 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "phpfpm.fullname" . }} + labels: + {{- include "phpfpm.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "phpfpm.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "phpfpm.selectorLabels" . | nindent 8 }} + spec: + containers: + - name: nginx + image: "{{ .Values.image.nginx.registry }}/{{ .Values.image.nginx.repository }}:{{ .Values.image.nginx.tag }}" + imagePullPolicy: {{ .Values.image.nginx.pullPolicy }} + ports: + - containerPort: 80 + volumeMounts: + - name: app-storage + mountPath: /var/www/html + subPath: html + - name: nginx-config + mountPath: /etc/nginx/nginx.conf + subPath: nginx.conf + - name: php-fpm + image: "{{ .Values.image.php.registry }}/{{ .Values.image.php.repository }}:{{ .Values.image.php.tag }}" + imagePullPolicy: {{ .Values.image.php.pullPolicy }} + command: + - 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.3 Alpine..." + apk add --no-cache php83 php83-pdo_mysql + {{- end }} + ) + {{- end }} + php-fpm + ports: + - containerPort: 9000 # PHP-FPMは9000ポートでリッスン + volumeMounts: + - name: app-storage + mountPath: /var/www/html + subPath: html + env: + {{- if .Values.externalDatabase.enabled }} + - name: DB_HOST + value: {{ .Values.externalDatabase.host | quote }} + - name: DB_PORT + value: {{ .Values.externalDatabase.port | quote }} + - name: DB_NAME + value: {{ .Values.externalDatabase.database | quote }} + - name: DB_USER + value: {{ .Values.externalDatabase.username | quote }} + - name: DB_PASS + valueFrom: + secretKeyRef: + name: {{ include "phpfpm.fullname" . }}-db-secret + key: {{ include "phpfpm.fullname" . }}-db-key + {{- end }} + {{- if .Values.selenium.enabled }} + - name: selenium + image: "{{ .Values.image.selenium.registry }}/{{ .Values.image.selenium.repository }}:{{ .Values.image.selenium.tag }}" + imagePullPolicy: {{ .Values.image.selenium.pullPolicy }} + ports: + - containerPort: 4444 # Selenium用ポート + volumeMounts: + - name: app-storage + mountPath: /var/www/html + subPath: html + {{- end }} + dnsPolicy: ClusterFirst + dnsConfig: + options: + - name: ndots + value: "1" + volumes: + - name: app-storage + {{- if .Values.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ include "phpfpm.fullname" . }}-pvc + {{- else }} + emptyDir: {} + {{- end }} + - name: nginx-config + configMap: + name: {{ include "phpfpm.fullname" . }}-nginx-config diff --git a/templates/ingress.yaml b/templates/ingress.yaml new file mode 100644 index 0000000..c72b810 --- /dev/null +++ b/templates/ingress.yaml @@ -0,0 +1,39 @@ +{{- if .Values.ingress.enabled }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "phpfpm.fullname" . }} + labels: + {{- include "phpfpm.labels" . | nindent 4 }} + annotations: + {{- toYaml .Values.ingress.annotations | nindent 4 }} +spec: + {{- if .Values.ingress.className }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ include "phpfpm.fullname" $ }} + port: + number: {{ $.Values.service.port }} + {{- end }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - secretName: {{ .secretName }} + hosts: + {{- range .hosts }} + - {{ . }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/templates/pvc.yaml b/templates/pvc.yaml new file mode 100644 index 0000000..652a7d0 --- /dev/null +++ b/templates/pvc.yaml @@ -0,0 +1,14 @@ +{{- if .Values.persistence.enabled }} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "phpfpm.fullname" . }}-pvc + labels: + {{- include "phpfpm.labels" . | nindent 4 }} +spec: + accessModes: + - {{ .Values.persistence.accessMode }} + resources: + requests: + storage: {{ .Values.persistence.size }} +{{- end }} diff --git a/templates/service.yaml b/templates/service.yaml new file mode 100644 index 0000000..04ceee1 --- /dev/null +++ b/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "phpfpm.fullname" . }} + labels: + {{- include "phpfpm.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: 80 + protocol: TCP + name: http + selector: + {{- include "phpfpm.selectorLabels" . | nindent 4 }}