# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Max API
spec:
    description: 中转 API 分发系统 (New API 二开美化版)
    icon: https://i.imgur.com/3pRJ59s.png
    variables:
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: 域名
          description: 你想要绑定到 Max API 的域名
    tags:
        - Starter
        - Tool
        - Website
    readme: 中转 API 分发系统 (New API 二开美化版)
    services:
        - name: mysql
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/mysql.svg
          template: PREBUILT
          spec:
            id: mysql
            source:
                image: mysql:8.0.33
            ports:
                - id: database
                  port: 3306
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/mysql
            instructions:
                - title: Command to connect to your MySQL
                  content: mysqlsh --sql --host=${PORT_FORWARDED_HOSTNAME} --port=${DATABASE_PORT_FORWARDED_PORT} --user=${MYSQL_USERNAME} --password=${MYSQL_PASSWORD} --schema=${MYSQL_DATABASE}
                - title: MySQL username
                  content: ${MYSQL_USERNAME}
                - title: MySQL password
                  content: ${MYSQL_PASSWORD}
                - title: MySQL database
                  content: ${MYSQL_DATABASE}
                - title: MySQL host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: MySQL port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                MYSQL_DATABASE:
                    default: zeabur
                    expose: true
                MYSQL_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                MYSQL_PASSWORD:
                    default: ${MYSQL_ROOT_PASSWORD}
                    expose: true
                MYSQL_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                MYSQL_ROOT_PASSWORD:
                    default: ${PASSWORD}
                MYSQL_USERNAME:
                    default: root
                    expose: true
            configs:
                - path: /etc/my.cnf
                  template: |
                    [mysqld]
                    default-authentication-plugin=mysql_native_password
                    skip-host-cache
                    skip-name-resolve
                    datadir=/var/lib/mysql
                    socket=/var/run/mysqld/mysqld.sock
                    secure-file-priv=/var/lib/mysql-files
                    user=mysql
                    max_allowed_packet=10M

                    pid-file=/var/run/mysqld/mysqld.pid
                    [client]
                    socket=/var/run/mysqld/mysqld.sock

                    !includedir /etc/mysql/conf.d/
                  permission: null
                  envsubst: null
        - name: redis
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/redis.svg
          template: PREBUILT
          spec:
            id: redis
            source:
                image: redis/redis-stack-server:latest
            ports:
                - id: database
                  port: 6379
                  type: TCP
            volumes:
                - id: data
                  dir: /data
            instructions:
                - title: Command to connect to your Redis
                  content: redis-cli -h ${PORT_FORWARDED_HOSTNAME} -p ${DATABASE_PORT_FORWARDED_PORT} -a ${REDIS_PASSWORD}
                - title: Redis Connection String
                  content: redis://:${REDIS_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}
                - title: Redis password
                  content: ${REDIS_PASSWORD}
                - title: Redis host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: Redis port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                REDIS_ARGS:
                    default: --requirepass ${REDIS_PASSWORD}
                REDIS_CONNECTION_STRING:
                    default: redis://:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}
                    expose: true
                REDIS_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                REDIS_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                REDIS_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                REDIS_URI:
                    default: ${REDIS_CONNECTION_STRING}
                    expose: true
        - name: max-api
          icon: https://i.imgur.com/3pRJ59s.png
          template: PREBUILT
          spec:
            id: max-api
            source:
                image: pochacco/max-api:latest
            ports:
                - id: web
                  port: 3000
                  type: HTTP
            env:
                REDIS_CONN_STRING:
                    default: ${REDIS_URI}
                SESSION_SECRET:
                    default: ${PASSWORD}
                SQL_DSN:
                    default: ${MYSQL_USERNAME}:${MYSQL_PASSWORD}@tcp(${MYSQL_HOST}:${MYSQL_PORT})/${MYSQL_DATABASE}
                TZ:
                    default: Asia/Shanghai
          domainKey: PUBLIC_DOMAIN
