mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-11 20:05:25 +00:00
For simplicity, move to a single docker container and use supervisord to handle running the processes.
This commit is contained in:
parent
1b34a5274c
commit
0a66eea9ee
10 changed files with 106 additions and 178 deletions
|
|
@ -7,3 +7,4 @@ README.md
|
|||
!.next/static
|
||||
!.next/standalone
|
||||
.git
|
||||
.sourcebot
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -38,3 +38,5 @@ yarn-error.log*
|
|||
next-env.d.ts
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/nextjs
|
||||
|
||||
.sourcebot
|
||||
63
Dockerfile
Normal file
63
Dockerfile
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
FROM node:18-alpine3.19 AS node-alpine
|
||||
FROM golang:1.22.2-alpine3.19 AS go-alpine
|
||||
|
||||
# ------ Build Zoekt ------
|
||||
FROM go-alpine AS zoekt-builder
|
||||
RUN apk add --no-cache ca-certificates
|
||||
WORKDIR /zoekt
|
||||
COPY vendor/zoekt/go.mod vendor/zoekt/go.sum ./
|
||||
RUN go mod download
|
||||
COPY vendor/zoekt ./
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o /cmd/ ./cmd/...
|
||||
|
||||
# ------ Build Web ------
|
||||
FROM node-alpine AS web-builder
|
||||
RUN apk add --no-cache libc6-compat
|
||||
WORKDIR /app
|
||||
COPY package.json yarn.lock* ./
|
||||
RUN yarn --frozen-lockfile
|
||||
COPY . .
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
RUN yarn run build
|
||||
|
||||
# ------ Runner ------
|
||||
FROM node-alpine AS runner
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV DATA_DIR=/data
|
||||
ENV CONFIG_PATH=$DATA_DIR/config.json
|
||||
ENV DATA_CACHE_DIR=$DATA_DIR/.sourcebot
|
||||
|
||||
# Configure dependencies
|
||||
RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget supervisor
|
||||
|
||||
# Configure zoekt
|
||||
COPY vendor/zoekt/install-ctags-alpine.sh .
|
||||
RUN ./install-ctags-alpine.sh && rm install-ctags-alpine.sh
|
||||
RUN mkdir -p ${DATA_CACHE_DIR}
|
||||
COPY --from=zoekt-builder \
|
||||
/cmd/zoekt-git-index \
|
||||
/cmd/zoekt-indexserver \
|
||||
/cmd/zoekt-mirror-github \
|
||||
/cmd/zoekt-mirror-gitiles \
|
||||
/cmd/zoekt-mirror-bitbucket-server \
|
||||
/cmd/zoekt-mirror-gitlab \
|
||||
/cmd/zoekt-mirror-gerrit \
|
||||
/cmd/zoekt-webserver \
|
||||
/usr/local/bin/
|
||||
|
||||
# Configure the webapp
|
||||
COPY --from=web-builder /app/public ./public
|
||||
RUN mkdir .next
|
||||
COPY --from=web-builder /app/.next/standalone ./
|
||||
COPY --from=web-builder /app/.next/static ./.next/static
|
||||
|
||||
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
COPY entrypoint.sh ./entrypoint.sh
|
||||
RUN chmod +x ./entrypoint.sh
|
||||
|
||||
EXPOSE 3000
|
||||
ENV PORT=3000
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
ENTRYPOINT ["/sbin/tini", "--", "./entrypoint.sh"]
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
# @see : https://github.com/vercel/next.js/tree/canary/examples/with-docker
|
||||
FROM node:18-alpine AS base
|
||||
|
||||
# Install dependencies only when needed
|
||||
FROM base AS deps
|
||||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||
RUN apk add --no-cache libc6-compat
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies based on the preferred package manager
|
||||
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
||||
RUN \
|
||||
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
||||
elif [ -f package-lock.json ]; then npm ci; \
|
||||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
||||
else echo "Lockfile not found." && exit 1; \
|
||||
fi
|
||||
|
||||
|
||||
# Rebuild the source code only when needed
|
||||
FROM base AS builder
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
# Next.js collects completely anonymous telemetry data about general usage.
|
||||
# Learn more here: https://nextjs.org/telemetry
|
||||
# Uncomment the following line in case you want to disable telemetry during the build.
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
RUN \
|
||||
if [ -f yarn.lock ]; then yarn run build; \
|
||||
elif [ -f package-lock.json ]; then npm run build; \
|
||||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
||||
else echo "Lockfile not found." && exit 1; \
|
||||
fi
|
||||
|
||||
# Production image, copy all the files and run next
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV=production
|
||||
# Uncomment the following line in case you want to disable telemetry during runtime.
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
COPY --from=builder /app/public ./public
|
||||
|
||||
# Set the correct permission for prerender cache
|
||||
RUN mkdir .next
|
||||
RUN chown nextjs:nodejs .next
|
||||
|
||||
# Automatically leverage output traces to reduce image size
|
||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
|
||||
USER nextjs
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENV PORT=3000
|
||||
|
||||
# server.js is created by next build from the standalone output
|
||||
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
CMD ["node", "server.js"]
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
FROM golang:1.22.2-alpine3.19 AS builder
|
||||
|
||||
RUN apk add --no-cache ca-certificates
|
||||
|
||||
WORKDIR /zoekt
|
||||
|
||||
COPY vendor/zoekt/go.mod vendor/zoekt/go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
COPY vendor/zoekt ./
|
||||
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o /cmd/ ./cmd/...
|
||||
|
||||
FROM alpine:3.19 AS zoekt
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget
|
||||
COPY vendor/zoekt/install-ctags-alpine.sh .
|
||||
RUN ./install-ctags-alpine.sh && rm install-ctags-alpine.sh
|
||||
|
||||
ENV ZOEKT_DATA_CACHE_DIR /zoekt-data/
|
||||
RUN mkdir -p ${ZOEKT_DATA_CACHE_DIR}
|
||||
|
||||
ENV CONFIG_PATH /app/configs/config.json
|
||||
|
||||
COPY entrypoint.zoekt-indexserver.sh ./entrypoint.sh
|
||||
RUN chmod +x ./entrypoint.sh
|
||||
|
||||
COPY --from=builder \
|
||||
/cmd/zoekt-git-index \
|
||||
/cmd/zoekt-indexserver \
|
||||
/cmd/zoekt-mirror-github \
|
||||
/cmd/zoekt-mirror-gitiles \
|
||||
/cmd/zoekt-mirror-bitbucket-server \
|
||||
/cmd/zoekt-mirror-gitlab \
|
||||
/cmd/zoekt-mirror-gerrit \
|
||||
/usr/local/bin/
|
||||
|
||||
ENTRYPOINT ["/sbin/tini", "--", "./entrypoint.sh"]
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
FROM golang:1.22.2-alpine3.19 AS builder
|
||||
|
||||
RUN apk add --no-cache ca-certificates
|
||||
|
||||
WORKDIR /zoekt
|
||||
|
||||
COPY vendor/zoekt/go.mod vendor/zoekt/go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
COPY vendor/zoekt ./
|
||||
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o /cmd/ ./cmd/...
|
||||
|
||||
FROM alpine:3.19 AS zoekt
|
||||
WORKDIR /app
|
||||
RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget
|
||||
|
||||
ENV ZOEKT_DATA_CACHE_DIR /zoekt-data/
|
||||
RUN mkdir -p ${ZOEKT_DATA_CACHE_DIR}
|
||||
|
||||
COPY entrypoint.zoekt-webserver.sh ./entrypoint.sh
|
||||
RUN chmod +x ./entrypoint.sh
|
||||
|
||||
COPY --from=builder \
|
||||
/cmd/zoekt-webserver \
|
||||
/usr/local/bin/
|
||||
|
||||
EXPOSE 6070
|
||||
|
||||
ENTRYPOINT ["/sbin/tini", "--", "./entrypoint.sh"]
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
version: '3'
|
||||
services:
|
||||
sourcebot:
|
||||
build:
|
||||
dockerfile: Dockerfile.sourcebot
|
||||
environment:
|
||||
- ZOEKT_WEBSERVER_URL=http://zoekt-webserver:6070
|
||||
ports:
|
||||
- 3000:3000
|
||||
|
||||
zoekt-indexserver:
|
||||
build:
|
||||
dockerfile: Dockerfile.zoekt-indexserver
|
||||
environment:
|
||||
- GITHUB_TOKEN=${GITHUB_TOKEN}
|
||||
- GITLAB_TOKEN=${GITLAB_TOKEN}
|
||||
- CONFIG_PATH=/app/configs/config.json
|
||||
- ZOEKT_DATA_CACHE_DIR=/zoekt-data/
|
||||
volumes:
|
||||
- ./configs/config.json:/app/configs/config.json:r
|
||||
- zoekt_data_cache:/zoekt-data/
|
||||
|
||||
zoekt-webserver:
|
||||
build:
|
||||
dockerfile: Dockerfile.zoekt-webserver
|
||||
environment:
|
||||
- ZOEKT_DATA_CACHE_DIR=/zoekt-data/
|
||||
volumes:
|
||||
- zoekt_data_cache:/zoekt-data/
|
||||
|
||||
volumes:
|
||||
zoekt_data_cache:
|
||||
|
|
@ -1,6 +1,12 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# Check if the configuration file exists
|
||||
if [ ! -f "$CONFIG_PATH" ]; then
|
||||
echo "Error: Configuration file not found at $CONFIG_PATH. Please check that you mounted a volume to $DATA_DIR, and the volume contains a config.json file at the root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if GITHUB_TOKEN is set
|
||||
if [ -n "$GITHUB_TOKEN" ]; then
|
||||
echo "$GITHUB_TOKEN" > "$HOME/.github-token"
|
||||
|
|
@ -29,4 +35,4 @@ else
|
|||
echo -e "\e[33mWarning: GitLab repositories will not be indexed since GITLAB_TOKEN was not set. If you are not using GitLab, disregard.\e[0m"
|
||||
fi
|
||||
|
||||
exec "zoekt-indexserver" "-data_dir" "${ZOEKT_DATA_CACHE_DIR}" "-mirror_config" "${CONFIG_PATH}"
|
||||
exec supervisord -c /etc/supervisor/conf.d/supervisord.conf
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
exec "zoekt-webserver" "-index" "${ZOEKT_DATA_CACHE_DIR}/index"
|
||||
31
supervisord.conf
Normal file
31
supervisord.conf
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
[supervisord]
|
||||
nodaemon=true
|
||||
logfile=/dev/null
|
||||
logfile_maxbytes=0
|
||||
|
||||
[program:zoekt-indexserver]
|
||||
command=zoekt-indexserver -data_dir %(ENV_DATA_CACHE_DIR)s -mirror_config %(ENV_CONFIG_PATH)s
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startretries=3
|
||||
stdout_logfile=/dev/fd/1
|
||||
stdout_logfile_maxbytes=0
|
||||
redirect_stderr=true
|
||||
|
||||
[program:zoekt-webserver]
|
||||
command=zoekt-webserver -index %(ENV_DATA_CACHE_DIR)s/index
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startretries=3
|
||||
stdout_logfile=/dev/fd/1
|
||||
stdout_logfile_maxbytes=0
|
||||
redirect_stderr=true
|
||||
|
||||
[program:node-server]
|
||||
command=node server.js
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startretries=3
|
||||
stdout_logfile=/dev/fd/1
|
||||
stdout_logfile_maxbytes=0
|
||||
redirect_stderr=true
|
||||
Loading…
Reference in a new issue