# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Odoo 19
spec:
    description: |
        Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.
    coverImage: https://raw.githubusercontent.com/canyugs/zeabur-template/refs/heads/main/odoo/screenshot.webp
    icon: https://odoocdn.com/openerp_website/static/src/img/assets/svg/odoo_logo.svg
    variables:
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: Domain
          description: What domain do you want to bind to?
    tags:
        - CRM
        - ERP
        - CMS
        - eCommerce
    readme: |
        # Odoo
        Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.
        Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

        ## Usage
        - Open your browser and go to `https://${PUBLIC_DOMAIN}`
        - Login with the username `admin` and `admin` as the password, and change the password for the admin user
        - Or create a new database to create a new admin user

        ## Configuration
        - See more configuration options in the [Odoo documentation](https://www.odoo.com/documentation/18.0/administration/on_premise/deploy.html)
    services:
        - name: postgresql
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            source:
                image: postgres:15
                command:
                    - docker-entrypoint.sh
                    - -c
                    - config_file=/etc/postgresql/postgresql.conf
            ports:
                - id: database
                  port: 5432
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/postgresql/data
            instructions:
                - title: Connection String
                  content: postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}
                - title: PostgreSQL Connect Command
                  content: psql "postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}"
                - title: PostgreSQL username
                  content: ${POSTGRES_USERNAME}
                - title: PostgresSQL password
                  content: ${POSTGRES_PASSWORD}
                - title: PostgresSQL database
                  content: ${POSTGRES_DATABASE}
                - title: PostgreSQL host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: PostgreSQL port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                PGDATA:
                    default: /var/lib/postgresql/data/pgdata
                POSTGRES_CONNECTION_STRING:
                    default: postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}
                    expose: true
                POSTGRES_DATABASE:
                    default: ${POSTGRES_DB}
                    expose: true
                POSTGRES_DB:
                    default: odoo
                POSTGRES_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                POSTGRES_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                POSTGRES_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                POSTGRES_URI:
                    default: ${POSTGRES_CONNECTION_STRING}
                    expose: true
                POSTGRES_USER:
                    default: odoo-admin
                POSTGRES_USERNAME:
                    default: ${POSTGRES_USER}
                    expose: true
            configs:
                - path: /etc/postgresql/postgresql.conf
                  template: |
                    # https://github.com/postgres/postgres/blob/master/src/backend/utils/misc/postgresql.conf.sample
                    listen_addresses = '*'
                    max_connections = 100
                    shared_buffers = 128MB
                    dynamic_shared_memory_type = posix
                    max_wal_size = 1GB
                    min_wal_size = 80MB
                    log_timezone = 'Etc/UTC'
                    datestyle = 'iso, mdy'
                    timezone = 'Etc/UTC'
                    lc_messages = 'en_US.utf8'
                    lc_monetary = 'en_US.utf8'
                    lc_numeric = 'en_US.utf8'
                    lc_time = 'en_US.utf8'
                    default_text_search_config = 'pg_catalog.english'
                  permission: null
                  envsubst: null
        - name: odoo
          icon: https://odoocdn.com/openerp_website/static/src/img/assets/svg/odoo_logo.svg
          template: PREBUILT
          spec:
            source:
                image: odoo:19.0
            ports:
                - id: web
                  port: 8069
                  type: HTTP
            volumes:
                - id: odoo-data
                  dir: /var/lib/odoo
                - id: odoo-addons
                  dir: /mnt/extra-addons
            instructions:
                - title: Odoo Database Master Password
                  content: ${ODOO_DATABASE_MASTER_PASSWORD}
            env:
                ODOO_DATABASE_MASTER_PASSWORD:
                    default: ${PASSWORD}
            init:
                - id: init-db
                  image: null
                  command:
                    - /bin/bash
                    - -c
                    - |
                      DB_ARGS=()
                      DB_ARGS+=("--db_host")
                      DB_ARGS+=("${POSTGRES_HOST}")
                      DB_ARGS+=("--db_port")
                      DB_ARGS+=("${POSTGRES_PORT}")
                      DB_ARGS+=("--db_user")
                      DB_ARGS+=("${POSTGRES_USERNAME}")
                      DB_ARGS+=("--db_password")
                      DB_ARGS+=("${POSTGRES_PASSWORD}")

                      if [ ! -f /var/lib/odoo/.initialized ]; then
                        wait-for-psql.py ${DB_ARGS[@]} --timeout=30
                        odoo -i base -d ${POSTGRES_DATABASE} --stop-after-init "${DB_ARGS[@]}"
                        touch /var/lib/odoo/.initialized
                      fi
                  volumes: null
            configs:
                - path: /etc/odoo/odoo.conf
                  template: "[options]\naddons_path = /mnt/extra-addons\ndata_dir = /var/lib/odoo\nadmin_passwd = ${ODOO_DATABASE_MASTER_PASSWORD}\ndb_host = ${POSTGRES_HOST}\ndb_port = ${POSTGRES_PORT}\ndb_name = ${POSTGRES_DATABASE}\ndb_user = ${POSTGRES_USERNAME}\ndb_password = ${POSTGRES_PASSWORD}\nlimit_time_cpu = 600\nlimit_time_real = 1200\n; load_language = zh_TW\n; csv_internal_sep = ,\n; db_maxconn = 64\n; db_template = template1\n; dbfilter = .*\n; debug_mode = False\n; email_from = False\n; limit_memory_hard = 2684354560\n; limit_memory_soft = 2147483648\n; limit_request = 8192\n; list_db = True\n; log_db = False\n; log_handler = [':INFO']\n; log_level = info\n; logfile = None\n; longpolling_port = 8072\n; max_cron_threads = 2\n; osv_memory_age_limit = 1.0\n; osv_memory_count_limit = False\n; smtp_password = False\n; smtp_port = 25\n; smtp_server = localhost\n; smtp_ssl = False\n; smtp_user = False\n; workers = 0\n; xmlrpc = True\n; xmlrpc_interface = \n; xmlrpc_port = 8069\n; xmlrpcs = True\n; xmlrpcs_interface = \n; xmlrpcs_port = 8071\n"
                  permission: null
                  envsubst: true
          domainKey: PUBLIC_DOMAIN
