# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: UniTranslate
spec:
    description: UniTranslate 是一个高性能的翻译服务，支持多种缓存和存储后端。
    icon: https://raw.githubusercontent.com/xgd16/UniTranslate/master/logo.svg
    variables:
        - key: API_KEY
          type: STRING
          name: API 密钥
          description: 用于 HTTP API 的密钥
    tags:
        - Translation
        - Tool
    readme: |-
        # UniTranslate

        UniTranslate 是一个高性能的翻译服务，支持多种缓存和存储后端，包括 Redis 和 MySQL。它提供灵活的配置选项，适用于各种翻译需求。
    services:
        - 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: 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: UniTranslate
          icon: https://raw.githubusercontent.com/xgd16/UniTranslate/master/logo.svg
          template: PREBUILT
          spec:
            id: unitranslate
            source:
                image: xgd16/uni-translate:latest
            ports:
                - id: web
                  port: 9431
                  type: HTTP
            env:
                API_KEY:
                    default: ${API_KEY}
                    expose: true
            configs:
                - path: /workspace/config.yaml
                  template: |-
                    # 基础 http 配置
                    server:
                      name: uniTranslate
                      address: "0.0.0.0:9431"
                      cacheMode: redis
                      cachePlatform: true
                      cacheRefreshOnStartup: false
                      key: "${API_KEY}"
                      keyMode: 1
                      configDeviceMode: "xdb"
                      recordDeviceMode: "mysql"
                      configDeviceDb: "default"
                      cacheWriteToStorage: true
                      requestRecordKeepDays: 7
                      apiEditConfig: true

                    # 数据库
                    database:
                      default:
                        type: "mysql"
                        link: "${MYSQL_USERNAME}:${MYSQL_PASSWORD}@tcp(${MYSQL_HOST}:${MYSQL_PORT})/${MYSQL_DATABASE}?charset=utf8mb4&parseTime=true&loc=Local"
                        createdAt: "createTime"
                        updatedAt: "updateTime"
                        debug: true

                    # redis
                    redis:
                      default:
                        address: ${REDIS_HOST}:${REDIS_PORT}
                        db: 0
                        pass: "${REDIS_PASSWORD}"

                    # 日志
                    logger:
                      path: "./log/default"
                      level: "all"
                      stdout: false
                      writerColorEnable: true

                    # GrayLog 支持
                    graylog:
                      open: false
                      host:
                      port:
                  permission: null
                  envsubst: true
