# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: PGBackWeb
spec:
    description: Effortless PostgreSQL backups with a user-friendly web interface!
    coverImage: https://raw.githubusercontent.com/eduardolat/pgbackweb/main/screenshots/summary.png
    icon: https://raw.githubusercontent.com/eduardolat/pgbackweb/main/internal/view/static/images/logo.png
    variables:
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: Domain
          description: The domain name of your PGBackWeb website.
    tags:
        - Tool
    readme: "PG Back Web isn't just another backup tool. It's your trusted ally in ensuring the security and availability of your PostgreSQL data:\n\n## Features\n\n- \U0001F4E6 Intuitive web interface: Manage your backups with ease, no database expertise required.\n- \U0001F4C5 Scheduled backups: Set it and forget it. PG Back Web takes care of the rest.\n- \U0001F4C8 Backup monitoring: Visualize the status of your backups with execution logs.\n- \U0001F4E4 Instant download & restore: Restore and download your backups when you need them, directly from the web interface.\n- \U0001F5A5 Multi-version support: Compatible with PostgreSQL 13, 14, 15, and 16.\n- \U0001F4C1 Local & S3 storage: Store backups locally or add as many S3 buckets as you want for greater flexibility.\n- \U0001F512 Security first: PGP encryption to protect your sensitive information.\n- \U0001F6E1️ Open-source trust: Open-source code under MIT license, backed by the robust pg_dump tool.\n- \U0001F31A Dark mode: Because we all love dark mode.\n\n## Usage\n\nThis is a one-click deployment template for PG Back Web. You can deploy it to a project that already has a [PostgreSQL](https://zeabur.com/templates/B20CX0) instance, or you can create a separate new project and connect it to your PostgreSQL instance using public networking.\n"
    services:
        - name: pbw-postgresql
          icon: https://cdn.zeabur.com/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            source:
                image: postgres:18
                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/18/docker
            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:
                PBW_POSTGRES_CONN_STRING:
                    default: postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}?sslmode=disable
                    expose: true
                PGDATA:
                    default: /var/lib/postgresql/18/docker/pgdata
                    expose: false
                POSTGRES_DATABASE:
                    default: ${POSTGRES_DB}
                    expose: false
                POSTGRES_DB:
                    default: pbw
                POSTGRES_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: false
                POSTGRES_PASSWORD:
                    default: ${PASSWORD}
                    expose: false
                POSTGRES_PORT:
                    default: ${DATABASE_PORT}
                    expose: false
                POSTGRES_USER:
                    default: root
                POSTGRES_USERNAME:
                    default: ${POSTGRES_USER}
                    expose: false
            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 = 256
                    shared_buffers = 256MB
                    dynamic_shared_memory_type = posix
                    max_wal_size = 1GB
                    min_wal_size = 80MB
                    log_timezone = 'UTC'
                    datestyle = 'iso, mdy'
                    timezone = 'UTC'
                    lc_messages = 'en_US.UTF-8'
                    lc_monetary = 'en_US.UTF-8'
                    lc_numeric = 'en_US.UTF-8'
                    lc_time = 'en_US.UTF-8'
                    default_text_search_config = 'pg_catalog.english'
                  permission: null
                  envsubst: null
        - name: pgbackweb
          icon: https://raw.githubusercontent.com/eduardolat/pgbackweb/main/internal/view/static/images/logo.png
          template: PREBUILT
          spec:
            source:
                image: eduardolat/pgbackweb:latest
            ports:
                - id: web
                  port: 8085
                  type: HTTP
            volumes:
                - id: data
                  dir: /root
            instructions:
                - title: Encryption Key
                  content: ${PBW_ENCRYPTION_KEY}
            env:
                PBW_ENCRYPTION_KEY:
                    default: ${PASSWORD}
          domainKey: PUBLIC_DOMAIN
