captainVersion: 4

services:
    $$cap_appname-mariadb:
        image: mariadb:$$cap_mariadb_version
        environment:
            MYSQL_RANDOM_ROOT_PASSWORD: '1'
            MYSQL_DATABASE: $$cap_mariadb_db
            MYSQL_USER: $$cap_mariadb_user
            MYSQL_PASSWORD: $$cap_mariadb_pass
        volumes:
            - $$cap_appname-mariadb-data:/var/lib/mysql
        caproverExtra:
            notExposeAsWebApp: 'true'

    $$cap_appname:
        image: viktorstrate/photoview:$$cap_photoview_version
        depends_on:
            - $$cap_appname-mariadb
        environment:
            PHOTOVIEW_DATABASE_DRIVER: mysql
            PHOTOVIEW_MYSQL_URL: $$cap_mariadb_user:$$cap_mariadb_pass@tcp(srv-captain--$$cap_appname-mariadb)/$$cap_mariadb_db
            PHOTOVIEW_LISTEN_IP: 0.0.0.0
            PHOTOVIEW_LISTEN_PORT: 80
            PHOTOVIEW_MEDIA_CACHE: /app/cache
            MAPBOX_TOKEN: $$cap_mapbox_token
        volumes:
            - $$cap_appname-media-cache:/app/cache
            - $$cap_photos_path:/photos

caproverOneClickApp:
    displayName: Photoview
    isOfficial: true
    description: Photo gallery for self-hosted personal servers.
    documentation: Taken from https://github.com/photoview/photoview/blob/master/docker-compose.example.yml.
    instructions:
        start: >-
            Photoview is a simple and user-friendly photo gallery that's made for photographers and aims to provide an easy and fast way to navigate directories, with thousands of high-resolution photos.


            You configure Photoview to look for photos and videos within a directory on your file system.
            The scanner automatically picks up your media and start to generate thumbnail images to make browsing super fast.


            When your media has been scanned they show up on the website, organised in the same way as on the filesystem.
        end: >-
            Photoview has successfully deployed.

            Finish the setup at http://$$cap_appname.$$cap_root_domain.

    variables:
        - id: $$cap_photoview_version
          label: Photoview Version
          defaultValue: '2.3.9'
          description: Check out their docker page for the valid tags https://hub.docker.com/r/viktorstrate/photoview/tags
          validRegex: /^([^\s^\/])+$/

        - id: $$cap_photos_path
          label: Location of your photos
          description: Change this to the directory where your photos are located on your server.
          validRegex: /\/[^\s-][a-zA-Z0-9_\/-]*[^\/][^\s-]/

        - id: $$cap_mapbox_token
          label: Mapbox Token (Optional)
          description: |-
              To enable map related features, you need to create a mapbox token.

              A token can be generated for free here https://account.mapbox.com/access-tokens/

              It's a good idea to limit the scope of the token to your own domain, to prevent others from using it.

              Leave empty to disable map related features.

        - id: $$cap_mariadb_version
          label: MariaDB Version
          defaultValue: '10.5'
          description: Check out their docker page for the valid tags https://hub.docker.com/r/library/mariadb/tags
          validRegex: /^([^\s^\/])+$/

        - id: $$cap_mariadb_db
          label: MariaDB Database
          description: Name of the Database used by Photoview
          defaultValue: 'photoview'

        - id: $$cap_mariadb_user
          label: MariaDB Username
          description: Username for the Database used by Photoview
          defaultValue: 'photoview'

        - id: $$cap_mariadb_pass
          label: MariaDB Password
          description: Password for the Database used by Photoview
          defaultValue: $$cap_gen_random_hex(16)
