Skip to content

Commit 178bd12

Browse files
committed
initial commit
Signed-off-by: Eitan Yarmush <[email protected]>
0 parents  commit 178bd12

Some content is hidden

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

41 files changed

+31036
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CI Build
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
env:
13+
VERSION: v0.0.1-test
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
- name: Set up QEMU
20+
uses: docker/setup-qemu-action@v3
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
with:
24+
platforms: linux/amd64,linux/arm64
25+
version: v0.23.0
26+
use: 'true'
27+
- name: Run make build
28+
env:
29+
DOCKER_BUILDKIT: 1
30+
DOCKER_BUILD_ARGS: >-
31+
--cache-from=type=gha
32+
--cache-to=type=gha,mode=max
33+
--platform=linux/amd64,linux/arm64
34+
--output=type=tar,dest=/dev/null
35+
DOCKER_REPO: "${{ github.repository_owner }}/tools"
36+
DOCKER_BUILDER: "docker buildx"
37+
run: make docker-build
38+
working-directory: ./
39+
40+
go-unit-tests:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@v4
45+
46+
- name: Set up Go
47+
uses: actions/setup-go@v4
48+
with:
49+
go-version: "1.24"
50+
cache: true
51+
52+
- name: Run cmd/main.go tests
53+
working-directory: go
54+
run: |
55+
go test -v ./...

.github/workflows/tag.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Tag and Push
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: 'Version number'
11+
12+
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#release
13+
# GITHUB_SHA = Last commit in the tagged release
14+
# GITHUB_REF = Tag ref of release refs/tags/<tag_name>
15+
jobs:
16+
push-images:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
steps:
22+
- name: 'Checkout GitHub Action'
23+
uses: actions/checkout@main
24+
25+
- name: Login to GitHub Container Registry
26+
uses: docker/login-action@v3
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Set up QEMU
33+
uses: docker/setup-qemu-action@v3
34+
- name: Set up Docker Buildx
35+
uses: docker/setup-buildx-action@v3
36+
37+
- name: 'Build Images'
38+
env:
39+
DOCKER_BUILD_ARGS: "--push --platform linux/amd64,linux/arm64"
40+
DOCKER_BUILDER: "docker buildx"
41+
run: |
42+
# if workflow_dispatch is used, use the version input
43+
if [ -n "${{ github.event.inputs.version }}" ]; then
44+
export VERSION=${{ github.event.inputs.version }}
45+
else
46+
export VERSION=$(echo "$GITHUB_REF" | cut -c12-)
47+
fi
48+
make docker-build
49+
release:
50+
# Only run release after images and helm chart are pushed
51+
# In the future we can take the chart from the helm action,
52+
# and build the CLI beforehand.
53+
needs:
54+
- push-images
55+
runs-on: ubuntu-latest
56+
permissions:
57+
contents: write
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v4
61+
- name: Build
62+
run: |
63+
# if workflow_dispatch is used, use the version input
64+
if [ -n "${{ github.event.inputs.version }}" ]; then
65+
export VERSION=${{ github.event.inputs.version }}
66+
else
67+
export VERSION=$(echo "$GITHUB_REF" | cut -c12-)
68+
fi
69+
make build
70+
- name: Release
71+
uses: softprops/action-gh-release@v2
72+
if: startsWith(github.ref, 'refs/tags/')
73+
with:
74+
files: |
75+
bin/kagent-tools-*

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bin/
2+
.idea/
3+
.vscode/
4+
.DS_Store
5+
.env
6+
.env.local
7+
.env.development.local
8+
.env.test.local
9+
.env.production.local

