apiVersion: container.mom/v1alpha1
kind: Template
metadata:
  name: wordpress
  namespace: container-mom-system
  labels:
    argocd.argoproj.io/instance: operator
spec:
  description: WordPress deployment with MariaDB database
  parameters:
    - name: SITE_NAME
      displayName: Site Name  
      description: Name of your WordPress site
      defaultValue: My WordPress Site
      required: true
    - name: ADMIN_EMAIL
      displayName: Admin Email
      description: WordPress admin email
      required: true
    - name: ADMIN_PASSWORD
      displayName: Admin Password
      description: WordPress admin password
      generate: expression
      required: true
    - name: MYSQL_ROOT_PASSWORD
      displayName: Database Root Password
      description: MySQL root password
      generate: expression
      required: true
    - name: MYSQL_DATABASE
      displayName: Database Name
      description: MySQL database name
      defaultValue: wordpress
      required: true
    - name: MYSQL_USER
      displayName: Database User
      description: MySQL user name
      defaultValue: wordpress
      required: true
    - name: MYSQL_PASSWORD
      displayName: Database Password
      description: MySQL user password
      generate: expression
      required: true
    - name: DOMAIN_NAME
      displayName: Domain Name
      description: Domain name for WordPress
      required: false
  components:
    - name: wordpress
      type: deployment
      properties:
        image: bitnami/wordpress:latest
        securityContext:
          runAsUser: 1001
          fsGroup: 1001
        resources:
          cpu: 500m
          memory: 512Mi
        env:
          - name: WORDPRESS_DATABASE_HOST
            value: mariadb:3306
          - name: WORDPRESS_DATABASE_PORT_NUMBER
            value: "3306"
          - name: WORDPRESS_DATABASE_NAME
            value: ${MYSQL_DATABASE}
          - name: WORDPRESS_DATABASE_USER
            value: ${MYSQL_USER}
          - name: WORDPRESS_DATABASE_PASSWORD
            value: ${MYSQL_PASSWORD}
          - name: WORDPRESS_USERNAME
            value: admin
          - name: WORDPRESS_PASSWORD
            value: ${ADMIN_PASSWORD}
          - name: WORDPRESS_EMAIL
            value: ${ADMIN_EMAIL}
          - name: WORDPRESS_BLOG_NAME
            value: ${SITE_NAME}
          - name: ALLOW_EMPTY_PASSWORD
            value: "yes"
          - name: WORDPRESS_SKIP_BOOTSTRAP
            value: "no"
          - name: WORDPRESS_TABLE_PREFIX
            value: wp_
          - name: WORDPRESS_CONFIG_EXTRA
            value: define('WP_HOME','https://${DOMAIN_NAME}'); define('WP_SITEURL','https://${DOMAIN_NAME}');
        volumes:
          - name: wordpress-data
            type: persistentVolumeClaim
            size: 10Gi
            storageClass: forgejo-local-storage
            mountPath: /bitnami/wordpress
    - name: mariadb
      type: statefulset
      properties:
        image: bitnami/mariadb:latest
        securityContext:
          runAsUser: 1001
          fsGroup: 1001
        resources:
          cpu: 500m
          memory: 1Gi
        env:
          - name: MARIADB_ROOT_PASSWORD
            value: ${MYSQL_ROOT_PASSWORD}
          - name: MARIADB_DATABASE
            value: ${MYSQL_DATABASE}
          - name: MARIADB_USER
            value: ${MYSQL_USER}
          - name: MARIADB_PASSWORD
            value: ${MYSQL_PASSWORD}
          - name: ALLOW_EMPTY_PASSWORD
            value: "no"
        statefulSetConfig:
          serviceName: mariadb-headless
          podManagementPolicy: OrderedReady
          updateStrategy:
            type: RollingUpdate
        volumeClaimTemplates:
          - name: mariadb-data
            accessModes:
              - ReadWriteOnce
            size: 5Gi
            storageClass: forgejo-local-storage
            mountPath: /bitnami/mariadb
    - name: wordpress
      type: service
      properties:
        targetComponent: wordpress
        ports:
          - name: http
            port: 80
            protocol: TCP
            targetPort: 8080
    - name: mariadb
      type: service
      properties:
        targetComponent: mariadb
        ports:
          - name: mysql
            port: 3306
            protocol: TCP
            targetPort: 3306
    - name: mariadb-headless
      type: service
      properties:
        targetComponent: mariadb
        ports:
          - name: mysql
            port: 3306
            protocol: TCP
            targetPort: 3306
    - name: wordpress-config
      type: configmap
      properties:
        configData:
          admin_email: ${ADMIN_EMAIL}
          site_name: ${SITE_NAME}
  networkConfig:
    domain:
      domainName: ${DOMAIN_NAME}
      useWildcard: false
      tls:
        autoCert: true
        email: ${ADMIN_EMAIL}
    ingressRules:
      - host: ${DOMAIN_NAME}
        path: /
        serviceName: wordpress
        servicePort: 80
