type: docker-compose
files:
  docker-compose.yml:
    content: |

      services:
        peertube:
          image: chocobozzz/peertube:production-bookworm
          networks:
            default:
              ipv4_address: 172.11.0.42
          ports:
           - "1935:1935"
           - "9000:9000"
          volumes:
            - assets:/app/client/dist
            - ./docker-volume/data:/data
            - ./docker-volume/config:/config
          depends_on:
            - postgres
            - redis
          restart: "always"

        postgres:
          image: postgres:13-alpine
          volumes:
            - ./docker-volume/db:/var/lib/postgresql/data
          restart: "always"

        redis:
          image: redis:6-alpine
          volumes:
            - ./docker-volume/redis:/data
          restart: "always"

      networks:
        default:
          ipam:
            driver: default
            config:
            - subnet: 172.11.0.0/16

      volumes:
        assets:

override:
  services:
    peertube:
      environment:
        PEERTUBE_DB_USERNAME: &db_username "peertube"
        PEERTUBE_DB_PASSWORD: &db_password !libervia_generate_pwd {name: db}
        PEERTUBE_DB_SSL: "false"
        PEERTUBE_DB_HOSTNAME: "postgres"
        PEERTUBE_WEBSERVER_HOSTNAME: !libervia_conf ["application peertube", "hostname"]
        PEERTUBE_TRUST_PROXY: '["127.0.0.1", "loopback", "172.18.0.0/16"]'
        PEERTUBE_SECRET: !libervia_generate_pwd {name: secret}
        PEERTUBE_SMTP_HOSTNAME: !libervia_conf ["", "email_server"]
        PEERTUBE_SMTP_USERNAME: !libervia_conf ["", "email_username"]
        PEERTUBE_SMTP_PASSWORD: !libervia_conf ["", "email_password"]
        PEERTUBE_SMTP_DISABLE_STARTTLS: !libervia_conf ["", "email_starttls", "false", "not"]
        PEERTUBE_SMTP_PORT: !libervia_conf ["", "email_port"]
        PEERTUBE_SMTP_FROM: !libervia_conf ["application peertube", "email_from", "peertube@example.com"]
        PEERTUBE_SMTP_TLS: "false"
        PEERTUBE_ADMIN_EMAIL: !libervia_conf ["", "email_admins_list", "", "first"]
        PEERTUBE_OBJECT_STORAGE_UPLOAD_ACL_PUBLIC: "public-read"
        PEERTUBE_OBJECT_STORAGE_UPLOAD_ACL_PRIVATE: "private"

      ports:
        # FIXME: For now we use a static ports, but dynamic ones should be used.
        - "1935:1935"
        - "9000:9000"
      volumes:
        - ./docker-volume/data:/data
        - ./docker-volume/config:/config
    postgres:
      environment:
        POSTGRES_USER: *db_username
        POSTGRES_PASSWORD: *db_password
        POSTGRES_DB: "peertube"

expose:
  web_external: true
  front_url: [override, services, peertube, environment, PEERTUBE_WEBSERVER_HOSTNAME]
  web_label: Videos
  ports:
    web:
      service: peertube
      private: 9000
  passwords:
    postgres: [override, services, peertube, environment, PEERTUBE_DB_PASSWORD]
    secret: [override, services, peertube, environment, PEERTUBE_SECRET]

