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: 4 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:

jobs:
verify:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4
Expand All @@ -39,18 +39,13 @@ jobs:
- name: Run go test
run: CGO_ENABLED=1 go test -tags "fts5" ./... -count=1

- name: Build release binaries
run: make build

- name: Build Wiki UI
run: make wiki-build
- name: Prepare container artifacts
run: make container-artifacts

- name: Build production image
run: |
docker build \
--build-arg VERSION=ci \
--build-arg COMMIT=${{ github.sha }} \
--build-arg DATE=unknown \
--build-arg TARGETARCH=amd64 \
--tag ccg:ci .

- name: Capture go build JSON
Expand Down
42 changes: 28 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
goos: darwin
goarch: amd64
artifact: ccg-darwin-amd64
- os: ubuntu-latest
- os: ubuntu-24.04
goos: linux
goarch: amd64
artifact: ccg-linux-amd64
- os: ubuntu-latest
- os: ubuntu-24.04
goos: linux
goarch: arm64
artifact: ccg-linux-arm64
Expand Down Expand Up @@ -162,6 +162,32 @@ jobs:
steps:
- uses: actions/checkout@v6

- name: Download Linux AMD64 artifact
uses: actions/download-artifact@v4
with:
name: ccg-linux-amd64
path: artifacts/ccg-linux-amd64

- name: Download Linux ARM64 artifact
uses: actions/download-artifact@v4
with:
name: ccg-linux-arm64
path: artifacts/ccg-linux-arm64

- name: Download Wiki artifact
uses: actions/download-artifact@v4
with:
name: ccg-wiki-dist
path: artifacts/ccg-wiki-dist

- name: Prepare container artifacts
shell: bash
run: |
mkdir -p container-artifacts/amd64 container-artifacts/arm64 container-artifacts/wiki
tar xzf artifacts/ccg-linux-amd64/ccg-linux-amd64.tar.gz -C container-artifacts/amd64
tar xzf artifacts/ccg-linux-arm64/ccg-linux-arm64.tar.gz -C container-artifacts/arm64
tar xzf artifacts/ccg-wiki-dist/ccg-wiki-dist.tar.gz -C container-artifacts/wiki

- name: Set up QEMU
uses: docker/setup-qemu-action@v4

Expand All @@ -187,14 +213,6 @@ jobs:
type=semver,pattern={{major}}
type=raw,value=latest,enable=${{ !contains(github.ref_name, '-') }}

- name: Prepare container build metadata
id: build-meta
shell: bash
run: |
echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
echo "commit=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
echo "date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT"

- name: Build and publish container image
uses: docker/build-push-action@v7
with:
Expand All @@ -203,10 +221,6 @@ jobs:
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
build-args: |
VERSION=${{ steps.build-meta.outputs.version }}
COMMIT=${{ steps.build-meta.outputs.commit }}
DATE=${{ steps.build-meta.outputs.date }}
cache-from: type=gha
cache-to: type=gha,mode=max

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ pyproject.toml
*.db-wal
/web/wiki/dist/
/web/wiki/node_modules/
/container-artifacts/
search-retrieval.md
_workspace/
46 changes: 12 additions & 34 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,19 @@
# Wiki UI build stage
FROM node:22-alpine AS wiki-builder
# Runtime stage packages binaries and Wiki assets prepared by the release workflow.
FROM ubuntu:24.04

WORKDIR /src/web/wiki
COPY web/wiki/package.json web/wiki/package-lock.json ./
RUN npm ci
COPY web/wiki/ ./
RUN npm run build
ARG TARGETARCH=amd64

# Build stage
FROM golang:1.25-alpine AS builder

RUN apk add --no-cache gcc musl-dev git

ARG VERSION=dev
ARG COMMIT=unknown
ARG DATE=unknown

WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN CGO_ENABLED=1 go build -tags "fts5" -ldflags="-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" -o /usr/local/bin/ccg ./cmd/ccg/ \
&& CGO_ENABLED=1 go build -tags "fts5" -ldflags="-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" -o /usr/local/bin/ccg-server ./cmd/ccg-server/

# Runtime stage
FROM alpine:3.21

RUN apk add --no-cache ca-certificates git \
&& addgroup -S ccg \
&& adduser -S -G ccg -h /home/ccg ccg \
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y ca-certificates git wget \
&& groupadd --system ccg \
&& useradd --system --gid ccg --create-home --home-dir /home/ccg ccg \
&& mkdir -p /repo /repos /home/ccg/.cache /home/ccg/.config/ccg \
&& chown -R ccg:ccg /repo /repos /home/ccg
&& chown -R ccg:ccg /repo /repos /home/ccg \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /usr/local/bin/ccg /usr/local/bin/ccg
COPY --from=builder /usr/local/bin/ccg-server /usr/local/bin/ccg-server
COPY --from=wiki-builder /src/web/wiki/dist /usr/share/ccg/wiki
COPY container-artifacts/${TARGETARCH}/ccg /usr/local/bin/ccg
COPY container-artifacts/${TARGETARCH}/ccg-server /usr/local/bin/ccg-server
COPY container-artifacts/wiki /usr/share/ccg/wiki

WORKDIR /repo
USER ccg
Expand Down
22 changes: 21 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ WIKI_ADDR ?= 127.0.0.1:8080
WIKI_DB ?= ccg.db
WIKI_REPO ?= .
WIKI_TOKEN ?=
HOST_GOOS := $(shell go env GOOS)
CONTAINER_ARCH ?= $(shell go env GOARCH)

.PHONY: build release build-debug build-json install vet test test-integration-helpers wiki-build wiki-db wiki-docs wiki-run wiki-run-indexed clean
.PHONY: build release build-debug build-json install vet test test-integration-helpers wiki-build wiki-db wiki-docs wiki-run wiki-run-indexed container-artifacts clean

build: release

Expand Down Expand Up @@ -39,6 +41,24 @@ test-integration-helpers:
wiki-build:
cd web/wiki && npm ci && npm run build

container-artifacts: wiki-build
mkdir -p container-artifacts/$(CONTAINER_ARCH) container-artifacts/wiki
if [ "$(HOST_GOOS)" = "linux" ]; then \
$(MAKE) release; \
else \
docker run --rm --platform linux/$(CONTAINER_ARCH) \
--user "$$(id -u):$$(id -g)" \
-e GOCACHE=/tmp/go-build \
-e VERSION="$(VERSION)" \
-e COMMIT="$(COMMIT)" \
-e DATE="$(DATE)" \
-v "$$(pwd):/src" -w /src golang:1.25-bookworm \
sh -c 'CGO_ENABLED=1 go build -tags "fts5" -ldflags "-s -w -X main.version=$$VERSION -X main.commit=$$COMMIT -X main.date=$$DATE" -o ccg ./cmd/ccg/ && CGO_ENABLED=1 go build -tags "fts5" -ldflags "-s -w -X main.version=$$VERSION -X main.commit=$$COMMIT -X main.date=$$DATE" -o ccg-server ./cmd/ccg-server/'; \
fi
cp ccg container-artifacts/$(CONTAINER_ARCH)/ccg
cp ccg-server container-artifacts/$(CONTAINER_ARCH)/ccg-server
cp -R web/wiki/dist/. container-artifacts/wiki/

wiki-db:
CGO_ENABLED=1 go run -tags "fts5" ./cmd/ccg --db-driver sqlite --db-dsn '$(WIKI_DB)' migrate
CGO_ENABLED=1 go run -tags "fts5" ./cmd/ccg --db-driver sqlite --db-dsn '$(WIKI_DB)' build '$(WIKI_REPO)'
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.integration.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Full-stack integration test: Gitea + PostgreSQL + ccg
# Usage: docker compose -f docker-compose.integration.yml up -d
# Usage: make container-artifacts
# CONTAINER_ARCH=$(go env GOARCH) docker compose -f docker-compose.integration.yml up -d
# ./scripts/integration-test.sh
# docker compose -f docker-compose.integration.yml down -v