Dockerfile

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
### STAGE 1: download-tools-cli
2+
ARG BASE_IMAGE_REGISTRY=cgr.dev
3+
FROM $BASE_IMAGE_REGISTRY/chainguard/wolfi-base:latest AS tools
4+
5+
ENV LANG=C.UTF-8
6+
ENV LC_ALL=C.UTF-8
7+
8+
RUN apk update && apk add \
9+
curl openssl bash git ca-certificates \
10+
&& rm -rf /var/cache/apk/*
11+
12+
ARG TARGETARCH
13+
ARG TOOLS_HELM_VERSION
14+
ARG TOOLS_ISTIO_VERSION
15+
ARG TOOLS_ARGO_ROLLOUTS_VERSION
16+
ARG TOOLS_KUBECTL_VERSION
17+
18+
WORKDIR /downloads
19+
20+
RUN curl -LO "https://dl.k8s.io/release/v$TOOLS_KUBECTL_VERSION/bin/linux/$TARGETARCH/kubectl" \
21+
&& chmod +x kubectl \
22+
&& /downloads/kubectl version --client
23+
24+
RUN curl -L https://istio.io/downloadIstio | ISTIO_VERSION=$TOOLS_ISTIO_VERSION TARGET_ARCH=$TARGETARCH sh - \
25+
&& mv istio-*/bin/istioctl /downloads/ \
26+
&& rm -rf istio-* \
27+
&& /downloads/istioctl --help
28+
29+
# Install Helm
30+
RUN curl -Lo helm.tar.gz https://get.helm.sh/helm-v${TOOLS_HELM_VERSION}-linux-${TARGETARCH}.tar.gz \
31+
&& tar -xvf helm.tar.gz \
32+
&& mv linux-${TARGETARCH}/helm /downloads/helm \
33+
&& chmod +x /downloads/helm \
34+
&& /downloads/helm version
35+
36+
# Install kubectl-argo-rollouts
37+
RUN curl -Lo /downloads/kubectl-argo-rollouts https://github.com/argoproj/argo-rollouts/releases/download/v${TOOLS_ARGO_ROLLOUTS_VERSION}/kubectl-argo-rollouts-linux-${TARGETARCH} \
38+
&& chmod +x /downloads/kubectl-argo-rollouts \
39+
&& /downloads/kubectl-argo-rollouts version
40+
41+
### STAGE 2: build-tools MCP
42+
ARG BASE_IMAGE_REGISTRY=cgr.dev
43+
FROM --platform=linux/$BUILDARCH $BASE_IMAGE_REGISTRY/chainguard/go:latest AS builder
44+
45+
ARG TARGETPLATFORM
46+
ARG TARGETARCH
47+
ARG LDFLAGS
48+
49+
WORKDIR /workspace
50+
51+
# Copy the Go Modules manifests
52+
COPY go.mod go.mod
53+
COPY go.sum go.sum
54+
55+
# cache deps before building and copying source so that we don't need to re-download as much
56+
# and so that source changes don't invalidate our downloaded layer
57+
RUN --mount=type=cache,target=/root/go/pkg/mod,rw \
58+
--mount=type=cache,target=/root/.cache/go-build,rw \
59+
go mod download
60+
61+
# Copy the go source
62+
COPY cmd cmd
63+
COPY internal internal
64+
COPY pkg pkg
65+
66+
# Build
67+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
68+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
69+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
70+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
71+
RUN --mount=type=cache,target=/root/go/pkg/mod,rw \
72+
--mount=type=cache,target=/root/.cache/go-build,rw \
73+
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags "$LDFLAGS" -o tool-server cmd/main.go
74+
75+
# Use distroless as minimal base image to package the manager binary
76+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
77+
FROM gcr.io/distroless/static:nonroot
78+
79+
WORKDIR /
80+
USER 65532:65532
81+
ENV PATH=$PATH:/bin
82+
83+
# Copy the tools
84+
COPY --from=tools --chown=65532:65532 /downloads/kubectl /bin/kubectl
85+
COPY --from=tools --chown=65532:65532 /downloads/istioctl /bin/istioctl
86+
COPY --from=tools --chown=65532:65532 /downloads/helm /bin/helm
87+
COPY --from=tools --chown=65532:65532 /downloads/kubectl-argo-rollouts /bin/kubectl-argo-rollouts
88+
# Copy the tool-server binary
89+
COPY --from=builder --chown=65532:65532 /workspace/tool-server /tool-server
90+
91+
ARG VERSION
92+
93+
LABEL org.opencontainers.image.source=https://github.com/kagent-dev/tools
94+
LABEL org.opencontainers.image.description="Kagent MCP tools server"
95+
LABEL org.opencontainers.image.authors="Kagent Creators 🤖"
96+
LABEL org.opencontainers.image.version="$VERSION"
97+
98+
ENTRYPOINT ["/tool-server"]

