Skip to content

Commit 19089d3

Browse files
EItanyaantweiss
andauthored
Cleanup post transfer (#3)
* feat: move agentId to agentRef, change khook-controller -> khook, fix build file Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * parallelize Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * fix workflow Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * feat: rename kind cluster to kagent to make cross work easier Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * move helm into helm folder Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * add helm-version Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * add push-helm-chart Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * update release file, I think it should work Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * use newer version of release job Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * fix: update with new namespaced ref API Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * change links to kagent-dev repo Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * remove unneeded deps Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * fixed the integration test Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * update tests for new typed interfaces Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * Update CRD definitions for agentRef Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> * use correct ref for session Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> --------- Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io> Co-authored-by: Ant Weiss <anton@otomato.io>
1 parent cc02ada commit 19089d3

61 files changed

Lines changed: 915 additions & 672 deletions

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: 25 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ name: CI/CD Pipeline
33
permissions:
44
actions: read
55
contents: read
6-
security-events: write
76

87
on:
98
push:
10-
branches: [ main, develop ]
9+
branches: [ main ]
1110
pull_request:
1211
branches: [ main ]
1312

1413
env:
15-
DOCKER_REGISTRY: otomato
16-
DOCKER_IMAGE: khook
17-
GO_VERSION: '1.21'
14+
# Cache key components for better organization
15+
CACHE_KEY_PREFIX: kagent-v2
16+
BRANCH_CACHE_KEY: ${{ github.head_ref || github.ref_name }}
17+
# Consistent builder configuration
18+
BUILDX_BUILDER_NAME: kagent-builder-v0.23.0
19+
BUILDX_VERSION: v0.23.0
1820

1921
jobs:
2022
test:
@@ -26,8 +28,6 @@ jobs:
2628

2729
- name: Set up Go
2830
uses: actions/setup-go@v4
29-
with:
30-
go-version: ${{ env.GO_VERSION }}
3131

3232
- name: Cache Go modules
3333
uses: actions/cache@v3
@@ -58,100 +58,31 @@ jobs:
5858
flags: unittests
5959
name: codecov-umbrella
6060

61-
build:
62-
name: Build
63-
runs-on: ubuntu-latest
64-
needs: test
65-
steps:
66-
- name: Checkout code
67-
uses: actions/checkout@v4
68-
69-
- name: Set up Go
70-
uses: actions/setup-go@v4
71-
with:
72-
go-version: ${{ env.GO_VERSION }}
73-
74-
- name: Build binary
75-
run: make build
76-
77-
- name: Upload binary artifact
78-
uses: actions/upload-artifact@v4
79-
with:
80-
name: khook-controller
81-
path: bin/manager
82-
8361
docker:
84-
name: Docker Build and Push
62+
services:
63+
registry:
64+
image: registry:2
65+
ports:
66+
- 5001:5000
67+
name: Docker Build
8568
runs-on: ubuntu-latest
86-
needs: [test, build]
87-
if: github.ref == 'refs/heads/main'
8869
steps:
8970
- name: Checkout code
9071
uses: actions/checkout@v4
9172

73+
- name: Set up QEMU
74+
uses: docker/setup-qemu-action@v3
75+
with:
76+
platforms: linux/amd64,linux/arm64
9277
- name: Set up Docker Buildx
9378
uses: docker/setup-buildx-action@v3
94-
95-
- name: Login to Docker Hub
96-
uses: docker/login-action@v3
9779
with:
98-
username: ${{ secrets.DOCKERHUB_USER }}
99-
password: ${{ secrets.DOCKERHUB_PASSWORD }}
100-
101-
- name: Extract metadata
102-
id: meta
103-
uses: docker/metadata-action@v5
104-
with:
105-
images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}
106-
tags: |
107-
type=ref,event=branch
108-
type=ref,event=pr
109-
type=sha,prefix={{branch}}-
110-
type=raw,value=latest,enable={{is_default_branch}}
111-
112-
- name: Build and push Docker image
113-
uses: docker/build-push-action@v5
114-
with:
115-
context: .
80+
name: ${{ env.BUILDX_BUILDER_NAME }}
81+
version: ${{ env.BUILDX_VERSION }}
11682
platforms: linux/amd64,linux/arm64
117-
push: true
118-
tags: |
119-
${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}:${{ github.sha }}
120-
${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}:latest
121-
labels: ${{ steps.meta.outputs.labels }}
122-
cache-from: type=gha
123-
cache-to: type=gha,mode=max
124-
125-
security:
126-
name: Security Scan
127-
runs-on: ubuntu-latest
128-
needs: test
129-
steps:
130-
- name: Checkout code
131-
uses: actions/checkout@v4
132-
133-
- name: Run Gosec Security Scanner
134-
uses: securego/gosec@master
135-
with:
136-
args: './...'
137-
138-
- name: Run Trivy vulnerability scanner
139-
uses: aquasecurity/trivy-action@master
140-
with:
141-
scan-type: 'fs'
142-
scan-ref: '.'
143-
format: 'sarif'
144-
output: 'trivy-results.sarif'
145-
146-
- name: Check for Trivy SARIF file
147-
run: |
148-
if [ ! -f "trivy-results.sarif" ]; then
149-
echo "Trivy results file not found!"
150-
exit 1
151-
fi
152-
153-
- name: Upload Trivy scan results to GitHub Security tab
154-
uses: github/codeql-action/upload-sarif@v3
155-
if: always()
156-
with:
157-
sarif_file: 'trivy-results.sarif'
83+
use: 'true'
84+
driver-opts: network=host
85+
- name: Build Docker image
86+
env:
87+
DOCKER_BUILD_ARGS: --push --platform linux/amd64,linux/arm64
88+
run: make docker-build

