Skip to content

Commit 36ce97f

Browse files
authored
ci: publish image to ghcr.io (#1042)
1 parent 8a4b57b commit 36ce97f

6 files changed

Lines changed: 123 additions & 59 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
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 \
8+
--quiet \
9+
--abbrev=12 \
10+
--date='format-local:%Y%m%d%H%M%S' \
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 }}

Dockerfile

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
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 && rm /usr/local/bin/install-ctags-alpine.sh
1731

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

20-
COPY install-ctags-alpine.sh .
21-
RUN ./install-ctags-alpine.sh && rm install-ctags-alpine.sh
39+
USER zoekt
40+
WORKDIR /home/zoekt
2241

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

2544
ENTRYPOINT ["/sbin/tini", "--"]
45+
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.

README.md

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

85+
#### Container image
86+
87+
Zoekt publishes a single container image at `ghcr.io/sourcegraph/zoekt`. It
88+
includes the Zoekt binaries, `git`, and `universal-ctags`. By default it runs
89+
`zoekt-webserver` against `/data/index`:
90+
91+
docker run --rm -p 6070:6070 -v "$PWD/index:/data/index" ghcr.io/sourcegraph/zoekt
92+
93+
You can override the default command to run `zoekt-indexserver` instead. This
94+
example stores cloned repositories, logs, and indexes under `/data` and reads a
95+
mounted mirror config file:
96+
97+
docker run --rm \
98+
-v "$PWD/config.json:/config.json:ro" \
99+
-v "$PWD/token.txt:/home/zoekt/token.txt:ro" \
100+
-v "$PWD/zoekt-data:/data" \
101+
ghcr.io/sourcegraph/zoekt \
102+
zoekt-indexserver -mirror_config /config.json -data_dir /data
103+
85104
If you start the web server with `-rpc`, it exposes a [simple JSON search
86105
API](doc/json-api.md) at `http://localhost:6070/api/search`.
87106

0 commit comments

Comments
 (0)