Skip to content

Commit 8566836

Browse files
committed
Merge remote-tracking branch 'upstream/main' into msukkari/sync-upstream
# Conflicts: # cmd/zoekt-webserver/main.go # go.mod # go.sum # query/parse.go
2 parents 01091d5 + c3d4afa commit 8566836

233 files changed

Lines changed: 11826 additions & 4498 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ jobs:
4848
steps:
4949
- name: add dependencies
5050
run: apk add bash go
51-
# Pinned a commit to make go version configurable.
52-
# This should be safe to upgrade once this commit is in a released version:
53-
# https://github.com/jidicula/go-fuzz-action/commit/23cc553941669144159507e2cccdbb4afc5b3076
54-
- uses: jidicula/go-fuzz-action@0206b61afc603b665297621fa5e691b1447a5e57
51+
- uses: jidicula/go-fuzz-action@2d8b802597c47a79764d83dabc27fb672f2fb8d9
5552
with:
5653
packages: 'github.com/sourcegraph/zoekt' # This is the package where the Protobuf round trip tests are defined
5754
fuzz-time: 30s
@@ -116,73 +113,3 @@ jobs:
116113
# Check if the generated code is up-to-date
117114
- run: .github/workflows/buf-generate-check.sh
118115

119-
# We build a shared docker image called "zoekt". This is not pushed, but is
120-
# used for creating the indexserver and webserver images.
121-
docker:
122-
if: github.ref == 'refs/heads/main'
123-
runs-on: ubuntu-latest
124-
needs:
125-
- "test"
126-
- "shellcheck"
127-
steps:
128-
- name: checkout
129-
uses: actions/checkout@v3
130-
131-
- name: version
132-
id: version
133-
run: .github/workflows/docker-version.sh
134-
135-
- name: docker-meta-webserver
136-
id: meta-webserver
137-
uses: docker/metadata-action@v3
138-
with:
139-
images: |
140-
sourcegraph/zoekt-webserver
141-
tags: |
142-
type=ref,event=branch
143-
type=ref,event=pr
144-
type=semver,pattern={{version}}
145-
type=sha
146-
- name: docker-meta-indexserver
147-
id: meta-indexserver
148-
uses: docker/metadata-action@v3
149-
with:
150-
images: |
151-
sourcegraph/zoekt-indexserver
152-
tags: |
153-
type=ref,event=branch
154-
type=ref,event=pr
155-
type=semver,pattern={{version}}
156-
type=sha
157-
158-
- name: build-zoekt
159-
uses: docker/build-push-action@v4
160-
with:
161-
context: .
162-
tags: "zoekt:latest"
163-
push: "false"
164-
build-args: VERSION=${{ steps.version.outputs.value }}
165-
166-
- name: Login to Docker Hub
167-
uses: docker/login-action@v2
168-
with:
169-
username: ${{ secrets.DOCKERHUB_USERNAME }}
170-
password: ${{ secrets.DOCKERHUB_TOKEN }}
171-
172-
- name: build-push-webserver
173-
uses: docker/build-push-action@v4
174-
with:
175-
context: .
176-
tags: sourcegraph/zoekt-webserver:${{ steps.version.outputs.value }}, ${{ steps.meta-webserver.outputs.tags }}, sourcegraph/zoekt-webserver:latest
177-
file: Dockerfile.webserver
178-
cache-from: sourcegraph/zoekt-webserver:latest
179-
push: true
180-
181-
- name: build-push-indexserver
182-
uses: docker/build-push-action@v4
183-
with:
184-
context: .
185-
tags: sourcegraph/zoekt-indexserver:${{ steps.version.outputs.value }}, ${{ steps.meta-indexserver.outputs.tags }}, sourcegraph/zoekt-indexserver:latest
186-
file: Dockerfile.indexserver
187-
cache-from: sourcegraph/zoekt-indexserver:latest
188-
push: true
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env bash
22

3-
# This is the psuedo-version that go.mod uses. We use the same version string
4-
# so that sourcegraph/sourcegraph's go.mod is kept in sync with the version we
5-
# publish.
3+
set -euo pipefail
64

7-
printf "::set-output name=value::"
8-
9-
TZ=UTC git --no-pager show \
5+
# This is the pseudo-version that go.mod uses. We use the same version string
6+
# so that downstream consumers can line up image versions with module versions.
7+
version="$(TZ=UTC git --no-pager show \
108
--quiet \
119
--abbrev=12 \
1210
--date='format-local:%Y%m%d%H%M%S' \
13-
--format="0.0.0-%cd-%h"
11+
--format='0.0.0-%cd-%h')"
12+
13+
printf 'value=%s\n' "$version" >>"$GITHUB_OUTPUT"

.github/workflows/docker.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Publish Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
workflow_dispatch:
10+
11+
jobs:
12+
docker:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
steps:
18+
- name: checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: version
24+
id: version
25+
run: .github/workflows/docker-version.sh
26+
27+
- name: setup-buildx
28+
uses: docker/setup-buildx-action@v3
29+
30+
- name: docker-meta
31+
id: meta
32+
uses: docker/metadata-action@v5
33+
with:
34+
images: ghcr.io/${{ github.repository }}
35+
tags: |
36+
type=semver,pattern={{version}}
37+
type=semver,pattern={{major}}.{{minor}}
38+
type=raw,value=${{ steps.version.outputs.value }},enable={{is_default_branch}}
39+
type=raw,value=latest,enable={{is_default_branch}}
40+
type=sha,prefix=sha-,format=short
41+
42+
- name: login to ghcr.io
43+
uses: docker/login-action@v3
44+
with:
45+
registry: ghcr.io
46+
username: ${{ github.actor }}
47+
password: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: build and push
50+
uses: docker/build-push-action@v6
51+
with:
52+
context: .
53+
push: true
54+
tags: ${{ steps.meta.outputs.tags }}
55+
labels: ${{ steps.meta.outputs.labels }}
56+
cache-from: type=gha
57+
cache-to: type=gha,mode=max
58+
build-args: |
59+
VERSION=${{ steps.version.outputs.value }}