Makefile

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
DOCKER_REGISTRY ?= ghcr.io
2+
BASE_IMAGE_REGISTRY ?= cgr.dev
3+
DOCKER_REPO ?= kagent-dev/kagent
4+
5+
BUILD_DATE := $(shell date -u '+%Y-%m-%d')
6+
GIT_COMMIT := $(shell git rev-parse --short HEAD || echo "unknown")
7+
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null | sed 's/-dirty//' | grep v || echo "v0.0.0-$(GIT_COMMIT)")
8+
9+
# Version information for the build
10+
LDFLAGS := "-X github.com/kagent-dev/tools/internal/version.Version=$(VERSION) \
11+
-X github.com/kagent-dev/tools/internal/version.GitCommit=$(GIT_COMMIT) \
12+
-X github.com/kagent-dev/tools/internal/version.BuildDate=$(BUILD_DATE)"
13+
14+
.PHONY: fmt
15+
fmt: ## Run go fmt against code.
16+
go fmt ./...
17+
18+
.PHONY: vet
19+
vet: ## Run go vet against code.
20+
go vet ./...
21+
22+
.PHONY: lint
23+
lint: golangci-lint ## Run golangci-lint linter
24+
$(GOLANGCI_LINT) run
25+
26+
.PHONY: lint-fix
27+
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
28+
$(GOLANGCI_LINT) run --fix
29+
30+
.PHONY: lint-config
31+
lint-config: golangci-lint ## Verify golangci-lint linter configuration
32+
$(GOLANGCI_LINT) config verify
33+
34+
35+
bin/kagent-tools-linux-amd64:
36+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o bin/kagent-tools-linux-amd64 ./cmd
37+
38+
bin/kagent-tools-linux-amd64.sha256: bin/kagent-tools-linux-amd64
39+
sha256sum bin/kagent-tools-linux-amd64 > bin/kagent-tools-linux-amd64.sha256
40+
41+
bin/kagent-tools-linux-arm64:
42+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o bin/kagent-tools-linux-arm64 ./cmd
43+
44+
bin/kagent-tools-linux-arm64.sha256: bin/kagent-tools-linux-arm64
45+
sha256sum bin/kagent-tools-linux-arm64 > bin/kagent-tools-linux-arm64.sha256
46+
47+
bin/kagent-tools-darwin-amd64:
48+
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o bin/kagent-tools-darwin-amd64 ./cmd
49+
50+
bin/kagent-tools-darwin-amd64.sha256: bin/kagent-tools-darwin-amd64
51+
sha256sum bin/kagent-tools-darwin-amd64 > bin/kagent-tools-darwin-amd64.sha256
52+
53+
bin/kagent-tools-darwin-arm64:
54+
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o bin/kagent-tools-darwin-arm64 ./cmd
55+
56+
bin/kagent-tools-darwin-arm64.sha256: bin/kagent-tools-darwin-arm64
57+
sha256sum bin/kagent-tools-darwin-arm64 > bin/kagent-tools-darwin-arm64.sha256
58+
59+
bin/kagent-tools-windows-amd64.exe:
60+
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o bin/kagent-tools-windows-amd64.exe ./cmd
61+
62+
bin/kagent-tools-windows-amd64.exe.sha256: bin/kagent-tools-windows-amd64.exe
63+
sha256sum bin/kagent-tools-windows-amd64.exe > bin/kagent-tools-windows-amd64.exe.sha256
64+
65+
.PHONY: build
66+
build: bin/kagent-tools-linux-amd64.sha256 bin/kagent-tools-linux-arm64.sha256 bin/kagent-tools-darwin-amd64.sha256 bin/kagent-tools-darwin-arm64.sha256 bin/kagent-tools-windows-amd64.exe.sha256
67+
68+
TOOLS_IMAGE_NAME ?= tools
69+
TOOLS_IMAGE_TAG ?= $(VERSION)
70+
TOOLS_IMG ?= $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(TOOLS_IMAGE_NAME):$(TOOLS_IMAGE_TAG)
71+
72+
RETAGGED_DOCKER_REGISTRY = cr.kagent.dev
73+
RETAGGED_TOOLS_IMG = $(RETAGGED_DOCKER_REGISTRY)/$(DOCKER_REPO)/$(TOOLS_IMAGE_NAME):$(TOOLS_IMAGE_TAG)
74+
75+
LOCALARCH ?= $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
76+
77+
DOCKER_BUILDER ?= docker
78+
DOCKER_BUILD_ARGS ?= --pull --load --platform linux/$(LOCALARCH)
79+
80+
TOOLS_ISTIO_VERSION ?= 1.26.1
81+
TOOLS_ARGO_ROLLOUTS_VERSION ?= 1.8.3
82+
TOOLS_KUBECTL_VERSION ?= 1.33.2
83+
TOOLS_HELM_VERSION ?= 3.18.3
84+
85+
# build args
86+
TOOLS_IMAGE_BUILD_ARGS = --build-arg VERSION=$(VERSION)
87+
TOOLS_IMAGE_BUILD_ARGS += --build-arg LDFLAGS=$(LDFLAGS)
88+
TOOLS_IMAGE_BUILD_ARGS += --build-arg TOOLS_ISTIO_VERSION=$(TOOLS_ISTIO_VERSION)
89+
TOOLS_IMAGE_BUILD_ARGS += --build-arg TOOLS_ARGO_ROLLOUTS_VERSION=$(TOOLS_ARGO_ROLLOUTS_VERSION)
90+
TOOLS_IMAGE_BUILD_ARGS += --build-arg TOOLS_KUBECTL_VERSION=$(TOOLS_KUBECTL_VERSION)
91+
TOOLS_IMAGE_BUILD_ARGS += --build-arg TOOLS_HELM_VERSION=$(TOOLS_HELM_VERSION)
92+
93+
.PHONY: docker-build # build tools image
94+
docker-build:
95+
$(DOCKER_BUILDER) build $(DOCKER_BUILD_ARGS) $(TOOLS_IMAGE_BUILD_ARGS) -f Dockerfile ./

0 commit comments

Comments
 (0)