mirror of
https://github.com/imjasonh/git-k8s
synced 2026-07-09 07:06:52 +00:00
- Remove Setup Knative step: the project only uses knative.dev/pkg as a Go library for the controller framework, not Knative Serving/Eventing. This eliminates the slowest setup step entirely. - Create config-logging and config-observability ConfigMaps directly, which is all knative.dev/pkg/injection/sharedmain needs at runtime. - Deploy Gitea in parallel with ko controller builds instead of sequentially, so both can start at the same time. - Combine the "wait for controllers" and "wait for Gitea" steps into one. - Reduce Gitea readiness probe initialDelaySeconds from 10s to 3s and periodSeconds from 5s to 3s. - Reduce Gitea API wait loop sleep from 2s to 1s. - Reduce e2e test poll interval from 2s to 1s for faster feedback. https://claude.ai/code/session_018itccL4SXV3eD7iuPwLGYa
214 lines
6.2 KiB
YAML
214 lines
6.2 KiB
YAML
name: CI
|
|
|
|
on:
|
|
pull_request:
|
|
branches: ["main"]
|
|
push:
|
|
branches: ["main"]
|
|
|
|
jobs:
|
|
build:
|
|
name: Build
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go.mod
|
|
cache-dependency-path: go.mod
|
|
|
|
- name: Go mod tidy
|
|
run: go mod tidy
|
|
|
|
- name: Build all binaries
|
|
run: |
|
|
go build ./cmd/push-controller/
|
|
go build ./cmd/sync-controller/
|
|
go build ./cmd/resolver-controller/
|
|
|
|
- name: Test
|
|
run: go test ./...
|
|
|
|
- name: Vet
|
|
run: go vet ./...
|
|
|
|
e2e:
|
|
name: e2e
|
|
runs-on: ubuntu-latest
|
|
|
|
env:
|
|
KO_DOCKER_REPO: registry.local:5000/git-k8s
|
|
GOFLAGS: "-mod=mod"
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go.mod
|
|
cache-dependency-path: go.mod
|
|
|
|
- name: Setup KinD
|
|
id: kind
|
|
uses: chainguard-dev/actions/setup-kind@main
|
|
with:
|
|
k8s-version: 1.33.x
|
|
|
|
- name: Install ko
|
|
uses: ko-build/setup-ko@v0.9
|
|
|
|
- name: Go mod tidy
|
|
run: go mod tidy
|
|
|
|
- name: Install CRDs
|
|
run: kubectl apply -f config/crds/
|
|
|
|
- name: Deploy RBAC and controller config
|
|
run: |
|
|
kubectl create namespace git-system || true
|
|
kubectl apply -f config/rbac/
|
|
# Create ConfigMaps required by knative.dev/pkg controller runtime.
|
|
kubectl create configmap config-logging -n git-system || true
|
|
kubectl create configmap config-observability -n git-system || true
|
|
|
|
- name: Deploy controllers and Gitea
|
|
run: |
|
|
# Deploy controllers and Gitea in parallel.
|
|
ko apply -f config/deployments/ &
|
|
KO_PID=$!
|
|
|
|
kubectl apply -f - <<'EOF'
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: gitea
|
|
namespace: git-system
|
|
spec:
|
|
replicas: 1
|
|
selector:
|
|
matchLabels:
|
|
app: gitea
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: gitea
|
|
spec:
|
|
containers:
|
|
- name: gitea
|
|
image: gitea/gitea:1.21-rootless
|
|
ports:
|
|
- containerPort: 3000
|
|
name: http
|
|
env:
|
|
- name: GITEA__database__DB_TYPE
|
|
value: sqlite3
|
|
- name: GITEA__security__INSTALL_LOCK
|
|
value: "true"
|
|
readinessProbe:
|
|
httpGet:
|
|
path: /api/v1/version
|
|
port: 3000
|
|
initialDelaySeconds: 3
|
|
periodSeconds: 3
|
|
resources:
|
|
requests:
|
|
cpu: 100m
|
|
memory: 256Mi
|
|
volumeMounts:
|
|
- name: data
|
|
mountPath: /var/lib/gitea
|
|
- name: config
|
|
mountPath: /etc/gitea
|
|
volumes:
|
|
- name: data
|
|
emptyDir: {}
|
|
- name: config
|
|
emptyDir: {}
|
|
EOF
|
|
kubectl apply -f - <<'EOF'
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: gitea
|
|
namespace: git-system
|
|
spec:
|
|
selector:
|
|
app: gitea
|
|
ports:
|
|
- port: 3000
|
|
targetPort: 3000
|
|
name: http
|
|
EOF
|
|
|
|
# Wait for ko build to finish.
|
|
wait $KO_PID
|
|
|
|
- name: Wait for controllers and Gitea
|
|
run: |
|
|
# Wait for everything in parallel.
|
|
for deploy in push-controller sync-controller resolver-controller gitea; do
|
|
echo "Waiting for ${deploy}..."
|
|
kubectl rollout status deployment/${deploy} \
|
|
--namespace=git-system --timeout=120s
|
|
done
|
|
# Verify Gitea API is responsive.
|
|
for i in $(seq 1 15); do
|
|
if kubectl exec -n git-system deploy/gitea -- \
|
|
curl -sf http://localhost:3000/api/v1/version; then
|
|
echo ""
|
|
echo "Gitea API is ready"
|
|
break
|
|
fi
|
|
echo "Waiting for Gitea API (attempt $i)..."
|
|
sleep 1
|
|
done
|
|
|
|
- name: Create Gitea admin user
|
|
run: |
|
|
kubectl exec -n git-system deploy/gitea -- \
|
|
gitea admin user create \
|
|
--admin \
|
|
--username testadmin \
|
|
--password testpassword123 \
|
|
--email admin@test.local \
|
|
--must-change-password=false
|
|
|
|
- name: Run e2e tests
|
|
run: |
|
|
# Port-forward Gitea so Go tests can reach it from the runner.
|
|
kubectl port-forward -n git-system svc/gitea 3000:3000 &
|
|
PF_PID=$!
|
|
# Wait for port-forward to be ready.
|
|
for i in $(seq 1 15); do
|
|
if curl -sf http://localhost:3000/api/v1/version > /dev/null 2>&1; then
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
GITEA_URL=http://localhost:3000 \
|
|
GITEA_INTERNAL_URL=http://gitea.git-system.svc.cluster.local:3000 \
|
|
go test -v -count=1 -timeout=10m -tags=e2e ./test/e2e/
|
|
|
|
kill $PF_PID 2>/dev/null || true
|
|
|
|
- name: Collect diagnostics
|
|
if: ${{ failure() }}
|
|
run: |
|
|
echo "=== Controller logs ==="
|
|
for ctrl in push-controller sync-controller resolver-controller; do
|
|
echo "--- ${ctrl} ---"
|
|
kubectl logs -n git-system deploy/${ctrl} --tail=50 2>/dev/null || true
|
|
done
|
|
echo "=== CRD resources ==="
|
|
kubectl get gitrepositories,gitbranches,gitpushtransactions,gitreposyncs -A -o yaml 2>/dev/null || true
|
|
|
|
- name: Collect KinD diagnostics
|
|
if: ${{ failure() }}
|
|
uses: chainguard-dev/actions/kind-diag@main
|
|
with:
|
|
artifact-name: kind-logs
|
|
cluster-resources: nodes,namespaces,crds
|
|
namespace-resources: pods,deployments,services,gitrepositories,gitbranches,gitpushtransactions,gitreposyncs
|