apiVersion: apps/v1
kind: Deployment
metadata:
  name: joomla
  namespace: joomla
  labels:
    app: joomla
spec:
  replicas: 1
  selector:
    matchLabels:
      app: joomla
  strategy:
    rollingUpdate:
      maxSurge: 0
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: joomla
    spec:
      containers:
      - image: riscv64/joomla:5.2.3-php8.1-fpm-alpine
        name: joomla
        imagePullPolicy: Always
        env:
        - name: JOOMLA_DB_HOST
          value: "mariadb.mariadb"
        - name: JOOMLA_DB_USER
          value: "joomla"
        - name: JOOMLA_DB_PASSWORD
          value: "joomla"
#        - JOOMLA_DB_PASSWORD_FILE:
#          value: "1000"
        - name: JOOMLA_DB_NAME
          value: "joomla"
        - name: JOOMLA_DB_TYPE
          value: "mysqli"
        - name: JOOMLA_SITE_NAME
          value: "allarddcs"
        - name: JOOMLA_ADMIN_USER
          value: "admin"
        - name: JOOMLA_ADMIN_USERNAME
          value: "admin"
        - name: JOOMLA_ADMIN_PASSWORD
          value: "JoomlaJoomla01"
        - name: JOOMLA_ADMIN_EMAIL
          value: "admin@allarddcs.nl"
#        - JOOMLA_EXTENSIONS_URLS:
#          value: "1000"
#        - JOOMLA_EXTENSIONS_PATHS:
#          value: "1000"
#        - JOOMLA_SMTP_HOST:
#          value: "1000"
#        - JOOMLA_SMTP_HOST_PORT:
        ports:
         - containerPort: 9000
           name: php-fpm
           protocol: TCP
        volumeMounts:
         - name: nfs-joomla
           mountPath: /var/www/html
           subPath: html
      - name: nginx
        image: riscv64/nginx:1.27.4-alpine
        ports:
          - containerPort: 80
        volumeMounts:
          - name: nfs-joomla
            mountPath: /var/www/html
            subPath: html
          - name: nfs-joomla
            mountPath: /etc/nginx/conf.d/default.conf
            subPath: default.conf
      volumes:
      - name: nfs-joomla
        persistentVolumeClaim:
          claimName: joomla-pvc
      volumes:
      - name: nfs-joomla                # < linkname of the volume for the pvc
        persistentVolumeClaim:
          claimName: joomla-pvc         # < pvc name we created in the previous yaml
---
apiVersion: v1
kind: Service
metadata:
  name: joomla
  namespace: joomla
spec:
  selector:
    app: joomla
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: joomla-http
  namespace: joomla
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`joomla-riscv.allarddcs.nl`)
      kind: Rule
      services:
        - name: joomla
          port: 80
      middlewares:
        - name: redirect-to-https
          namespace: joomla
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: joomla-tls
  namespace: joomla
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`joomla-riscv.allarddcs.nl`)
      kind: Rule
      services:
        - name: joomla
          port: 80
  tls:
    certResolver: letsencrypt
---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: redirect-to-https
  namespace: joomla
spec:
  redirectScheme:
    scheme: https
    permanent: true
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: joomla-pv
spec:
  storageClassName: ""
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    server: 192.168.2.110
    path: /mnt/nfs_share/joomla/riscv
    readOnly: false
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: joomla-pvc
  namespace: joomla
spec:
  storageClassName: ""
  volumeName: joomla-pv
  accessModes:
    - ReadWriteMany
  volumeMode: Filesystem
  resources:
    requests:
      storage: 2Gi
