# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Ghost
spec:
    description: Independent technology for modern publishing.
    coverImage: https://user-images.githubusercontent.com/353959/169805900-66be5b89-0859-4816-8da9-528ed7534704.png
    icon: https://asset.brandfetch.io/idu2c8EUPA/idDlmNoqhC.png?updated=1709156005896
    variables:
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: Ghost's domain
          description: The domain name for your Ghost instance.
    tags:
        - Blog
        - CMS
        - Tool
    readme: |-
        # Ghost

        ## Introduction

        Ghost is a powerful app for professional publishers to create, share, and grow a business around their content. It comes with modern tools to build a website, publish content, send newsletters & offer paid subscriptions to members.

        **Publish by web & email newsletter.** An editor built from the ground-up for professionals. Calm by design, with advanced workflows by default. No more suffering through clumsy toolbars or drag & oops. Immerse yourself in the story with an interface that's invisible until you need it, and powerful when you do.

        **Rich media & dynamic cards.** Modern publishing requires more than just words. Expand your story with image galleries, gifs, video, audio, products, info boxes, accordion toggles, downloadable files, bookmarks, and so much more.

        **Newsletters built-in.** Deliver posts by email newsletter to your audience, so they'll be in the loop whenever something new goes live. Segment your audience and send multiple different newsletters based on preference.

        **Manage your memberships.** See who's signing up, who's paying, and what they're reading, so you can get a better understanding of your core audience.

        ## Usage

        1. Deploy this template, and this template will hint you to bind your domain.
        2. After starting the service, you can access the admin panel at `https://<your-domain>/ghost`.
        3. After setting up your Ghost instance, your audience can access your Ghost instance at `https://<your-domain>`.

        ## Configuration

        ### Updating the Ghost domain

        Run the following command in your Ghost service (for how to run commands, see [this documentation](https://zeabur.com/docs/deploy/command-execution)):

        ```bash
        ghost config url https://your-new-domain
        ```

        Then, restart your Ghost service.

        ### Setting up email

        To enable email functionality for member invitations and notifications, configure the mail environment variables in your Ghost service:

        1. Go to your Ghost service in Zeabur
        2. Navigate to **Variables**
        3. Add the following environment variables based on your email service provider:
           - `mail__transport`: Email service (e.g., `SMTP`, `Mailgun`, `SendGrid`)
           - `mail__options__service`: Service name (e.g., `Gmail`, `Mailgun`)
           - `mail__options__auth__user`: Your email username
           - `mail__options__auth__pass`: Your email password or API key
        4. For detailed mail configuration options, see [Ghost email configuration docs](https://docs.ghost.org/config#mail)

        ### Setting up newsletters

        To configure newsletter delivery:

        1. Access the admin panel at `https://<your-domain>/ghost`
        2. Navigate to **Settings** → **Email newsletter** → **Mailgun Settings**
        3. Configure your Mailgun settings:
           - **Mailgun region**: Select your region (US or EU)
           - **Mailgun domain**: Enter your Mailgun domain
           - **Mailgun private API key**: Enter your private API key
        4. Save the settings
        5. Learn more at [Ghost newsletters documentation](https://docs.ghost.org/newsletters#bulk-email-configuration)

        ### Forgot your password?

        If you forgot your Ghost admin password, you can reset it directly in the database:

        1. Go to your MySQL service and navigate to Database > zeabur database

        ![Ghost Forgot Password](https://cdn.zeabur.com/ghost-forgot-password.png)

        2. Click "Execute SQL Command" and run the following command:

        ```sql
        UPDATE zeabur.users SET password='\$2a\$12\$1hiHKBSMnfHOjS0BQ227sO38Y9JpxnNMKutH573F8zMvkRljPFyGe' WHERE email = 'your-email@example.com';
        ```

        Replace `your-email@example.com` with the email address you use to log in. The password will be reset to `password123`.

        If you want to use a different password, you can generate a bcrypt hash using this tool: [Bcrypt Generator](https://bcrypt-generator.com/).
    services:
        - name: mysql
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/mysql.svg
          template: PREBUILT
          spec:
            source:
                image: mysql:8.0
            ports:
                - id: database
                  port: 3306
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/mysql
            instructions:
                - title: Command to connect to your MySQL
                  content: mysqlsh --sql --host=${CONTAINER_HOSTNAME} --port=${MYSQL_PORT} --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} --schema=${MYSQL_DATABASE}
                - title: MySQL username
                  content: ${MYSQL_USER}
                - title: MySQL password
                  content: ${MYSQL_PASSWORD}
                - title: MySQL database
                  content: ${MYSQL_DATABASE}
                - title: MySQL host
                  content: ${CONTAINER_HOSTNAME}
                - title: MySQL port
                  content: ${MYSQL_PORT}
            env:
                MYSQL_DATABASE:
                    default: zeabur
                    expose: true
                MYSQL_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                MYSQL_PASSWORD:
                    default: ${MYSQL_ROOT_PASSWORD}
                    expose: true
                MYSQL_PORT:
                    default: "3306"
                    expose: true
                MYSQL_ROOT_PASSWORD:
                    default: ${PASSWORD}
                MYSQL_USER:
                    default: mysql
                    expose: true
            configs:
                - path: /etc/my.cnf
                  template: |-
                    [mysqld]
                    host-cache-size=0
                    skip-name-resolve
                    datadir=/var/lib/mysql
                    socket=/var/lib/mysql/mysqld.sock
                    secure-file-priv=/var/lib/mysql-files
                    user=mysql
                    max_allowed_packet=10M
                    performance_schema=off
                    pid-file=/var/lib/mysql/mysqld.pid

                    [client]
                    socket=/var/run/mysqld/mysqld.sock

                    !includedir /etc/mysql/conf.d/
                  permission: null
                  envsubst: null
        - name: ghost
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/ghost.svg
          template: PREBUILT
          spec:
            source:
                image: ghost:6.7.0-alpine3.22
            ports:
                - id: web
                  port: 2368
                  type: HTTP
            volumes:
                - id: data
                  dir: /var/lib/ghost/content
            env:
                database__client:
                    default: mysql
                database__connection__database:
                    default: ${MYSQL_DATABASE}
                database__connection__host:
                    default: ${MYSQL_HOST}
                database__connection__password:
                    default: ${MYSQL_PASSWORD}
                database__connection__port:
                    default: ${MYSQL_PORT}
                database__connection__user:
                    default: ${MYSQL_USER}
                mail__options__auth__pass:
                    default: ""
                mail__options__auth__user:
                    default: ""
                mail__options__service:
                    default: ""
                mail__transport:
                    default: Direct
                url:
                    default: https://${ZEABUR_WEB_DOMAIN}
            configs:
                - path: /usr/local/bin/docker-entrypoint.sh
                  template: "#!/bin/bash\nset -e\n\n# remind users to bind domain\nif [[ \"$url\" == \"\" ]]; then\n    echo \"⚠️ Please bind your domain in Zeabur first.\"\n    echo \"⚠️ 请先在 Zeabur 绑定您的域名。\"\n    echo \"\U0001F449 https://zeabur.com/docs/networking/public\"\n    exit 1\nfi\n\n# allow the container to be started with `--user`\nif [[ \"$*\" == node*current/index.js* ]] && [ \"$(id -u)\" = '0' ]; then\n    find \"$GHOST_CONTENT\" \\! -user node -exec chown node '{}' +\n    exec gosu node \"$BASH_SOURCE\" \"$@\"\nfi\n\nif [[ \"$*\" == node*current/index.js* ]]; then\n    baseDir=\"$GHOST_INSTALL/content.orig\"\n    for src in \"$baseDir\"/*/ \"$baseDir\"/themes/*; do\n        src=\"${src%/}\"\n        target=\"$GHOST_CONTENT/${src#$baseDir/}\"\n        mkdir -p \"$(dirname \"$target\")\"\n        if [ ! -e \"$target\" ]; then\n            tar -cC \"$(dirname \"$src\")\" \"$(basename \"$src\")\" | tar -xC \"$(dirname \"$target\")\"\n        fi\n    done\nfi\n\nexec \"$@\"\n"
                  permission: 493
                  envsubst: null
          domainKey: PUBLIC_DOMAIN
