Soft Serve

repository·main·Indexed 27 days ago

https://github.com/charmbracelet/soft-serve

A self-hostable Git server designed for the command line, featuring a TUI accessible over SSH and support for Git LFS. It supports SQLite and Postgres backends, provides administrative tools for user and repository management, and allows for the configuration of both per-repository and global Git server-side hooks.

Tokens
11.3K
Snippets
19
Records
106
Agent score
92%

What's inside soft-serve

  1. Enable and start Soft Serve via Systemd

    main

    After creating your service file, use the following commands to reload the daemon, enable the service to start on boot, and start the service immediately.

    # Reload systemd daemon
    sudo systemctl daemon-reload
    
    # Enable Soft Serve to start on-boot
    sudo systemctl enable soft-serve.service
    
    # Start Soft Serve now!!
    sudo systemctl start soft-serve.service
  2. Create and manage user access tokens for HTTP

    main

    Since Soft Serve uses SSH for authentication, you can generate access tokens to use as basic auth credentials for HTTP(s) or git:// connections. Use the token as the username in the URL.

    Commands:

    • token create '<name>': Create a token.
    • token create --expires-in <duration> '<name>': Create a token with an expiration (e.g., 1y).
  3. Configure SSH for Soft Serve access

    main

    To avoid specifying the hostname, port, and identity file for every command, add an entry to your ~/.ssh/config file. This also allows git to use the shorthand hostname for cloning and pushing.

    Example configuration for a local instance:

    Host soft
      HostName localhost
      Port 23231
      IdentityFile ~/.ssh/id_ed25519
      IdentitiesOnly yes
  4. Access the Soft Serve TUI via SSH

    main

    You can browse repositories using the Soft Serve TUI over SSH. To connect to a local instance, use the following command:

    ssh localhost -p 23231

    To link directly to a specific repository within the TUI, use the -t flag:

    ssh -p 23231 localhost -t soft-serve

    Note: Copying text (like clone commands) to your clipboard over SSH requires a terminal that supports OSC52.

    ssh localhost -p 23231
  5. Create a custom Systemd service file for Soft Serve

    main

    To run Soft Serve manually via Systemd, create a service file at /etc/systemd/system/soft-serve.service.

    Note that the following example assumes running as root. Ensure ExecStart points to your soft-serve binary location and SOFT_SERVE_DATA_PATH is correctly set.

    [Unit]
    Description=Soft Serve git server 🍦
    Documentation=https://github.com/charmbracelet/soft-serve
    Requires=network-online.target
    After=network-online.target
    
    [Service]
    Type=simple
    Restart=always
    RestartSec=1
    ExecStart=/usr/bin/soft serve
    Environment=SOFT_SERVE_DATA_PATH=/var/local/lib/soft-serve
    EnvironmentFile=-/etc/soft-serve.conf
    WorkingDirectory=/var/local/lib/soft-serve
    
    [Install]
    WantedBy=multi-user.target
  6. Print repository files with syntax highlighting

    main

    You can view the contents of a specific file within a repository using the repo blob command.

    Options:

    • -c: Enable syntax coloring.
    • -l: Print line numbers.
    • --raw: Print raw file contents (useful for binary data).
  7. Install Soft Serve

    main

    Soft Serve is a single binary called soft. You can install it using various package managers depending on your operating system:

    • macOS or Linux: Use Homebrew.
    • Windows: Use Winget.
    • Arch Linux: Use pacman.
    • Nix: Use nix-env.
    • Debian/Ubuntu: Use the Charm APT repository.
    • Fedora/RHEL: Use the Charm Yum repository.
    • Go: Use go install.
    • Docker: A Docker image is available.
    # macOS or Linux
    brew install charmbracelet/tap/soft-serve
    
    # Windows (with Winget)
    winget install charmbracelet.soft-serve
    
    # Arch Linux
    pacman -S soft-serve
    
    # Nix
    nix-env -iA nixpkgs.soft-serve
    
    # Debian/Ubuntu
    sudo mkdir -p /etc/apt/keyrings
    curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
    echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
    sudo apt update && sudo apt install soft-serve
    
    # Fedora/RHEL
    echo '[charm]
    name=Charm
    baseurl=https://repo.charm.sh/yum/
    enabled=1
    gpgcheck=1
    gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/yum.repos.d/charm.repo
    sudo yum install soft-serve
    
    # Go
    go install github.com/charmbracelet/soft-serve/cmd/soft@latest
  8. Run Soft Serve as a Systemd Service

    main

    If you are not using the pre-packaged deb/rpm versions, you can manage Soft Serve as a Systemd service.

    1. Prepare the data directory: Create the directory where Soft Serve will store its data (e.g., /var/local/lib/soft-serve).
    2. Configure environment variables: Use the SOFT_SERVE_DATA_PATH environment variable to point to your data directory.
    3. Create a configuration file: You can use an environment file (e.g., /etc/soft-serve.conf) to override settings. Settings defined in this file will override the config.yaml located in the data path. Specifically, keys defined in SOFT_SERVE_INITIAL_ADMIN_KEYS will be merged with the initial_admin_keys from the data path's config.yaml.
  9. Browse and interact with Soft Serve via SSH

    main

    You can interact with a Soft Serve instance using standard SSH commands to browse repositories, view directory trees, or print file contents.

    • TUI: Jump directly into the interactive TUI.
    • Directory Tree: Print a directory tree for a specific repository.
    • Blob/File: Print a specific file. Use -c for syntax highlighting and -l for line numbers.
    # Jump directly to a repo in the TUI
    ssh git.charm.sh -t soft-serve
    
    # Print out a directory tree for a repo
    ssh git.charm.sh repo tree soft-serve
    
    # Print a specific file
    ssh git.charm.sh repo blob soft-serve cmd/soft/main.go
    
    # Print a file with syntax highlighting and line numbers
    ssh git.charm.sh repo blob soft-serve cmd/soft/main.go -c -l
  10. Set up a Soft Serve server

    main

    To start a Soft Serve server, ensure git is installed and run the command soft serve.

    By default, a data directory is created to store repositories, SSH keys, and the database.

    Initial Admin Setup

    When running the server for the first time, you must set the SOFT_SERVE_INITIAL_ADMIN_KEYS environment variable to your SSH authorized public key. This creates an admin user with full privileges.

    Customizing Data and Config Paths

    • To change the default data path, use the SOFT_SERVE_DATA_PATH environment variable.
    • To override the program configuration location, use SOFT_SERVE_CONFIG_LOCATION (the file must be pre-created).
  11. Configure Soft Serve Git Hooks

    main

    Soft Serve supports standard Git server-side hooks: pre-receive, update, post-update, and post-receive. You can define hooks at two levels:

    1. Per-repository hooks: Place executable hook files in the repository's hooks directory.
    2. Global hooks: Place executable hook files in the hooks directory located under your SOFT_SERVE_DATA_PATH. Global hooks run for all repositories and are useful for tasks like CI/CD.

    Example update hook script:

    #!/bin/sh
    #
    # An example hook script to echo information about the push
    # and send it to the client.
    
    refname="$1"
    oldrev="$2"
    newrev="$3"
    
    # Safety check
    if [ -z "$GIT_DIR" ]; then
            echo "Don't run this script from the command line." >&2
            echo " (if you want, you can supply GIT_DIR then run" >&2
            echo "  $0 <ref> <oldrev> <newrev>)" >&2
            exit 1
    fi
    
    if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
            echo "usage: $0 <ref> <oldrev> <newrev>" >&2
            exit 1
    fi
    
    # Check types
    # if $newrev is 0000...0000, it's a commit to delete a ref.
    zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
    if [ "$newrev" = "$zero" ]; then
            newrev_type=delete
    else
            newrev_type=$(git cat-file -t $newrev)
    fi
    
    echo "Hi from Soft Serve update hook!"
    echo
    echo "RefName: $refname"
    echo "Change Type: $newrev_type"
    echo "Old SHA1: $oldrev"
    echo "New SHA1: $newrev"
    
    exit 0
  12. Configure the Soft Serve database

    main

    Soft Serve supports SQLite (default) and Postgres. Configuration can be done via config.yaml or environment variables.

    Using Postgres

    1. Create a database in Postgres: psql -h<hostname> -p<port> -U<user> -c 'CREATE DATABASE soft_serve'
    2. Set the db.driver to postgres and provide the db.data_source connection string.

    You can include a password directly in the connection string: postgres://myuser:dbpass@localhost:5432/my_soft_serve_db.

    # config.yaml example for Postgres
    db:
      driver: "postgres"
      data_source: "postgres://postgres@localhost:5432/soft_serve?sslmode=disable"
    # Using environment variables for Postgres
    SOFT_SERVE_DB_DRIVER=postgres \
    SOFT_SERVE_DB_DATA_SOURCE="postgres://postgres@localhost:5432/soft_serve?sslmode=disable" \
    soft serve