# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Mastodon
spec:
    description: Social networking that's not for sale.
    icon: https://joinmastodon.org/logos/logo-purple.svg
    variables:
        - key: MASTODON_WEB_DOMAIN
          type: DOMAIN
          name: Web Domain
          description: Mastodon Web Domain
        - key: MASTODON_ADMIN_USERNAME
          type: STRING
          name: Instance Admin Username
          description: Mastodon admin username.
        - key: MASTODON_ADMIN_EMAIL
          type: STRING
          name: Instance Admin E-Mail Address
          description: Mastodon admin email.
    tags:
        - Blog
        - Website
    readme: |-
        Mastodon is a **free, open-source social network server** based on ActivityPub where users can follow friends and discover new ones. On Mastodon, users can publish anything they want: links, pictures, text, and video. All Mastodon servers are interoperable as a federated network (users on one server can seamlessly communicate with users from another one, including non-Mastodon software that implements ActivityPub!)
        Click below to **learn more** in a video:

        [![Screenshot](https://blog.joinmastodon.org/2018/06/why-activitypub-is-the-future/ezgif-2-60f1b00403.gif)][youtube_demo]

        [youtube_demo]: https://www.youtube.com/watch?v=IPSbNdBmWKE

        ## How To
        To deploy a Mastodon instance, click the button, and wait.

        **Important Notice** : You should generate your own MASTODON_OTP_SECRET, MASTODON_SECRET_KEY_BASE, ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT, ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY, and ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY

        ### How To Generate Secrets
        MASTODON_OTP_SECRET, MASTODON_SECRET_KEY_BASE: `openssl rand -hex 64`


        ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY, ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT, ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY: Run this ruby script: https://gist.github.com/ffha/17325ae25ae4880f0444c5fcd9e7f1d0
    services:
        - name: PostgreSQL
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            source:
                image: zeabur/bitnami-postgresql:14
            ports:
                - id: database
                  port: 5432
                  type: TCP
            volumes:
                - id: database
                  dir: /bitnami/postgresql
            instructions:
                - title: Connection String
                  content: postgresql://${POSTGRESQL_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRESQL_DATABASE}
                - title: PostgreSQL Connect Command
                  content: psql "postgresql://${POSTGRESQL_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRESQL_DATABASE}"
                - title: PostgreSQL username
                  content: ${POSTGRESQL_USERNAME}
                - title: PostgresSQL password
                  content: ${POSTGRESQL_PASSWORD}
                - title: PostgresSQL database
                  content: ${POSTGRESQL_DATABASE}
                - title: PostgreSQL host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: PostgreSQL port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                DATABASE_URL:
                    default: postgresql://${POSTGRESQL_USERNAME}:${POSTGRESQL_PASSWORD}@${POSTGRESQL_HOST}:${POSTGRESQL_PORT_NUMBER}/${POSTGRESQL_DATABASE}
                    expose: true
                POSTGRESQL_DATABASE:
                    default: mastodon
                    expose: true
                POSTGRESQL_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                POSTGRESQL_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                POSTGRESQL_PORT_NUMBER:
                    default: ${DATABASE_PORT}
                    expose: true
                POSTGRESQL_USERNAME:
                    default: mastodon
                    expose: true
        - name: Redis
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/redis.svg
          template: PREBUILT
          spec:
            source:
                image: zeabur/bitnami-redis:8.2.1
            ports:
                - id: cache
                  port: 6379
                  type: TCP
            volumes:
                - id: redis-data
                  dir: /bitnami/redis/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_CONNECTION_STRING:
                    default: redis://:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT_NUMBER}
                    expose: true
                REDIS_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                REDIS_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                REDIS_PORT_NUMBER:
                    default: ${CACHE_PORT}
                    expose: true
                REDIS_URL:
                    default: ${REDIS_CONNECTION_STRING}
                    expose: true
        - name: Web
          icon: https://joinmastodon.org/logos/logo-purple.svg
          dependencies:
            - Redis
            - PostgreSQL
          template: PREBUILT
          spec:
            source:
                image: zeabur/bitnami-mastodon:4.4.3
            ports:
                - id: web
                  port: 3000
                  type: HTTP
            volumes:
                - id: mastodon-data
                  dir: /bitnami/mastodon
            env:
                ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY:
                    default: 1CrG9j0WF1zGXOUAykfw0I4DvSeCz1KB
                    expose: true
                ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT:
                    default: 95jWyk7LK9mwxp4r2EVwNGpUCsXJCmOv
                    expose: true
                ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY:
                    default: jxXjXLSYLNSvl66wPo2qIJib8BPyUmbJ
                    expose: true
                LOCAL_DOMAIN:
                    default: ${MASTODON_WEB_DOMAIN}
                MASTODON_ADMIN_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                MASTODON_DATABASE_HOST:
                    default: ${POSTGRESQL_HOST}
                    expose: true
                MASTODON_DATABASE_NAME:
                    default: ${POSTGRESQL_DATABASE}
                    expose: true
                MASTODON_DATABASE_PASSWORD:
                    default: ${POSTGRESQL_PASSWORD}
                    expose: true
                MASTODON_DATABASE_PORT_NUMBER:
                    default: ${POSTGRESQL_PORT_NUMBER}
                    expose: true
                MASTODON_DATABASE_USERNAME:
                    default: ${POSTGRESQL_USERNAME}
                    expose: true
                MASTODON_ELASTICSEARCH_ENABLED:
                    default: "false"
                    expose: true
                MASTODON_MODE:
                    default: web
                MASTODON_OTP_SECRET:
                    default: 0f97264373e19af4eca05a9fae6ea643b383e3307da72cc88855725b246603af8045ceaec99e5a660efb581c04796ea269748db61fd751a573a881dcc4879d45
                    expose: true
                MASTODON_REDIS_HOST:
                    default: ${REDIS_HOST}
                    expose: true
                MASTODON_REDIS_PASSWORD:
                    default: ${REDIS_PASSWORD}
                    expose: true
                MASTODON_REDIS_PORT_NUMBER:
                    default: ${REDIS_PORT_NUMBER}
                    expose: true
                MASTODON_SECRET_KEY_BASE:
                    default: b2db3ffdc5f70ac8498a39959448ec79409c6ec21cfdcc53cfdb998c751d52d85a9dd097bad2f9006e197ded2241d07731f5a1d455723eb11f3d5eedf39832a6
                    expose: true
                MASTODON_WEB_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                VAPID_PRIVATE_KEY:
                    default: kJgdSb2MOFpdmeMnA4CauLdU9DxLiTWgwLuxKHnsX1o
                    expose: true
                VAPID_PUBLIC_KEY:
                    default: BH_obf08KE24z1FqEllSwVXuKfdy5CR1WKWPuquL6PWqLuKWKffMFOm0vl_gX0eIASz76LRg3VN4B8p4AyFjCaQ
                    expose: true
        - name: Streaming
          icon: https://joinmastodon.org/logos/logo-purple.svg
          dependencies:
            - Redis
            - PostgreSQL
          template: PREBUILT
          spec:
            source:
                image: zeabur/bitnami-mastodon:4.4.3
            ports:
                - id: streaming
                  port: 4000
                  type: TCP
            volumes:
                - id: mastodon-data
                  dir: /bitnami/mastodon
            env:
                MASTODON_MODE:
                    default: streaming
                MASTODON_STREAMING_API_BASE_URL:
                    default: ws://${CONTAINER_HOSTNAME}
                    expose: true
        - name: Sidekiq
          icon: https://joinmastodon.org/logos/logo-purple.svg
          dependencies:
            - Redis
            - PostgreSQL
          template: PREBUILT
          spec:
            source:
                image: zeabur/bitnami-mastodon:4.4.3
            volumes:
                - id: mastodon-data
                  dir: /mastodon/public/system
            env:
                MASTODON_MODE:
                    default: sidekiq
