Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/docker-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -euo pipefail

# This is the pseudo-version that go.mod uses. We use the same version string
# so that downstream consumers can line up image versions with module versions.
version="$(TZ=UTC git --no-pager show \
--quiet \
--abbrev=12 \
--date='format-local:%Y%m%d%H%M%S' \
--format='0.0.0-%cd-%h')"

printf 'value=%s\n' "$version" >>"$GITHUB_OUTPUT"
59 changes: 59 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Publish Docker Image

on:
push:
branches:
- main
tags:
- 'v*'
workflow_dispatch:

jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: version
id: version
run: .github/workflows/docker-version.sh

- name: setup-buildx
uses: docker/setup-buildx-action@v3

- name: docker-meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=${{ steps.version.outputs.value }},enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
type=sha,prefix=sha-,format=short

- name: login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ steps.version.outputs.value }}
44 changes: 32 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
FROM golang:1.23.4-alpine3.19 AS builder
# syntax=docker/dockerfile:1.7
FROM golang:1.26.2-alpine AS builder

RUN apk add --no-cache ca-certificates

ENV CGO_ENABLED=0
WORKDIR /go/src/github.com/sourcegraph/zoekt
WORKDIR /src

# Cache dependencies
# Cache dependency resolution separately from source changes.
COPY go.mod go.sum ./
RUN go mod download
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download

COPY . .
ARG VERSION=dev
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
mkdir -p /out && \
go build \
-trimpath \
-ldflags "-X github.com/sourcegraph/zoekt.Version=$VERSION" \
-o /out/ \
./cmd/...

FROM alpine:3

COPY . ./
ARG VERSION
RUN go install -ldflags "-X github.com/sourcegraph/zoekt.Version=$VERSION" ./cmd/...
RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget

FROM alpine:3.19 AS zoekt
COPY --chmod=755 install-ctags-alpine.sh /usr/local/bin/install-ctags-alpine.sh
RUN /usr/local/bin/install-ctags-alpine.sh && rm /usr/local/bin/install-ctags-alpine.sh

RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget
RUN addgroup -S zoekt && \
adduser -S -G zoekt -h /home/zoekt zoekt && \
mkdir -p /data/index /home/zoekt && \
chown -R zoekt:zoekt /data /home/zoekt

COPY --from=builder /out/ /usr/local/bin/

COPY install-ctags-alpine.sh .
RUN ./install-ctags-alpine.sh && rm install-ctags-alpine.sh
USER zoekt
WORKDIR /home/zoekt

COPY --from=builder /go/bin/* /usr/local/bin/
ENV DATA_DIR=/data/index

ENTRYPOINT ["/sbin/tini", "--"]
CMD ["zoekt-webserver", "-index", "/data/index", "-pprof", "-rpc"]
23 changes: 0 additions & 23 deletions Dockerfile.indexserver

This file was deleted.

24 changes: 0 additions & 24 deletions Dockerfile.webserver

This file was deleted.

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ This will start a web server with a simple search UI at http://localhost:6070.
See the [query syntax docs](doc/query_syntax.md) for more details on the query
language.

#### Container image

Zoekt publishes a single container image at `ghcr.io/sourcegraph/zoekt`. It
includes the Zoekt binaries, `git`, and `universal-ctags`. By default it runs
`zoekt-webserver` against `/data/index`:

docker run --rm -p 6070:6070 -v "$PWD/index:/data/index" ghcr.io/sourcegraph/zoekt

You can override the default command to run `zoekt-indexserver` instead. This
example stores cloned repositories, logs, and indexes under `/data` and reads a
mounted mirror config file:

docker run --rm \
-v "$PWD/config.json:/config.json:ro" \
-v "$PWD/token.txt:/home/zoekt/token.txt:ro" \
-v "$PWD/zoekt-data:/data" \
ghcr.io/sourcegraph/zoekt \
zoekt-indexserver -mirror_config /config.json -data_dir /data

If you start the web server with `-rpc`, it exposes a [simple JSON search
API](doc/json-api.md) at `http://localhost:6070/api/search`.

Expand Down
Loading