### Install and Start Soft Serve Server Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/README.md Installs the Soft Serve binary and starts the server with an initial admin key. Ensure your public SSH key is in `~/.ssh/id_ed25519.pub`. ```bash # Install Soft Serve go install github.com/charmbracelet/soft-serve/cmd/soft@latest # Start server SOFT_SERVE_INITIAL_ADMIN_KEYS="$(cat ~/.ssh/id_ed25519.pub)" soft serve # Access via SSH ssh localhost -p 23231 ``` -------------------------------- ### Install Soft Serve with Go Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Install the Soft Serve command-line tool directly using Go. ```bash go install github.com/charmbracelet/soft-serve/cmd/soft@latest ``` -------------------------------- ### Install Soft Serve with Nix Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Install Soft Serve using Nix package manager. ```bash # Nix nix-env -iA nixpkgs.soft-serve ``` -------------------------------- ### Install Soft Serve with Winget Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Install Soft Serve on Windows using the Winget package manager. ```bash # Windows (with Winget) winget install charmbracelet.soft-serve ``` -------------------------------- ### Example Soft Serve YAML Configuration Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/config.md A comprehensive example of a `config.yaml` file, demonstrating various settings for SSH, HTTP, database, logging, and more. ```yaml name: "My Git Server" ssh: enabled: true listen_addr: ":2222" public_url: "ssh://git.example.com:2222" key_path: "ssh/host_key" client_key_path: "ssh/client_key" idle_timeout: 300 git: enabled: true listen_addr: ":9418" public_url: "git://git.example.com" max_connections: 32 http: enabled: true listen_addr: ":443" public_url: "https://git.example.com" tls_key_path: "tls/key.pem" tls_cert_path: "tls/cert.pem" cors: allowed_origins: - "https://git.example.com" db: driver: "postgres" data_source: "postgres://user:pass@localhost/soft_serve" log: format: "json" path: "/var/log/soft-serve/server.log" lfs: enabled: true ssh_enabled: false jobs: mirror_pull: "@every 1h" initial_admin_keys: - "ssh-ed25519 AAAAC3Nza..." ``` -------------------------------- ### Example Response for Pack Files Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md This is an example of the response format when requesting a list of pack files. ```text P pack-1234567890abcdef.pack ``` -------------------------------- ### PostgreSQL Connection String Examples Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/db.md Examples of valid PostgreSQL connection strings for different configurations, including host, port, and SSL mode. ```text postgres://user:pass@localhost/dbname postgresql://user:pass@localhost:5432/dbname?sslmode=disable postgres://user@socket:5433/dbname ``` -------------------------------- ### Install Soft Serve with Homebrew Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Install Soft Serve on macOS or Linux using the Homebrew package manager. ```bash # macOS or Linux brew install charmbracelet/tap/soft-serve ``` -------------------------------- ### Install Soft Serve on Debian/Ubuntu Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Install Soft Serve on Debian or Ubuntu systems using the Charm APT repository. ```bash # 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 ``` -------------------------------- ### Install Soft Serve with Pacman Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Install Soft Serve on Arch Linux using the Pacman package manager. ```bash # Arch Linux pacman -S soft-serve ``` -------------------------------- ### Create Repository with Options Example Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/types.md Demonstrates creating a new repository with specified options, such as setting it as private and providing a description. ```go opts := proto.RepositoryOptions{ Private: true, Description: "Internal project", ProjectName: "Acme Project", Hidden: false, } repo, _ := backend.CreateRepository(ctx, "acme", user, opts) ``` -------------------------------- ### Install Soft Serve on Fedora/RHEL Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Install Soft Serve on Fedora or RHEL systems by configuring the Charm YUM repository. ```bash # 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 ``` -------------------------------- ### Enable and Start Service Source: https://github.com/charmbracelet/soft-serve/blob/main/systemd.md Commands to reload the daemon and activate the Soft Serve service. ```sh # 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 ``` -------------------------------- ### Create User with Options Example Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/types.md Demonstrates how to create a new user with specific options, such as setting admin privileges and providing initial public keys. ```go opts := proto.UserOptions{ Admin: true, PublicKeys: []ssh.PublicKey{key1, key2}, } user, _ := backend.CreateUser(ctx, "alice", opts) ``` -------------------------------- ### GET /{repo}/objects/info/alternates Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Get the alternates configuration file for a repository. Requires authentication. ```APIDOC ## GET /{repo}/objects/info/alternates ### Description Get alternates configuration file. ### Method GET ### Endpoint /{repo}/objects/info/alternates #### Path Parameters - **repo** (string) - Required - The name of the repository. #### Response File content (text) ### Status Codes - `200 OK` - Alternates file returned - `404 Not Found` - File not found ``` -------------------------------- ### SQLite Configuration Example Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/db.md Example configuration for using SQLite as the database driver. The `data_source` specifies the path to the database file. SQLite is suitable for single-server deployments due to its file-based nature. ```yaml db: driver: "sqlite" data_source: "soft-serve.db" ``` -------------------------------- ### Soft Serve Git Server-Side Hook Example Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md An example of a 'pre-receive' hook script for Soft Serve. This script echoes information about a push event to the client. ```sh #!/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 could supply GIT_DIR then run" >&2 echo " $0 )" >&2 exit 1 fi if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then echo "usage: $0 " >&2 exit 1 fi # Check types # if $newrev is 0000...0000, it's a commit to delete a ref. zero=$(git hash-object --stdin -p -U -c 'CREATE DATABASE soft_serve' ``` -------------------------------- ### Get Repository by Name Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Retrieves a specific repository by its name. Returns an error if the repository does not exist. ```Go repo, err := backend.Repository(ctx, "myrepo") ``` -------------------------------- ### Setup Repository Webhook Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/README.md Configures a webhook for a repository to receive specific event notifications. Supports JSON content type and custom secrets. ```go backend.CreateWebhook(ctx, repo, "https://ci.example.com/webhook", webhook.ContentTypeJSON, "secret123", []webhook.Event{webhook.EventPush}, true) ``` -------------------------------- ### GET /readyz Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Readiness check endpoint. Returns 200 if the server is ready to serve requests. Verifies database connectivity and determines if traffic should be routed to this instance. ```APIDOC ## GET /readyz ### Description Readiness check endpoint. Returns 200 if the server is ready to serve requests. ### Method GET ### Endpoint /readyz ### Description Verifies database connectivity. Used to determine if traffic should be routed to this instance. ``` -------------------------------- ### Get Repository Description Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Retrieves the description string for a given repository. Ensure the repository name is valid. ```go func (d *Backend) Description(ctx context.Context, name string) (string, error) ``` -------------------------------- ### Backend API: Repository Operations Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/README.md Go code examples for creating, looking up, modifying metadata, and managing collaborators for repositories via the Soft Serve backend API. ```go // Create repository repo, _ := backend.CreateRepository(ctx, "myrepo", user, opts) // Lookup repo, _ := backend.Repository(ctx, "myrepo") repos, _ := backend.Repositories(ctx) // Modify metadata backend.SetDescription(ctx, "myrepo", "A cool project") backend.SetProjectName(ctx, "myrepo", "My Project") backend.SetPrivate(ctx, "myrepo", true) // Manage collaborators backend.AddCollaborator(ctx, "alice", "myrepo", access.ReadWriteAccess) collabs, _ := backend.Collaborators(ctx, "myrepo") ``` -------------------------------- ### Backend API: User Operations Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/README.md Go code examples for creating, looking up, and managing SSH keys and access tokens for users via the Soft Serve backend API. ```go // Create user user, _ := backend.CreateUser(ctx, "alice", opts) // Lookup user user, _ := backend.User(ctx, "alice") user, _ := backend.UserByID(ctx, 123) user, _ := backend.UserByPublicKey(ctx, key) // Manage keys backend.AddPublicKey(ctx, "alice", key) backend.RemovePublicKey(ctx, "alice", key) // Manage tokens token, _ := backend.CreateAccessToken(ctx, user, "CI", expiry) backend.DeleteAccessToken(ctx, user, tokenID) ``` -------------------------------- ### Get Configuration as Environment Variables Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/config.md Retrieves the current server configuration as an array of environment variable strings in the format "KEY=VALUE". Useful for passing configuration to child processes. ```go cfg, _ := config.Load("config.yaml") envs := cfg.Environ() for _, env := range envs { fmt.Println(env) } ``` -------------------------------- ### Manage Repository Webhooks Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Soft Serve supports repository webhooks via the 'repo webhook' command. This example shows the usage for managing webhooks. ```sh Manage repository webhooks Usage: ssh -p 23231 localhost repo webhook [command] Aliases: webhook, webhooks Available Commands: create Create a repository webhook delete Delete a repository webhook deliveries Manage webhook deliveries list List repository webhooks update Update a repository webhook Flags: -h, --help help for webhook ``` -------------------------------- ### Database Readiness Health Check Endpoint Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/db.md Implement a GET /readyz endpoint that checks database connectivity using PingContext. It returns a 200 OK if the database is ready, or 503 Service Unavailable otherwise. ```go // GET /readyz func getReadiness(w http.ResponseWriter, r *http.Request) { ctx := r.Context() database := db.FromContext(ctx) if err := database.PingContext(ctx); err != nil { w.WriteHeader(http.StatusServiceUnavailable) return } w.WriteHeader(http.StatusOK) } ``` -------------------------------- ### Load Configuration with Environment Variable Overrides Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/config.md Loads the Soft Serve configuration, allowing environment variables to override settings defined in a configuration file. Example shows setting SSH listen address and HTTP public URL. ```go // Set config via environment variables os.Setenv("SOFT_SERVE_SSH_LISTEN_ADDR", ":2222") os.Setenv("SOFT_SERVE_HTTP_PUBLIC_URL", "https://git.example.com") // Load with env overrides cfg, _ := config.Load("config.yaml") ``` -------------------------------- ### GET /{repo}/HEAD Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Get the HEAD reference (current branch) for a repository. Requires authentication. ```APIDOC ## GET /{repo}/HEAD ### Description Get the HEAD reference (current branch). ### Method GET ### Endpoint /{repo}/HEAD #### Path Parameters - **repo** (string) - Required - The name of the repository. #### Response File content (text, typically "ref: refs/heads/main") ### Status Codes - `200 OK` - HEAD reference returned - `404 Not Found` - File not found ``` -------------------------------- ### Create New Backend Instance Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Instantiates a new Soft Serve backend. Requires context, configuration, database connection, and a storage backend. ```Go b := backend.New(ctx, cfg, db, st) ``` -------------------------------- ### GET /{repo}/objects/info/http-alternates Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Retrieves the HTTP alternates configuration file for a repository. This file specifies alternative locations for accessing repository objects. ```APIDOC ## GET /{repo}/objects/info/http-alternates ### Description Get HTTP alternates configuration file. ### Method GET ### Endpoint `/{repo}/objects/info/http-alternates` ### Auth Required Yes ### Response File content (text) ### Status Codes - `200 OK` - File returned - `404 Not Found` - File not found ``` -------------------------------- ### GET /{repo}/info/refs Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Git smart HTTP reference discovery endpoint. First step of smart HTTP git protocol. Advertises available services and refs. Requires authentication. ```APIDOC ## GET /{repo}/info/refs ### Description Git smart HTTP reference discovery endpoint. ### Method GET ### Endpoint /{repo}/info/refs #### Path Parameters - **repo** (string) - Required - The name of the repository. #### Query Parameters - **service** (string) - Required - Git service type: `git-upload-pack` or `git-receive-pack` #### Response Headers - `Content-Type: application/x-git--advertisement` #### Response Body Git service advertisement (text format) ### Example Request ``` GET /myrepo/info/refs?service=git-upload-pack HTTP/1.1 Host: example.com ``` ### Example Response ``` 001e# service=git-upload-pack 0000 001ebd35fda8397c1e4b4e2d9c5f3a1b8c7d6e5f4 HEAD ``` ### Description First step of smart HTTP git protocol. Advertises available services and refs. ``` -------------------------------- ### Initialize Database Connection in Go Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/db.md Set up a new database connection using configuration, specifying the driver and data source path. This function returns a DB instance or an error. ```go func setupDatabase(dataPath string) (*db.DB, error) { cfg := &config.Config{ DB: config.DBConfig{ Driver: "sqlite", DataSource: filepath.Join(dataPath, "soft-serve.db"), }, DataPath: dataPath, } ctx := context.Background() return db.New(ctx, cfg) } ``` -------------------------------- ### Create a New Repository Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Use the `repo create` command to initialize a new repository on your Soft Serve instance. Ensure you are a registered user and have collaborator access if required. ```sh ssh -p 23231 localhost repo create icecream ``` -------------------------------- ### Health Check: Readiness Endpoint Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Use the GET /readyz endpoint to check if the Soft Serve server is ready to serve requests, including verifying database connectivity. It returns 200 OK if ready, or 503 Service Unavailable if not. ```http HTTP/1.1 200 OK ``` ```http HTTP/1.1 503 Service Unavailable ``` -------------------------------- ### Initialize a New Git Repository Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/git.md Initializes a new Git repository at the specified path. Use `bare: true` to create a bare repository without a working directory. ```go repo, err := git.Init("./myrepo.git", true) if err != nil { log.Fatal(err) } ``` -------------------------------- ### WWW-Authenticate Header Example Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Example of the WWW-Authenticate header returned with a 401 Unauthorized response, specifying authentication scheme and realm. ```http Basic realm="Git" charset="UTF-8", Token, Bearer ``` -------------------------------- ### Go Get Meta Tag Endpoint Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Provides meta tags for `go get` command support, enabling Go packages to be cloned directly. ```APIDOC ## GET /{repo} ### Description Go-get meta tag endpoint for `go get` support. ### Method GET ### Endpoint `/{repo}` ### Query Parameters - **go-get** (string) - Required - Indicates this is a go-get request. Value should be `1`. ### Response Headers - **Content-Type** (string) - `text/html; charset=utf-8` ### Response Body (example) ```html ``` ``` -------------------------------- ### Get HEAD Reference Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Retrieves the current HEAD reference for a repository using GET /{repo}/HEAD. Returns the file content, typically 'ref: refs/heads/main'. ```http GET /{repo}/HEAD HTTP/1.1 Host: example.com ``` -------------------------------- ### Pass Configuration to Backend Services Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/config.md Initializes backend services like database and storage using the loaded configuration. The configuration object is then passed to the backend constructor. ```go cfg, _ := config.Load("config.yaml") db, _ := db.New(ctx, cfg) st, _ := storage.New(cfg.DataPath) b := backend.New(ctx, cfg, db, st) ``` -------------------------------- ### Go Get Meta Tag Endpoint Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md This endpoint provides go-get meta tags for Go packages, enabling `go get` command support. It returns an HTML response with specific meta tags. ```html ``` -------------------------------- ### Create User Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Creates a new user account with specified options, including admin status and public keys. Ensure all required options are provided. ```go func (d *Backend) CreateUser(ctx context.Context, username string, opts proto.UserOptions) (proto.User, error) ``` ```go opts := proto.UserOptions{ Admin: false, PublicKeys: []ssh.PublicKey{key1}, } user, err := backend.CreateUser(ctx, "alice", opts) ``` -------------------------------- ### Development Soft Serve Configuration via Environment Variables Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/configuration.md Sets up a local development environment for Soft Serve using environment variables. This includes data path, server name, and network addresses for SSH and HTTP. ```bash #!/bin/bash export SOFT_SERVE_DATA_PATH="./data" export SOFT_SERVE_NAME="Local Dev Server" export SOFT_SERVE_SSH_LISTEN_ADDR=":2222" export SOFT_SERVE_SSH_PUBLIC_URL="ssh://localhost:2222" export SOFT_SERVE_HTTP_LISTEN_ADDR=":3000" export SOFT_SERVE_HTTP_PUBLIC_URL="http://localhost:3000" export SOFT_SERVE_LOG_FORMAT="text" export SOFT_SERVE_DB_DRIVER="sqlite" export SOFT_SERVE_DB_DATA_SOURCE=":memory:" soft serve ``` -------------------------------- ### Description Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Gets the description of a repository. ```APIDOC ## Description ### Description Gets the description of a repository. ### Method Not applicable (Go method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None explicitly provided. ### Response #### Success Response (string, error) Returns the repository description and an error if the operation fails. #### Response Example None explicitly provided. ``` -------------------------------- ### ProjectName Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Gets the project name of a repository. ```APIDOC ## ProjectName ### Description Gets the project name of a repository. ### Method Not applicable (Go method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None explicitly provided. ### Response #### Success Response (string, error) Returns the project name and an error if the operation fails. #### Response Example None explicitly provided. ``` -------------------------------- ### git.Init Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/git.md Initializes and opens a new Git repository at the specified path. It can create a bare repository if the `bare` flag is set to true. ```APIDOC ## Init ### Description Initializes and opens a new Git repository. ### Function Signature ```go func Init(path string, bare bool) (*Repository, error) ``` ### Parameters #### Path Parameters - **path** (string) - Required - Path where repository will be created - **bare** (bool) - Required - Create bare repository (no working directory) ### Returns - **Repository** (*Repository) - A pointer to the newly created Repository object. - **Error** (error) - An error if the directory already exists or is not empty, or if git init fails. ### Example ```go repo, err := git.Init("./myrepo.git", true) if err != nil { log.Fatal(err) } ``` ``` -------------------------------- ### Get Access Level for User Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Retrieves the access level for a specific user on a given repository. ```go func (d *Backend) AccessLevelForUser(ctx context.Context, username string, repoName string) (access.AccessLevel, error) ``` -------------------------------- ### Load Configuration from File Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/config.md Loads the Soft Serve configuration from a specific YAML file path. Handles potential errors during loading. ```go // Load from specific file cfg, err := config.Load("/etc/soft-serve/config.yaml") if err != nil { log.Fatal(err) } ``` -------------------------------- ### Get Anonymous Access Level Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Retrieves the configured access level for anonymous users connecting to the server. ```go func (b *Backend) AnonAccess(ctx context.Context) access.AccessLevel ``` -------------------------------- ### New Backend Instance Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Creates a new Soft Serve backend instance with the provided context, configuration, database connection, and storage backend. ```APIDOC ## New ### Description Creates a new Soft Serve backend instance. ### Signature ```go func New(ctx context.Context, cfg *config.Config, db *db.DB, st store.Store) *Backend ``` ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body (None) ### Returns - `*Backend` - A new backend instance. ### Example ```go b := backend.New(ctx, cfg, db, st) ``` ``` -------------------------------- ### Get User Access Level to Repository Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Determines the access level a specific user has for a given repository. ```go func (d *Backend) AccessLevel(ctx context.Context, user proto.User, repo proto.Repository) access.AccessLevel ``` -------------------------------- ### Get Repository Project Name Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Fetches the project name associated with a repository. This can be used for display or organization. ```go func (d *Backend) ProjectName(ctx context.Context, name string) (string, error) ``` -------------------------------- ### Create Data Directory Source: https://github.com/charmbracelet/soft-serve/blob/main/systemd.md Prepare the directory where Soft Serve will store its data. ```sh sudo mkdir -p /var/local/lib/soft-serve ``` -------------------------------- ### Clone and Push Repositories Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/README.md Demonstrates cloning a repository over SSH and HTTPS, and pushing a new repository to the server. ```bash # Clone via SSH git clone ssh://localhost:23231/myrepo # Clone via HTTP git clone https://localhost:23232/myrepo.git # Push to create new repository git push ssh://localhost:23231/newrepo main ``` -------------------------------- ### GET /{repo}/objects/pack/pack-{hash}.idx Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Retrieves the index file for a specific pack file from the repository. ```APIDOC ## GET /{repo}/objects/pack/pack-{hash}.idx ### Description Get pack index file. ### Method GET ### Endpoint `/{repo}/objects/pack/pack-{hash}.idx` Where `{hash}` is a 40-character hex string. ### Auth Required Yes ### Response Binary pack index data ### Status Codes - `200 OK` - Index file returned - `404 Not Found` - Index file not found ``` -------------------------------- ### GET /{repo}/objects/pack/pack-{hash}.pack Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Retrieves a specific pack file from the repository using its hash. ```APIDOC ## GET /{repo}/objects/pack/pack-{hash}.pack ### Description Get pack file. ### Method GET ### Endpoint `/{repo}/objects/pack/pack-{hash}.pack` Where `{hash}` is a 40-character hex string. ### Auth Required Yes ### Response Binary pack file data ### Status Codes - `200 OK` - Pack file returned - `404 Not Found` - Pack file not found ``` -------------------------------- ### List All Repositories Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Fetches a list of all repositories managed by the backend. Handles potential storage errors. ```Go repos, err := backend.Repositories(ctx) ``` -------------------------------- ### Create Repository Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Creates a new repository with specified options. Handles name validation and checks for existing repositories. Use for creating private or public repositories with descriptions. ```Go opts := proto.RepositoryOptions{ Private: false, Description: "A test repository", ProjectName: "Test", } repo, err := backend.CreateRepository(ctx, "myrepo", user, opts) ``` -------------------------------- ### AccessLevelForUser Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Gets the access level for a user to a repository by names. This function retrieves the permissions a specific user has for a given repository. ```APIDOC ## AccessLevelForUser ### Description Gets the access level for a user to a repository by names. ### Method Not applicable (Go function) ### Endpoint Not applicable (Go function) ### Parameters #### Path Parameters - **username** (string) - Required - Username - **repoName** (string) - Required - Repository name ### Response #### Success Response - **access.AccessLevel** - The access level of the user for the repository. - **error** - An error if the operation fails. ``` -------------------------------- ### GET /{repo}/objects/info/packs Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Retrieves a list of pack files available in the repository. Each line in the response represents a pack file. ```APIDOC ## GET /{repo}/objects/info/packs ### Description Get list of pack files. ### Method GET ### Endpoint `/{repo}/objects/info/packs` ### Auth Required Yes ### Response Plain text, one pack file per line ### Status Codes - `200 OK` - Pack list returned - `404 Not Found` - Directory not found ### Example Response ``` P pack-1234567890abcdef.pack ``` ``` -------------------------------- ### Get Commit Diff Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/git.md Calculates the difference between a commit and its parent. Returns an error if the diff operation fails or if the commit has no parent. ```Go commit, _ := repo.Commit("abc1234") diff, err := repo.Diff(commit) if err != nil { log.Fatal(err) } for _, file := range diff.Files { fmt.Println("File:", file.Path) fmt.Println("Changes:", file.Added, "added, ", file.Deleted, "deleted") } ``` -------------------------------- ### Define Soft Serve Configuration Source: https://github.com/charmbracelet/soft-serve/blob/main/systemd.md Create an optional configuration file to override default server settings. ```conf # Config defined here will override the config in /var/local/lib/soft-serve/config.yaml # Keys defined in `SOFT_SERVE_INITIAL_ADMIN_KEYS` will be merged with # the `initial_admin_keys` from /var/local/lib/soft-serve/config.yaml. # #SOFT_SERVE_GIT_LISTEN_ADDR=:9418 #SOFT_SERVE_HTTP_LISTEN_ADDR=:23232 #SOFT_SERVE_SSH_LISTEN_ADDR=:23231 #SOFT_SERVE_SSH_KEY_PATH=ssh/soft_serve_host_ed25519 #SOFT_SERVE_INITIAL_ADMIN_KEYS='ssh-ed25519 AAAAC3NzaC1lZDI1...' ``` -------------------------------- ### Load Configuration from Directory Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/config.md Loads server configuration by looking for a 'config.yaml' file within a specified data directory. Handles file reading, YAML parsing, and validation errors. ```go cfg, err := config.LoadDirectory("/var/lib/soft-serve") if err != nil { log.Fatal(err) } ``` -------------------------------- ### Get Access Level by Public Key to Repository Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Determines the access level granted to an SSH public key for a specific repository. ```go func (d *Backend) AccessLevelByPublicKey(ctx context.Context, key ssh.PublicKey, repo proto.Repository) access.AccessLevel ``` -------------------------------- ### Get User by Access Token Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Retrieves user information using an access token. Returns proto.ErrUserNotFound if the token is invalid or has expired. ```go func (d *Backend) UserByAccessToken(ctx context.Context, token string) (proto.User, error) ``` -------------------------------- ### Create Repository with Description and Project Name Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md When creating a repository, you can optionally provide a description and project name using specific flags. This helps in organizing and identifying your repositories. ```sh ssh -p 23231 localhost repo create icecream '-d "This is an Ice Cream description"' ``` ```sh ssh -p 23231 localhost repo create icecream '-d "This is an Ice Cream description"' '-n "Ice Cream"' ``` -------------------------------- ### Get User by Username Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Retrieves a user's profile information using their unique username. Returns proto.ErrUserNotFound if the user does not exist. ```go func (d *Backend) User(ctx context.Context, username string) (proto.User, error) ``` -------------------------------- ### Get Repository Information Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Retrieve detailed information about a repository, including its branches, tags, and description, using the `repo info` command. ```sh ssh -p 23231 localhost repo icecream info ``` -------------------------------- ### Get HEAD Reference Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/git.md Retrieves the HEAD reference, which typically points to the current branch. Handles errors if HEAD is detached or invalid. ```go head, err := repo.HEAD() if err != nil { log.Fatal(err) } fmt.Println("Current branch:", head.Name().Short()) ``` -------------------------------- ### Configure HTTP Public URL Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/configuration.md Set the public URL for HTTP/HTTPS cloning. If TLS is enabled, this must start with `https://`. ```yaml http: public_url: "https://git.example.com" ``` -------------------------------- ### Printing a File with Syntax Highlighting Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Fetch and display a specific file from a repository with syntax highlighting and line numbers enabled. ```bash ssh git.charm.sh repo blob soft-serve cmd/soft/main.go -c -l ``` -------------------------------- ### Load Configuration from File Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/config.md Loads server configuration from a specified YAML file path. Handles file reading, YAML parsing, and validation errors. ```go cfg, err := config.Load("/etc/soft-serve/config.yaml") if err != nil { log.Fatal(err) } ``` -------------------------------- ### Get Webhook by ID Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Retrieves a specific webhook's details using its unique identifier. Use this to fetch configuration for a single webhook. ```go func (b *Backend) Webhook(ctx context.Context, repo proto.Repository, id int64) (webhook.Hook, error) ``` -------------------------------- ### Get User by ID Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Retrieves a user's profile information using their unique integer ID. Returns proto.ErrUserNotFound if the user does not exist. ```go func (d *Backend) UserByID(ctx context.Context, id int64) (proto.User, error) ``` -------------------------------- ### Import Soft Serve Packages Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/README.md Reference the necessary Soft Serve packages in your Go code. These imports provide access to the backend, configuration, proto, access, and git functionalities. ```go import ( "github.com/charmbracelet/soft-serve/pkg/backend" "github.com/charmbracelet/soft-serve/pkg/config" "github.com/charmbracelet/soft-serve/pkg/proto" "github.com/charmbracelet/soft-serve/pkg/access" "github.com/charmbracelet/soft-serve/git" ) ``` -------------------------------- ### List All Users Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Fetches a list of all registered users in the system. ```go func (d *Backend) Users(ctx context.Context) ([]proto.User, error) ``` -------------------------------- ### Get File Contents Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/git.md Retrieves the content of a specific file within a given tree path. This is useful for reading file data from a repository. ```go tree, _ := repo.TreePath(head, "docs") blob, _ := tree.Blob("README.md") content, _ := blob.Data() fmt.Println(string(content)) ``` -------------------------------- ### Accessing a Repo in Soft Serve TUI Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Connect to the Soft Serve instance and jump directly to a specific repository within the TUI. ```bash ssh git.charm.sh -t soft-serve ``` -------------------------------- ### Get Blob Content Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/git.md Retrieves a specific file (blob) from a Git tree by its path. Handles potential errors during retrieval and data extraction. ```Go tree, _ := repo.Tree(head) blob, err := tree.Blob("README.md") if err != nil { log.Fatal(err) } content, _ := blob.Data() fmt.Println(string(content)) ``` -------------------------------- ### Create Webhook Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Creates a webhook for a repository. Use this to set up automated notifications or actions based on repository events. ```go func (b *Backend) CreateWebhook(ctx context.Context, repo proto.Repository, url string, contentType webhook.ContentType, secret string, events []webhook.Event, active bool) error ``` -------------------------------- ### Load Configuration from Data Directory Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/config.md Loads the Soft Serve configuration from a 'config.yaml' file located within the specified data directory. Handles potential errors during loading. ```go // Load config.yaml from data directory cfg, err := config.LoadDirectory("/var/lib/soft-serve") if err != nil { log.Fatal(err) } ``` -------------------------------- ### GET /{repo}/objects/{hash} Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Retrieves a loose object from the Git object database using its hash. The hash is split into two parts for the path. ```APIDOC ## GET /{repo}/objects/{hash} ### Description Get loose object from git object database. ### Method GET ### Endpoint `/{repo}/objects/{XX}/{YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY}` Where `{XX}` is first 2 hex chars and `{YYYYYY...}` is remaining 38 hex chars of object hash. ### Auth Required Yes ### Response Binary object data ### Status Codes - `200 OK` - Object returned - `404 Not Found` - Object not found ``` -------------------------------- ### Load Configuration Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/config.md Loads configuration from a YAML file. Use this to access server settings like name, listen addresses, and database driver. ```go cfg, _ := config.Load("config.yaml") fmt.Println("Server Name:", cfg.Name) fmt.Println("SSH Listen:", cfg.SSH.ListenAddr) fmt.Println("HTTP Public URL:", cfg.HTTP.PublicURL) fmt.Println("Database Driver:", cfg.DB.Driver) ``` -------------------------------- ### Run Soft-Serve as a container Source: https://github.com/charmbracelet/soft-serve/blob/main/docker.md Execute the container with volume mounting for data persistence and port mapping. Ensure the container is run without the --tty or -t flags. ```sh docker run \ --name=soft-serve \ --volume /path/to/data:/soft-serve \ --publish 23231:23231 \ --publish 23232:23232 \ --publish 23233:23233 \ --publish 9418:9418 \ -e SOFT_SERVE_INITIAL_ADMIN_KEYS="YOUR_ADMIN_KEY_HERE" \ --restart unless-stopped \ charmcli/soft-serve:latest ``` -------------------------------- ### GET /livez Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Liveness check endpoint. Always returns 200 if the server is running. Used for health monitoring to check if the server process is alive. ```APIDOC ## GET /livez ### Description Liveness check endpoint. Always returns 200 if the server is running. ### Method GET ### Endpoint /livez ### Description Used for health monitoring to check if the server process is alive. ``` -------------------------------- ### Get Commit History Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/git.md Retrieves a list of commits based on specified options, such as revision, count, and skip. Useful for paginating or filtering commit logs. ```Go // Recent 10 commits on main branch commits, err := repo.CommitLog(git.LogOptions{ Rev: "main", Count: 10, }) if err != nil { log.Fatal(err) } for _, commit := range commits { fmt.Printf("%s %s\n", commit.ID[:7], commit.Message) } ``` -------------------------------- ### Get Specific Commit Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/git.md Fetches a commit object using its hash or a Git revision. Logs an error if the revision does not exist or if the Git operation fails. ```Go commit, err := repo.Commit("abc1234") if err != nil { log.Fatal(err) } fmt.Println("Author:", commit.Author.Name) fmt.Println("Message:", commit.Message) ``` -------------------------------- ### Push to Soft Serve to Create Repository Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Push your local branch (e.g., `main`) to the Soft Serve remote. If the repository does not exist on the server, it will be created automatically upon the first push. ```sh git push origin main ``` -------------------------------- ### Get Tree at a Reference Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/git.md Retrieves the directory tree structure associated with a given Git reference (branch, tag, or commit). Errors if the reference does not exist. ```go head, _ := repo.HEAD() tree, err := repo.Tree(head) if err != nil { log.Fatal(err) } for _, entry := range tree.Entries() { fmt.Println(entry.Name, entry.Mode) } ``` -------------------------------- ### Printing a Specific File from a Repo Source: https://github.com/charmbracelet/soft-serve/blob/main/README.md Fetch and display the content of a specific file from a repository on Soft Serve. ```bash ssh git.charm.sh repo blob soft-serve cmd/soft/main.go ``` -------------------------------- ### Manage Users and Repositories via SSH Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/README.md Commands to create users, repositories, set privacy, and manage collaborators using the Soft Serve SSH interface. ```bash # Create new user ssh -p 23231 localhost user create alice -k "ssh-ed25519 AAAA..." # Create repository ssh -p 23231 localhost repo create myrepo # Make private ssh -p 23231 localhost repo private myrepo true # Add collaborator ssh -p 23231 localhost repo collab add myrepo alice read-write ``` -------------------------------- ### Create New Database Connection Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/db.md Initializes a new database connection pool using the provided context and configuration. Ensure the configuration contains valid database settings. The connection pool should be closed when no longer needed. ```go cfg, _ := config.Load("config.yaml") db, err := db.New(ctx, cfg) if err != nil { log.Fatal(err) } deffer db.Close() ``` -------------------------------- ### Backend Service - Constructor Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/QUICK_REFERENCE.md Creates a new backend service instance. ```APIDOC ## New ### Description Create a new backend service. ### Signature `New(ctx, cfg, db, st) *Backend` ### Parameters - **ctx**: Context for the operation. - **cfg**: Configuration for the backend. - **db**: Database connection. - **st**: Storage provider. ``` -------------------------------- ### Get User by Public Key Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Identifies a user account based on their associated SSH public key. Returns proto.ErrUserNotFound if no user is found with the given key. ```go func (d *Backend) UserByPublicKey(ctx context.Context, key ssh.PublicKey) (proto.User, error) ``` -------------------------------- ### Create Systemd Service File Source: https://github.com/charmbracelet/soft-serve/blob/main/systemd.md Define the service unit file to manage the Soft Serve process. ```conf [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 ``` -------------------------------- ### Get Subtree within a Tree Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/git.md Retrieves a subtree located at a specified path relative to the current tree object. This allows for navigating nested directory structures. ```go rootTree, _ := repo.Tree(head) cmdTree, _ := rootTree.SubTree("cmd") ``` -------------------------------- ### Add User with SSH Key Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/README.md Create a new user in Soft Serve and associate an SSH public key with them. This is the primary method for user authentication. ```go key, _ := ssh.ParsePublicKey([]byte(publicKeyStr)) user, _ := backend.CreateUser(ctx, "alice", proto.UserOptions{ PublicKeys: []ssh.PublicKey{key}, }) ``` -------------------------------- ### Get Tree at a Specific Path within a Reference Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/git.md Retrieves the directory tree for a specific path within a given Git reference. Useful for inspecting subdirectories. ```go head, _ := repo.HEAD() srcTree, err := repo.TreePath(head, "src") if err != nil { log.Fatal(err) } ``` -------------------------------- ### Load Configuration from Directory Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/config.md Loads configuration by looking for a `config.yaml` file within a specified data directory. This is a convenient way to manage configuration when it's co-located with other data. ```APIDOC ## LoadDirectory ### Description Loads configuration from a data directory. It specifically looks for a `config.yaml` file within the provided directory. ### Function Signature ```go func LoadDirectory(dataPath string) (*Config, error) ``` ### Parameters #### Path Parameters - **dataPath** (string) - Required - Path to data directory ### Returns - **`*Config`**: A pointer to the loaded configuration object. - **`error`**: An error if the configuration file cannot be found or parsed. ### Example ```go cfg, err := config.LoadDirectory("/var/lib/soft-serve") if err != nil { log.Fatal(err) } ``` ``` -------------------------------- ### Get Tree at a Git Reference String Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/git.md Retrieves the directory tree structure using a Git reference provided as a string, such as a branch name or commit hash. ```go tree, err := repo.LsTree("main") if err != nil { log.Fatal(err) } ``` -------------------------------- ### List Webhooks Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Lists all configured webhooks for a specific repository. Useful for auditing or managing existing webhook configurations. ```go func (b *Backend) ListWebhooks(ctx context.Context, repo proto.Repository) ([]webhook.Hook, error) ``` -------------------------------- ### Get File Content from Repository Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/QUICK_REFERENCE.md Retrieves the content of a specific file from a repository at a given commit or branch. Assumes 'head' refers to a valid commit or branch reference. ```go tree, _ := repo.Tree(head) blob, _ := tree.Blob("path/to/file.txt") content, _ := blob.Data() ``` -------------------------------- ### Check Database Readiness with Ping Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/db.md Verify if the database is reachable and responsive by calling PingContext. Returns nil if the ping is successful. ```go func isDatabaseReady(ctx context.Context, database *db.DB) bool { return database.PingContext(ctx) == nil } ``` -------------------------------- ### List All Repository References Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/git.md Lists all references within the repository, including branches and tags. The output contains the reference spec and its ID. ```go refs, err := repo.References() if err != nil { log.Fatal(err) } for _, ref := range refs { fmt.Println("Ref:", ref.Refspec, "->", ref.ID) } ``` -------------------------------- ### Get Webhook Delivery by ID Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Fetches details of a specific webhook delivery attempt using both the webhook ID and the delivery ID. Useful for inspecting individual delivery outcomes. ```go func (b *Backend) WebhookDelivery(ctx context.Context, webhookID int64, id uuid.UUID) (webhook.Delivery, error) ``` -------------------------------- ### POST/GET /{repo}/info/lfs/locks Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/endpoints.md Manages Git LFS file locks. Use GET to list existing locks and POST to create a new lock, preventing concurrent modifications. ```APIDOC ## POST/GET /{repo}/info/lfs/locks ### Description List or create LFS locks. ### Method POST (create), GET (list) ### Endpoint `/{repo}/info/lfs/locks` ### Auth Required Yes ### POST Request Body ```json { "path": "large-file.bin", "ref": { "name": "refs/heads/main" } } ``` ### GET Response Body ```json { "locks": [ { "id": "123", "path": "large-file.bin", "locked_at": "2024-06-02T10:00:00Z", "owner": { "name": "alice" } } ] } ``` ### Status Codes - `200 OK` - Success - `403 Forbidden` - Insufficient access - `409 Conflict` - File already locked ``` -------------------------------- ### Set User Password Source: https://github.com/charmbracelet/soft-serve/blob/main/_autodocs/api-reference/backend.md Establishes or updates the password for a user account. Passwords should be provided in plain text. ```go func (d *Backend) SetPassword(ctx context.Context, username string, password string) error ```