Expand Down Expand Up @@ -54,6 +55,8 @@ services:
build:
context: .
dockerfile: Dockerfile
args:
TARGETARCH: ${CONTAINER_ARCH:-amd64}
environment:
- CCG_DB_DRIVER=postgres
- CCG_DB_DSN=host=postgres user=ccg password=ccg dbname=ccg_integration port=5432 sslmode=disable
Expand Down
3 changes: 2 additions & 1 deletion guide/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ MCP initialization and tool responses are strict: malformed JSON, top-level JSON
### Manual Container Management

```bash
docker compose -f docker-compose.integration.yml up -d --build
make container-artifacts
CONTAINER_ARCH="$(go env GOARCH)" docker compose -f docker-compose.integration.yml up -d --build
docker compose -f docker-compose.integration.yml down -v
```

Expand Down
11 changes: 9 additions & 2 deletions guide/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ Each stable release publishes the full semantic version, minor, major, and
## Build Image

```bash
docker build -t ccg .
make container-artifacts
docker build --build-arg TARGETARCH="$(go env GOARCH)" -t ccg .
```

`make container-artifacts` compiles the Linux binaries and Wiki UI once, then
the Dockerfile packages those prepared assets without compiling source. Linux
hosts use the local Go toolchain; other hosts compile the matching Linux
architecture inside `golang:1.25-bookworm`.

## Run as MCP Server

```bash
Expand Down Expand Up @@ -177,6 +183,7 @@ docker compose up -d
The full-stack pipeline test can also be run with Docker Compose. See the [Development Guide](development.md#integration-test) for details.

```bash
docker compose -f docker-compose.integration.yml up -d --build
make container-artifacts
CONTAINER_ARCH="$(go env GOARCH)" docker compose -f docker-compose.integration.yml up -d --build
docker compose -f docker-compose.integration.yml down -v
```
3 changes: 2 additions & 1 deletion guide/ko/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ MCP 초기화 및 도구 응답은 엄격하게 체크됩니다: 잘못된 형
### 수동 컨테이너 관리

```bash
docker compose -f docker-compose.integration.yml up -d --build
make container-artifacts
CONTAINER_ARCH="$(go env GOARCH)" docker compose -f docker-compose.integration.yml up -d --build
docker compose -f docker-compose.integration.yml down -v
```

Expand Down
11 changes: 9 additions & 2 deletions guide/ko/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
## 이미지 빌드 (Build Image)

```bash
docker build -t ccg .
make container-artifacts
docker build --build-arg TARGETARCH="$(go env GOARCH)" -t ccg .
```

`make container-artifacts`는 Linux 바이너리와 Wiki UI를 한 번만 빌드하고,
Dockerfile은 준비된 결과물만 패키징합니다. Linux 호스트에서는 로컬 Go
도구체인을 사용하며, 그 외 호스트에서는 `golang:1.25-bookworm` 컨테이너에서
대상 Linux 아키텍처용 바이너리를 컴파일합니다.

## MCP 서버로 실행 (Run as MCP Server)

```bash
Expand Down Expand Up @@ -151,6 +157,7 @@ docker compose up -d
전체 파이프라인 테스트 또한 Docker Compose로 실행할 수 있습니다. 자세한 내용은 [개발 가이드](development.md#integration-test)를 참조하십시오.

```bash
docker compose -f docker-compose.integration.yml up -d --build
make container-artifacts
CONTAINER_ARCH="$(go env GOARCH)" docker compose -f docker-compose.integration.yml up -d --build
docker compose -f docker-compose.integration.yml down -v
```
Loading
Loading