# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Discourse
spec:
    description: A platform for community discussion. Free, open, simple.
    coverImage: https://blog.discourse.org/content/images/size/w2000/2023/08/2023-08_FeaturedImage-3.1-v2-1.jpg
    icon: https://avatars.githubusercontent.com/u/3220138
    variables:
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: Discourse Domain
          description: The domain name for your Discourse instance.
    tags:
        - Website
    readme: |
        # Discourse - The online home for your community

        Discourse make your community easy to connect and collaborate anytime, anywhere. Discourse now powers over 20,000 online communities of all shapes and sizes, including GitLab, SailPoint, OpenAI, Elastic, Docker, Unreal Engine, and many more.

        For more details about Discourse, see [their homepage](https://www.discourse.org).

        ## Features

        - **Features for every use case**: Discourse enables thoughtful discussion and meaningful connections with features for every use case, from tracking product feedback to sharing your latest creations, now with the added support of AI.
        - **Endless ways to customize**: Keep your forum on brand, integrate with your tech stack, and optimize forum features for engagement.
        - **Quick chats and thoughtful discussions**: An integrated experience for chat and long form discussions enables members to build relationships while your community builds knowledge.
        - **Powerful moderation tools**: Keep the discussion healthy, on-track, and free from any inappropriate content with our best-in-class moderation tools and AI.
        - **Fully open source**: The entire Discourse codebase is open and freely available to the public—forever.
        - **Truly portable data**: No matter where your forum lives, you retain full ownership of your data. No lock-in, no hidden fees, no data sent to advertisers.
        - **Unlimited conversation history**: Always have full access to your community's conversation history—no questions asked.

        ## Usage

        This Discourse is based on the Bitnami Discourse image. You can find more information about the image [here](https://hub.docker.com/r/bitnami/discourse).

        The initialization may take about 5 minutes. Before the initialization is complete, you may see a 502 error.

        You can see the username and password of your Discourse instance in the "Overview" > "Instructions" section.

        ### Plugin Installation

        Run the following command to install the plugin:

        ```bash
        cd /opt/bitnami/discourse && RAILS_ENV=production bundle exec rake plugin:install repo=<plugin Git repository URL>
        ```

        Replace `<plugin Git repository URL>` with the URL of the plugin's Git repository. For example, to install the `discourse-custom-header-links` plugin, run the following command:

        ```bash
        cd /opt/bitnami/discourse && RAILS_ENV=production bundle exec rake plugin:install repo=https://github.com/discourse/discourse-custom-header-links
        ```

        After the installation of your plugin, restart your Discourse to precompile the assets.

        ### SMTP configuration

        You will see some variables starting with `DISCOURSE_SMTP` in the "Environment Variables" section. You can set these variables to configure the SMTP settings for your Discourse instance.

        After the configuration, restart your Discourse **and Sidekiq** to apply the changes.
    services:
        - name: postgresql
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            id: postgresql
            source:
                image: pgvector/pgvector:pg17
                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: zeabur
                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: root
                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'

                    # https://github.com/discourse/discourse_docker/blob/main/templates/postgres.template.yml
                    synchronous_commit = off
                    shared_buffers = 256MB
                    work_mem = 40MB
                    logging_collector = off
                    log_min_duration_statement = 100
                  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:
                CONFFILE:
                    default: /etc/redis-stack.conf
                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
            configs:
                - path: /etc/redis-stack.conf
                  template: |
                    port 6379
                    daemonize no
                  permission: null
                  envsubst: null
        - name: discourse
          icon: https://avatars.githubusercontent.com/u/3220138
          dependencies:
            - postgresql
            - redis
          template: PREBUILT_V2
          spec:
            id: discourse
            source:
                image: zeabur/bitnami-discourse:3
            ports:
                - id: web
                  port: 3000
                  type: HTTP
            volumes:
                - id: data
                  dir: /bitnami/discourse
            instructions:
                - title: Discourse username
                  content: ${DISCOURSE_USERNAME}
                - title: Discourse password
                  content: ${DISCOURSE_PASSWORD}
            env:
                DISCOURSE_DATABASE_HOST:
                    default: ${POSTGRES_HOST}
                    expose: true
                DISCOURSE_DATABASE_NAME:
                    default: ${POSTGRES_DATABASE}
                    expose: true
                DISCOURSE_DATABASE_PASSWORD:
                    default: ${POSTGRES_PASSWORD}
                    expose: true
                DISCOURSE_DATABASE_PORT_NUMBER:
                    default: ${POSTGRES_PORT}
                    expose: true
                DISCOURSE_DATABASE_USER:
                    default: ${POSTGRES_USERNAME}
                    expose: true
                DISCOURSE_EMAIL:
                    default: discourse@zeabur.com
                    expose: true
                DISCOURSE_HOST:
                    default: ${ZEABUR_WEB_DOMAIN}
                    expose: true
                DISCOURSE_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                DISCOURSE_REDIS_HOST:
                    default: ${REDIS_HOST}
                    expose: true
                DISCOURSE_REDIS_PASSWORD:
                    default: ${REDIS_PASSWORD}
                    expose: true
                DISCOURSE_REDIS_PORT_NUMBER:
                    default: ${REDIS_PORT}
                    expose: true
                DISCOURSE_REDIS_USE_SSL:
                    default: "false"
                    expose: true
                DISCOURSE_SMTP_HOST:
                    default: ""
                    expose: true
                DISCOURSE_SMTP_PASSWORD:
                    default: ""
                    expose: true
                DISCOURSE_SMTP_PORT:
                    default: ""
                    expose: true
                DISCOURSE_SMTP_PROTOCOL:
                    default: ""
                    expose: true
                DISCOURSE_SMTP_USER:
                    default: ""
                    expose: true
                DISCOURSE_USERNAME:
                    default: discourse
                    expose: true
        - name: sidekiq
          icon: https://avatars.githubusercontent.com/u/3220138
          dependencies:
            - discourse
          template: PREBUILT_V2
          spec:
            id: sidekiq
            source:
                image: zeabur/bitnami-discourse:3
                command:
                    - /opt/bitnami/scripts/discourse-sidekiq/run.sh
            ports:
                - id: web
                  port: 3000
                  type: HTTP
            volumes:
                - id: data
                  dir: /bitnami/discourse
            env:
                DATABASE_URL:
                    default: ${POSTGRES_CONNECTION_STRING}