.github/workflows/release.yml

Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,102 +3,103 @@ name: Release
33
on:
44
push:
55
tags:
6-
- 'v*'
6+
- "v*.*.*"
77

88
env:
9-
DOCKER_REGISTRY: otomato
10-
DOCKER_IMAGE: khook
11-
GO_VERSION: '1.21'
9+
# Cache key components for better organization
10+
CACHE_KEY_PREFIX: kagent-v2
11+
BRANCH_CACHE_KEY: ${{ github.head_ref || github.ref_name }}
12+
# Consistent builder configuration
13+
BUILDX_BUILDER_NAME: kagent-builder-v0.23.0
14+
BUILDX_VERSION: v0.23.0
15+
DOCKER_REGISTRY: ghcr.io
16+
DOCKER_REPO: kagent-dev/khook
1217

1318
jobs:
14-
release:
15-
name: Create Release
19+
push-images:
20+
services:
21+
registry:
22+
image: registry:2
23+
ports:
24+
- 5001:5000
25+
name: Docker Build
1626
runs-on: ubuntu-latest
1727
steps:
1828
- name: Checkout code
1929
uses: actions/checkout@v4
20-
with:
21-
fetch-depth: 0
2230

23-
- name: Set up Go
24-
uses: actions/setup-go@v4
31+
- name: Set up QEMU
32+
uses: docker/setup-qemu-action@v3
2533
with:
26-
go-version: ${{ env.GO_VERSION }}
27-
28-
- name: Build binaries
29-
run: |
30-
make build
31-
# Build for multiple architectures
32-
GOOS=linux GOARCH=amd64 go build -o bin/manager-linux-amd64 cmd/main.go
33-
GOOS=linux GOARCH=arm64 go build -o bin/manager-linux-arm64 cmd/main.go
34-
GOOS=darwin GOARCH=amd64 go build -o bin/manager-darwin-amd64 cmd/main.go
35-
GOOS=darwin GOARCH=arm64 go build -o bin/manager-darwin-arm64 cmd/main.go
36-
GOOS=windows GOARCH=amd64 go build -o bin/manager-windows-amd64.exe cmd/main.go
37-
34+
platforms: linux/amd64,linux/arm64
3835
- name: Set up Docker Buildx
3936
uses: docker/setup-buildx-action@v3
37+
with:
38+
name: ${{ env.BUILDX_BUILDER_NAME }}
39+
version: ${{ env.BUILDX_VERSION }}
40+
platforms: linux/amd64,linux/arm64
41+
use: 'true'
42+
driver-opts: network=host
4043

