What is Deployment?

Deployment refers to the process of making a software application available for use. In the context of Zoekt, deployment involves setting up and configuring the Zoekt server on a production environment so that it can serve code search queries effectively.

Why is Deployment important?

Deployment is crucial for several reasons:

  • Availability: A deployed Zoekt server makes code search capabilities accessible to developers and users.
  • Reliability: Deployment ensures that the Zoekt server runs reliably, providing consistent and uninterrupted code search service.
  • Scalability: Deployment enables scaling the Zoekt server to handle increasing code search demands.
  • Management: Deployment allows for easy management of the Zoekt server, including updates, restarts, and monitoring.

Deployment Options

Zoekt offers various deployment options, each suited to different needs and environments. Here’s a breakdown of the most common options:

1. Systemd Unit File

A systemd unit file provides a standardized way to manage and automate the startup and shutdown of services on Linux systems. This approach offers several benefits:

  • Automated Startup: The systemd unit file ensures that Zoekt starts automatically when the server boots up.
  • Automatic Restart: Systemd monitors the service and automatically restarts it if it crashes.
  • Resource Management: Systemd allows for configuring resource limits and dependencies for Zoekt.

Example systemd unit file:

[Unit]
          Description=Zoekt code search server
          After=network.target
          
          [Service]
          User=zoekt
          Group=zoekt
          WorkingDirectory=/var/lib/zoekt
          ExecStart=/usr/local/bin/zoekt-sourcegraph-indexserver -config /etc/zoekt/config.toml
          
          [Install]
          WantedBy=multi-user.target
          

Source: cmd/zoekt-sourcegraph-indexserver/systemd/zoekt-sourcegraph-indexserver.service

2. Docker Container

Docker containers offer a portable and isolated environment for running applications. Deploying Zoekt as a Docker container provides the following advantages:

  • Portability: Docker containers can be easily moved between different environments.
  • Isolation: Containers isolate the Zoekt server from other applications on the host system.
  • Consistency: Docker ensures that Zoekt runs consistently across different environments.

Dockerfile example:

FROM ubuntu:latest
          
          # Install dependencies
          RUN apt-get update && apt-get install -y \
              curl \
              git \
              build-essential \
              libpq-dev \
              libgit2-dev \
              zlib1g-dev \
              libzstd-dev \
              libsodium-dev \
              ca-certificates
          
          # Install Zoekt
          RUN curl -L https://github.com/sourcegraph/zoekt/releases/latest/download/zoekt-linux-amd64.tar.gz | tar -xzf - -C /usr/local/bin/
          
          # Configure Zoekt
          COPY config.toml /etc/zoekt/config.toml
          
          # Run Zoekt
          CMD ["/usr/local/bin/zoekt-sourcegraph-indexserver", "-config", "/etc/zoekt/config.toml"]
          

Source: https://hub.docker.com/r/sourcegraph/zoekt

3. Kubernetes

Kubernetes is a container orchestration platform that allows for managing and scaling applications across a cluster of nodes. Deploying Zoekt on Kubernetes provides the following benefits:

  • High Availability: Kubernetes automatically manages failover and replication to ensure high availability.
  • Scalability: Kubernetes makes it easy to scale Zoekt up or down based on demand.
  • Self-Healing: Kubernetes automatically recovers from failures and restarts failed pods.

Kubernetes deployment file example:

apiVersion: apps/v1
          kind: Deployment
          metadata:
            name: zoekt
          spec:
            replicas: 3
            selector:
              matchLabels:
                app: zoekt
            template:
              metadata:
                labels:
                  app: zoekt
              spec:
                containers:
                - name: zoekt
                  image: sourcegraph/zoekt:latest
                  ports:
                  - containerPort: 8080
                  volumeMounts:
                  - name: zoekt-config
                    mountPath: /etc/zoekt/config.toml
                volumes:
                - name: zoekt-config
                  configMap:
                    name: zoekt-config
          

Source: https://github.com/sourcegraph/sourcegraph/blob/main/deploy/kubernetes

Choosing the Right Deployment Option

The best deployment option depends on various factors, including:

  • Infrastructure: The available infrastructure and resources.
  • Experience: The developer’s experience with different deployment methods.
  • Requirements: The specific requirements for Zoekt, such as scalability, high availability, and security.

For example, if high availability and scalability are paramount, Kubernetes might be the preferred option. If simplicity and portability are priorities, a Docker container could be more suitable.

Top-Level Directory Explanations

cmd/ - This directory contains the command-line interface (CLI) for Zoekt.

cmd/zoekt/ - This directory contains the main package for the CLI tool.

cmd/zoekt-archive-index/ - This directory contains the code for building and managing archive indexes.

cmd/zoekt-dynamic-indexserver/ - This directory contains the code for the dynamic index server.

cmd/zoekt-git-clone/ - This directory contains the code for cloning Git repositories.

cmd/zoekt-git-index/ - This directory contains the code for managing Git indexes.

cmd/zoekt-index/ - This directory contains the code for managing indexes in general.

cmd/zoekt-indexserver/ - This directory contains the code for the index server.

cmd/zoekt-merge-index/ - This directory contains the code for merging indexes.

cmd/zoekt-repo-index/ - This directory contains the code for managing repository indexes.

cmd/zoekt-sourcegraph-indexserver/ - This directory contains the code for the Sourcegraph index server.

doc/ - This directory contains documentation for the project.

Entrypoints and Where to Start

cmd/zoekt/main.go - The main entrypoint for the Zoekt command-line tool, providing functions for displaying matches, loading shards, and starting various profiling modes.

cmd/zoekt-dynamic-indexserver/main.go - The main entrypoint for the dynamic index server, handling logging, indexing repositories, and empty directories.

cmd/zoekt-indexserver/main.go - The main entrypoint for the index server, handling logging, periodic fetching, indexing pending repos, and deleting logs.

cmd/zoekt-mirror-gerrit/main.go - The main entrypoint for the gerrit mirror binary, which fetches and indexes repositories using the gerrit protocol.

cmd/zoekt-mirror-gitlab/main.go - The main entrypoint for the gitlab mirror binary, which fetches and indexes repositories using the gitlab API.

cmd/zoekt-repo-index/main.go - The main entrypoint for the repo-index binary, which indexes a repository-based repository using a manifest file.

cmd/zoekt-merge-index/main.go - The main entrypoint for the merge index binary, which merges indexes from multiple shards.

cmd/zoekt-git-clone/main.go - The main entrypoint for the git clone binary, which fetches and clones repositories from various sources.

cmd/zoekt-mirror-gitiles/main.go - The main entrypoint for the gitiles mirror binary, which fetches and indexes repositories from a gitiles server.

cmd/zoekt-git-index/main.go - The main entrypoint for the git index binary, which indexes a git repository.

cmd/zoekt-mirror-bitbucket-server/main.go - The main entrypoint for the bitbucket-server mirror binary, which fetches and clones repositories from a bitbucket server.

cmd/zoekt-index/main.go - The main entrypoint for the index binary, which indexes a repository or an archive.

cmd/zoekt-archive-index/main.go - The main entrypoint for the archive index binary, which indexes an archive.

cmd/zoekt-sourcegraph-indexserver/main.go - The main entrypoint for the sourcegraph index server, which periodically reindexes enabled repositories on Sourcegraph.

cmd/zoekt-mirror-github/main.go - The main entrypoint for the github mirror binary, which fetches and clones repositories from a GitHub user or organization.

cmd/zoekt-webserver/main.go - The main entrypoint for the web server, which serves search results and handles various HTTP requests.