mermaid.ink

repository·main·Indexed 42 days ago

https://github.com/jihchi/mermaid.ink

A service that transforms Mermaid diagram syntax into images using a headless browser. Version 16.0.0 supports local installation via pnpm, deployment via Docker, and configuration through environment variables for scaling, timeouts, and PostgreSQL database caching.

Tokens
948
Snippets
4
Records
5
Agent score
4%

What's inside mermaid.ink

  1. Install and run mermaid.ink locally

    main

    To run the project from source, clone the repository, install dependencies using pnpm, and start the application. You can use the DEBUG=app:* environment variable to enable debugging for the app namespace.

    git clone https://github.com/jihchi/mermaid.ink.git
    cd mermaid.ink
    pnpm install
    DEBUG=app:* pnpm start
  2. Launch mermaid.ink via Docker

    main

    You can run mermaid.ink using a Docker container. The default command requires --cap-add=SYS_ADMIN to function, but this is generally not recommended for security reasons.

    Secure alternatives

    1. Using a custom seccomp profile Instead of using SYS_ADMIN, you can use Jessie Frazelle's seccomp profile for Chrome:

    wget https://raw.githubusercontent.com/jfrazelle/dotfiles/master/etc/docker/seccomp/chrome.json
    docker run --security-opt seccomp=$(pwd)/chrome.json ghcr.io/jihchi/mermaid.ink

    2. Running without a seccomp profile If you encounter core dump errors during startup, you can run the container without a seccomp profile:

    docker run --security-opt seccomp=unconfined ghcr.io/jihchi/mermaid.ink

    3. Default (Not recommended)

    docker run --cap-add=SYS_ADMIN -p 3000:3000 ghcr.io/jihchi/mermaid.ink
  3. Configure mermaid.ink via environment variables

    main

    The following environment variables can be used to configure the behavior of the mermaid.ink service:

    variable namedefault valuedescription
    MAX_WIDTH10000Maximum scaled diagram width allowed.
    MAX_HEIGHT10000Maximum scaled diagram height allowed.
    FONT_AWESOME_CSS_URL<unset>Custom URL for injected Font-Awesome CSS. Use FA_VERSION as a placeholder for the version (e.g., https://.../FA_VERSION/css/all.min.css).
    PROTOCOL_TIMEOUT180000Timeout for individual CDP (Chrome DevTools Protocol) calls.
    HEADLESS_MODE'true'Browser mode: 'true' (new headless), 'shell' (old headless/chrome-headless-shell).
    QUEUE_CONCURRENCY1Maximum number of concurrent rendering jobs.
    QUEUE_ADD_TIMEOUT3000Timeout in milliseconds for a rendering job.
    ENABLE_DATABASE<unset>Set to 'true' to enable PostgreSQL database caching.
    PGHOST<unset>PostgreSQL server hostname.
    PGPORT<unset>PostgreSQL server port.
    PGDATABASE<unset>PostgreSQL database name.
    PGUSERNAME<unset>PostgreSQL username.
    PGPASSWORD<unset>PostgreSQL password
  4. Start the mermaid.ink server

    main

    The mermaid.ink server is bootstrapped by initializing a Koa application that includes a Puppeteer browser instance, a job queue, and an optional database connection. By default, the server listens on port 3000, but this can be configured using the PORT environment variable.

    # Run with default port 3000
    node src/index.js
    
    # Run on a custom port
    PORT=8080 node src/index.js
  5. Fix HTTP 431 Request Header Fields Too Large error

    main

    If you encounter the HTTP 431 Request Header Fields Too Large error, you must increase the --max-http-header-size limit.

    Warning: Increasing this limit may expose the service to Denial of Service (DoS) attacks.

    Local execution

    Set the NODE_OPTIONS environment variable:

    NODE_OPTIONS="--max-http-header-size=102400000" npm start

    Docker execution

    Pass the NODE_OPTIONS via the -e flag:

    docker run --rm -it -e 'NODE_OPTIONS="--max-http-header-size=102400000"' -p 3000:3000 ghcr.io/jihchi/mermaid.ink