41-
- name: Login to Docker Hub
44+
- name: Login to GitHub Container Registry
4245
uses: docker/login-action@v3
4346
with:
44-
username: ${{ secrets.DOCKER_USERNAME }}
45-
password: ${{ secrets.DOCKER_PASSWORD }}
47+
registry: ghcr.io
48+
username: ${{ github.actor }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
- name: Build Docker image
51+
env:
52+
DOCKER_BUILD_ARGS: --push --platform linux/amd64,linux/arm64
53+
run: make docker-build
4654

47-
- name: Extract tag name
48-
id: tag
49-
run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
55+
push-helm-chart:
56+
needs:
57+
- push-images
58+
runs-on: ubuntu-latest
59+
permissions:
60+
contents: read
61+
packages: write
62+
steps:
63+
- name: 'Checkout GitHub Action'
64+
uses: actions/checkout@main
5065

51-
- name: Build and push Docker image
52-
uses: docker/build-push-action@v5
66+
- name: Login to GitHub Container Registry
67+
uses: docker/login-action@v3
5368
with:
54-
context: .
55-
platforms: linux/amd64,linux/arm64
56-
push: true
57-
tags: |
58-
${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}:${{ steps.tag.outputs.tag }}
59-
${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}:latest
60-
cache-from: type=gha
61-
cache-to: type=gha,mode=max
69+
registry: ghcr.io
70+
username: ${{ github.actor }}
71+
password: ${{ secrets.GITHUB_TOKEN }}
72+
- name: Build Helm chart
73+
run: make helm-publish
6274

63-
- name: Generate release manifests
64-
run: |
65-
mkdir -p release
66-
# Generate install manifest
67-
cat > release/install.yaml << EOF
68-
# KHook Controller Installation Manifest
69-
# Version: ${{ steps.tag.outputs.tag }}
70-
---
71-
EOF
72-
cat config/crd/bases/kagent.dev_hooks.yaml >> release/install.yaml
73-
echo "---" >> release/install.yaml
74-
# Add RBAC and deployment manifests here when they exist
75-
76-
# Generate CRD-only manifest
77-
cp config/crd/bases/kagent.dev_hooks.yaml release/crds.yaml
75+
release:
76+
needs:
77+
- push-helm-chart
78+
name: Create Release
79+
runs-on: ubuntu-latest
80+
steps:
81+
- name: Checkout code
82+
uses: actions/checkout@v4
83+
with:
84+
fetch-depth: 0
7885

7986
- name: Create GitHub Release
80-
uses: softprops/action-gh-release@v1
87+
uses: softprops/action-gh-release@v2
88+
if: startsWith(github.ref, 'refs/tags/')
8189
with:
82-
tag_name: ${{ steps.tag.outputs.tag }}
83-
name: Release ${{ steps.tag.outputs.tag }}
8490
draft: false
8591
prerelease: false
8692
generate_release_notes: true
87-
files: |
88-
bin/manager-*
89-
release/install.yaml
90-
release/crds.yaml
91-
body: |
92-
## Docker Images
93-
94-
```bash
95-
docker pull ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}:${{ steps.tag.outputs.tag }}
96-
```
97-
93+
body: |
9894
## Installation
9995
10096
```bash
101-
kubectl apply -f https://github.com/${{ github.repository }}/releases/download/${{ steps.tag.outputs.tag }}/install.yaml
97+
helm install khook-crds oci://ghcr.io/kagent-dev/khook/helm/khook-crds \
98+
--namespace kagent \
99+
--create-namespace
100+
helm install khook oci://ghcr.io/kagent-dev/khook/helm/khook \
101+
--namespace kagent \
102+
--create-namespace
102103
```
103104
104105
## What's Changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ coverage.html
6161
.env.*.local
6262

6363
# Helm charts
64-
charts/*/charts/
65-
charts/*/requirements.lock
64+
helm/*/charts/
65+
helm/*/requirements.lock
6666

6767
# Generated files
6868
*.pb.go

Dockerfile

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
# Build the manager binary
2-
FROM golang:1.24 AS builder
2+
ARG BUILDPLATFORM
3+
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
4+
ARG TARGETARCH
5+
ARG TARGETPLATFORM
6+
# This is used to print the build platform in the logs
7+
ARG BUILDPLATFORM
8+
39

410
WORKDIR /workspace
511
# Copy the Go Modules manifests
612
COPY go.mod go.mod
713
COPY go.sum go.sum
14+
815
# cache deps before building and copying source so that we don't need to re-download as much
916
# and so that source changes don't invalidate our downloaded layer
10-
RUN go mod download
17+
RUN --mount=type=cache,target=/root/go/pkg/mod,rw \
18+
--mount=type=cache,target=/root/.cache/go-build,rw \
19+
go mod download
1120

1221
# Copy the go source
1322
COPY cmd/ cmd/
1423
COPY api/ api/
1524
COPY internal/ internal/
1625

17-
# Build
18-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager cmd/main.go
26+
ARG LDFLAGS
27+
RUN --mount=type=cache,target=/root/go/pkg/mod,rw \
28+
--mount=type=cache,target=/root/.cache/go-build,rw \
29+
echo "Building on $BUILDPLATFORM -> linux/$TARGETARCH" && \
30+
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags "$LDFLAGS" -o manager cmd/main.go
1931

2032
# Use distroless as minimal base image to package the manager binary
2133
# Refer to https://github.com/GoogleContainerTools/distroless for more details
@@ -24,4 +36,11 @@ WORKDIR /
2436
COPY --from=builder /workspace/manager .
2537
USER 65532:65532
2638

39+
ARG VERSION
40+
41+
LABEL org.opencontainers.image.source=https://github.com/kagent-dev/khook
42+
LABEL org.opencontainers.image.description="Khook is the controller for running hooks for agents."
43+
LABEL org.opencontainers.image.authors="Kagent Creators 🤖"
44+
LABEL org.opencontainers.image.version="$VERSION"
45+
2746
ENTRYPOINT ["/manager"]

0 commit comments

Comments
 (0)