AGENT.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Zoekt Coding Agent Guidelines
2+
3+
## Build & Test Commands
4+
- Build: `go build ./cmd/...`
5+
- Run all tests: `go test ./... -short`
6+
- Run a single test: `go test -run=TestName ./path/to/package`
7+
- Run specific test with verbose output: `go test -v -run=TestName ./path/to/package`
8+
- Benchmark: `go test -bench=BenchmarkName ./path/to/package`
9+
- Fuzzing: `go test -fuzz=FuzzTestName -fuzztime=30s ./package`
10+
- Smoke test: Check a specific repo: `go run ./cmd/zoekt-git-index /path/to/repo`
11+
12+
## Code Style Guidelines
13+
- Import format: standard Go imports (stdlib, external, internal) with alphabetical sorting
14+
- Error handling: explicit error checking with proper returns (no ignored errors)
15+
- Naming: Go standard (CamelCase for exported, camelCase for private)
16+
- Tests: Table-driven tests preferred with descriptive names
17+
- Documentation: All exported functions should have comments
18+
- Shell scripts: Use shfmt with `-i 2 -ci -bn` flags
19+
- Proto files: Run buf lint and format checks
20+
- Memory optimization: As a code search database, Zoekt is memory-sensitive - be conscious of struct field ordering and memory usage in core structures
21+
22+
## Documentation Resources
23+
- Design overview: `doc/design.md` - Core architecture and search methodology
24+
- Indexing details: `doc/indexing.md` - How the indexing process works
25+
- Query syntax: `doc/query_syntax.md` - Search query language reference
26+
- FAQ: `doc/faq.md` - Common questions and troubleshooting

CONTRIBUTING.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Contributing
2+
3+
We welcome contributions to the project! To propose a change, please fork the repository, make your changes, then submit
4+
a pull request. If the change is significant or potentially controversial, please open an issue first to discuss it.
5+
Zoekt does not require a CLA to contribute.
6+
7+
Before opening a pull request, make sure that you have run the tests locally:
8+
```sh
9+
go test ./...
10+
```
11+
12+
It's also good to run a local smoke test for the relevant component. For example, if you've made changes in
13+
`zoekt-git-index`, you can try indexing a repository locally:
14+
```sh
15+
go run ./cmd/zoekt-git-index /path/to/repo
16+
```
17+

Dockerfile

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,47 @@
1-
FROM golang:1.23.4-alpine3.19 AS builder
1+
# syntax=docker/dockerfile:1.7
2+
FROM golang:1.26.2-alpine AS builder
23

34
RUN apk add --no-cache ca-certificates
45

56
ENV CGO_ENABLED=0
6-
WORKDIR /go/src/github.com/sourcegraph/zoekt
7+
WORKDIR /src
78

8-
# Cache dependencies
9+
# Cache dependency resolution separately from source changes.
910
COPY go.mod go.sum ./
10-
RUN go mod download
11+
RUN --mount=type=cache,target=/go/pkg/mod \
12+
go mod download
13+
14+
COPY . .
15+
ARG VERSION=dev
16+
RUN --mount=type=cache,target=/go/pkg/mod \
17+
--mount=type=cache,target=/root/.cache/go-build \
18+
mkdir -p /out && \
19+
go build \
20+
-trimpath \
21+
-ldflags "-X github.com/sourcegraph/zoekt.Version=$VERSION" \
22+
-o /out/ \
23+
./cmd/...
24+
25+
FROM alpine:3
1126

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

16-
FROM alpine:3.19 AS zoekt
29+
COPY --chmod=755 install-ctags-alpine.sh /usr/local/bin/install-ctags-alpine.sh
30+
RUN /usr/local/bin/install-ctags-alpine.sh && \
31+
rm /usr/local/bin/install-ctags-alpine.sh \
32+
/usr/local/bin/universal-optscript
1733

18-
RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget
34+
RUN addgroup -S zoekt && \
35+
adduser -S -G zoekt -h /home/zoekt zoekt && \
36+
mkdir -p /data/index /home/zoekt && \
37+
chown -R zoekt:zoekt /data /home/zoekt
38+
39+
COPY --from=builder /out/ /usr/local/bin/
1940

20-
COPY install-ctags-alpine.sh .
21-
RUN ./install-ctags-alpine.sh && rm install-ctags-alpine.sh
41+
USER zoekt
42+
WORKDIR /home/zoekt
2243

23-
COPY --from=builder /go/bin/* /usr/local/bin/
44+
ENV DATA_DIR=/data/index
2445

2546
ENTRYPOINT ["/sbin/tini", "--"]
47+
CMD ["zoekt-webserver", "-index", "/data/index", "-pprof", "-rpc"]

Dockerfile.indexserver

Lines changed: 0 additions & 23 deletions
This file was deleted.

Dockerfile.webserver

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)