Explorar el Código

Feature #TASK_QT-18250 update makefile

Carl hace 8 meses
padre
commit
5b8260f85e

+ 95 - 12
Makefile

@@ -1,6 +1,28 @@
+# 统一的 Makefile - 支持 x86 和 ARM 架构
+# 使用方法:
+#   make ARCH=x86 all          - 构建 x86 版本
+#   make ARCH=arm image        - 构建并推送 ARM 镜像
+#   make ARCH=arm only-build   - 构建 ARM 版本
+
+arch ?= x86
+
+# 根据架构设置变量
+ifeq ($(arch),arm)
+	DOCKER_CONTAINER = euspace-arm
+	IMAGE_TAG_SUFFIX = arm64
+	PLATFORM = linux/arm64
+	DOCKERFILE = Dockerfile.arm64
+else
+	DOCKER_CONTAINER = euspace
+	IMAGE_TAG_SUFFIX = amd64
+	PLATFORM = linux/amd64
+	DOCKERFILE = Dockerfile
+endif
+
 VERSION=0.0.1
 FILTER=
 PARAMS=
+
 # Set debug
 ifeq ($(debug),1)
 PARAMS+=debug=1
@@ -21,35 +43,78 @@ endif
 
 # Set eBPF build kernel
 ifdef kernel
-	PARAMS+= kernel=${kernel}
+	PARAMS+=kernel=${kernel}
 endif
 
 ifdef version
 	VERSION=${version}
+	PARAMS+=version=${version}
 endif
 
 GIT_COMMIT=$(shell git rev-parse --short HEAD)
 BUILD_DATE=$(shell date '+%Y-%m-%d-%H:%M:%S')
-ARCH=$(shell uname -m)
+INNER_ARCH=$(shell uname -m)
 
 # Set Version
-TARGET_FILE=dist/${ARCH}/package_dir/bin/euspace
+TARGET_FILE=dist/${INNER_ARCH}/package_dir/bin/euspace
 GO_LD_FLAGS_VERSION=-X github.com/coroot/coroot-node-agent/flags.AgentVersion=${VERSION}
 GO_LD_FLAGS_GIT_COMMIT=-X github.com/coroot/coroot-node-agent/flags.GitCommit=${GIT_COMMIT}
 GO_LD_FLAGS_BUILD_DATE=-X github.com/coroot/coroot-node-agent/flags.BuildDate=${BUILD_DATE}
 GO_LD_FLAGS=-ldflags="${GO_LD_FLAGS_VERSION} ${GO_LD_FLAGS_GIT_COMMIT} ${GO_LD_FLAGS_BUILD_DATE}"
 
-all: c-build go-build
+# 帮助信息
+help:
+	@echo "Usage: make arch=<x86|arm> <target>"
+	@echo ""
+	@echo "Architecture options (case-insensitive):"
+	@echo "  arch=x86     - Build for x86_64 architecture (default)"
+	@echo "  arch=arm     - Build for ARM64 architecture"
+	@echo ""
+	@echo "Build targets:"
+	@echo "  all          - Build (ebpf-build + go-build)"
+	@echo "  ebpf-build   - Build eBPF components"
+	@echo "  go-build     - Build Go application"
+	@echo "  only-build   - Build only (ebpf-build + go-build)"
+	@echo "  docker-build - Build in containerized environment (for CI/CD)"
+	@echo ""
+	@echo "eBPF kernel parameters (only for ebpf-build):"
+	@echo "  kernel=all   - Build for all supported kernels (512, 506, 420, 416)"
+	@echo "  kernel=512   - Build for kernel 5.12 only"
+	@echo "  kernel=506   - Build for kernel 5.06 only"
+	@echo "  kernel=420   - Build for kernel 4.20 only"
+	@echo "  kernel=416   - Build for kernel 4.16 only"
+	@echo ""
+	@echo "Version parameters (only for go-build / image-build):"
+	@echo "  version=<ver> - Set version number for Go application"
+	@echo "                  version=1.1.2, version=2.0.0, etc."
+	@echo ""
+	@echo "Docker targets:"
+	@echo "  image-build  - Build Docker image"
+	@echo "  image-push   - Push Docker image"
+	@echo "  image        - Build and push image"
+	@echo ""
+	@echo "Examples:"
+	@echo "  make arch=x86 all          - Build for x86"
+	@echo "  make arch=arm image        - Build and push ARM image"
+	@echo "  make arch=arm only-build   - Build ARM version only"
+	@echo "  make ebpf-build kernel=all - Build eBPF for all kernels"
+	@echo "  make ebpf-build kernel=512 - Build eBPF for kernel 5.12 only"
+	@echo "  make go-build version=1.1.2 - Build Go with version 1.1.2"
+	@echo "  make docker-build kernel=all version=1.0 - CI/CD build with all kernels"
 
-build:
-	CGO_ENABLED=1 go build -gcflags="all=-N -l" ${GO_LD_FLAGS} -buildvcs=false -o ${TARGET_FILE}
-c:
-	docker exec -it 62d0676aa0b7 sh -c 'cd /opt/github/euspace/ebpftracer && make all ${PARAMS}'
-c-build: c
+ebpf-build:
+	docker exec -it $(DOCKER_CONTAINER) sh -c 'cd /opt/github/euspace/ebpftracer && make all ${PARAMS}'
 
 go-build:
-	docker exec -it 62d0676aa0b7 bash -c 'cd /opt/github/euspace && source ~/.g/env && make build'
-go: go-build run
+	docker exec -it $(DOCKER_CONTAINER) bash -c 'cd /opt/github/euspace && source ~/.g/env && make build ${PARAMS}'
+
+only-build: ebpf-build go-build
+
+all: only-build
+
+build:
+	CGO_ENABLED=1 go build -gcflags="all=-N -l" ${GO_LD_FLAGS} -buildvcs=false -o ${TARGET_FILE}
+	${TARGET_FILE} -v
 
 run:
 	ssh [email protected] 'cd /opt/github/euspace && CONFIG_ENDPOINT=10.0.16.250:18080 && TRACES_ENDPOINT=http://10.0.16.250:18080/docp/api/v2/data/receive ${FILTER} ./euspace --listen="0.0.0.0:8123"'
@@ -60,4 +125,22 @@ docker-build-go:
 	source ~/.g/env; CGO_ENABLED=1 go build -a -gcflags="all=-N -l" ${GO_LD_FLAGS} -buildvcs=false -o ${TARGET_FILE}
 docker-build: docker-build-c docker-build-go
 	@echo Target file: ${TARGET_FILE}
-	@echo Euspaces build success!
+	@echo Euspaces build success!
+
+# Image configuration
+AGENT_IMAGE_NAME=euspace-agent
+IMAGE_TAG=${VERSION}-dev-$(IMAGE_TAG_SUFFIX)
+IMAGE_FULL=${AGENT_IMAGE_NAME}:${IMAGE_TAG}
+
+image-build:
+	docker build --platform=$(PLATFORM) -t harbor.cloudwise.com/apm/${IMAGE_FULL} -f $(DOCKERFILE) .
+
+image-push:
+	docker push harbor.cloudwise.com/apm/${IMAGE_FULL}
+
+image: only-build image-build image-push
+
+debug:
+	exit
+
+.PHONY: help ebpf-build go-build only-build all docker-build image-build image-push image debug

+ 144 - 0
manifests/amd64/cloudwise-euspace-k8s/cloudwise-euspace-ds.yaml

@@ -0,0 +1,144 @@
+apiVersion: apps/v1
+kind: DaemonSet
+metadata:
+  name: cloudwise-apm-euspace
+  namespace: cloudwise
+spec:
+  selector:
+    matchLabels:
+      app: cloudwise-apm-euspace
+  template:
+    metadata:
+      annotations:
+        container.apparmor.security.beta.kubernetes.io/cloudwise-apm-euspace: unconfined
+      name: cloudwise-apm-euspace
+      namespace: cloudwise
+      labels:
+        app: cloudwise-apm-euspace
+    spec:
+      hostPID: true
+      hostNetwork: true
+      nodeSelector:
+        kubernetes.io/os: linux
+        kubernetes.io/arch: amd64
+      containers:
+        - name: cloudwise-apm-euspace
+          image: harbor.cloudwise.com/apm/euspace-agent:1.5.0-dev-amd64
+          imagePullPolicy: IfNotPresent
+          args: ["--listen", "0.0.0.0:8123", "--cgroupfs-root", "/host/sys/fs/cgroup","--run-in-container"]
+          ports:
+            - containerPort: 8123
+              name: http
+          securityContext:
+            privileged: true
+            runAsUser: 0
+          volumeMounts:
+            - name: sys-fs-cgroup
+              mountPath: /host/sys/fs/cgroup
+              readOnly: true
+            - name: sys-kernel-debug
+              mountPath: /sys/kernel/debug
+              readOnly: true
+            - name: host-usr
+              mountPath: /host/usr
+              readOnly: true
+              mountPropagation: HostToContainer
+            - name: host-var
+              mountPath: /host/var
+              readOnly: false
+              mountPropagation: HostToContainer
+            - name: host-run
+              mountPath: /host/run
+              readOnly: false
+              mountPropagation: HostToContainer
+            - name: host-tmp
+              mountPath: /host/tmp
+              readOnly: false
+              mountPropagation: HostToContainer
+          env:
+            - name: CONFIG_SERVER
+              value: ''
+            - name: DATA_SERVER
+              value: ''
+            - name: DISABLE_E2E_TRACING
+              value: 'false'
+            - name: DISABLE_STACK_TRACING
+              value: 'true'
+            - name: DISABLE_REG_HOST
+              value: 'false'
+            - name: CONSOLE_LOG
+              value: 'true'
+            - name: LOG_LEVEL
+              value: 'info'
+            - name: SEND
+              value: '1'
+            - name: INSECURE_SKIP_VERIFY
+              value: 'true'
+            - name: node_ip
+              valueFrom:
+                fieldRef:
+                  fieldPath: status.hostIP
+      volumes:
+        - name: sys-fs-cgroup
+          hostPath:
+            path: /sys/fs/cgroup
+        - name: sys-kernel-debug
+          hostPath:
+            path: /sys/kernel/debug
+        - name: host-usr
+          hostPath:
+            path: /usr  
+            type: Directory
+        - name: host-var
+          hostPath:
+            path: /var
+            type: Directory
+        - name: host-run
+          hostPath:
+            path: /run
+            type: Directory
+        - name: host-tmp
+          hostPath:
+            path: /tmp
+            type: Directory   
+---
+kind: ClusterRole
+apiVersion: rbac.authorization.k8s.io/v1
+metadata:
+  name: euspace-agent-role
+rules:
+  - apiGroups: [""]
+    resources:
+      - nodes
+      - namespaces
+      - configmaps
+      - services
+      - pods
+      - replicationcontrollers
+    verbs: ["get", "list", "watch"]
+  - apiGroups: ["apps"]
+    resources:
+      - daemonsets
+      - deployments
+      - replicasets
+      - statefulsets
+    verbs: ["get", "list", "watch"]
+  - apiGroups: ["extensions", "networking.k8s.io"]
+    resources: ["ingresses"]
+    verbs: ["get", "list", "watch"]
+  - apiGroups: ["route.openshift.io"]
+    resources: ["routes"]
+    verbs: ["get", "list", "watch"]
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRoleBinding
+metadata:
+  name: cw-agent-view-binding
+subjects:
+  - kind: ServiceAccount
+    name: default
+    namespace: cloudwise
+roleRef:
+  kind: ClusterRole
+  name: euspace-agent-role
+  apiGroup: rbac.authorization.k8s.io

+ 4 - 0
manifests/amd64/cloudwise-euspace-k8s/cloudwise-ns.yaml

@@ -0,0 +1,4 @@
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: cloudwise

+ 149 - 0
manifests/arm/cloudwise-euspace-k8s/cloudwise-euspace-ds.yaml

@@ -0,0 +1,149 @@
+#apiVersion: v1
+#kind: Namespace
+#metadata:
+#  name: cloudwise
+#---
+apiVersion: apps/v1
+kind: DaemonSet
+metadata:
+  name: cloudwise-apm-euspace
+  namespace: cloudwise
+spec:
+  selector:
+    matchLabels:
+      app: cloudwise-apm-euspace
+  template:
+    metadata:
+      annotations:
+        container.apparmor.security.beta.kubernetes.io/cloudwise-apm-euspace: unconfined
+      name: cloudwise-apm-euspace
+      namespace: cloudwise
+      labels:
+        app: cloudwise-apm-euspace
+    spec:
+      hostPID: true
+      hostNetwork: true
+      nodeSelector:
+        kubernetes.io/os: linux
+        kubernetes.io/arch: arm64
+      containers:
+        - name: cloudwise-apm-euspace
+          image: harbor.cloudwise.com/apm/euspace-agent:1.5.0-dev-arm64
+          imagePullPolicy: IfNotPresent
+          args: ["--listen", "0.0.0.0:8123", "--cgroupfs-root", "/host/sys/fs/cgroup","--run-in-container"]
+          ports:
+            - containerPort: 8123
+              name: http
+          securityContext:
+            privileged: true
+            runAsUser: 0
+          volumeMounts:
+            - name: sys-fs-cgroup
+              mountPath: /host/sys/fs/cgroup
+              readOnly: true
+            - name: sys-kernel-debug
+              mountPath: /sys/kernel/debug
+              readOnly: true
+            - name: host-usr
+              mountPath: /host/usr
+              readOnly: true
+              mountPropagation: HostToContainer
+            - name: host-var
+              mountPath: /host/var
+              readOnly: false
+              mountPropagation: HostToContainer
+            - name: host-run
+              mountPath: /host/run
+              readOnly: false
+              mountPropagation: HostToContainer
+            - name: host-tmp
+              mountPath: /host/tmp
+              readOnly: false
+              mountPropagation: HostToContainer
+          env:
+            - name: CONFIG_SERVER
+              value: ''
+            - name: DATA_SERVER
+              value: ''
+            - name: DISABLE_E2E_TRACING
+              value: 'false'
+            - name: DISABLE_STACK_TRACING
+              value: 'true'
+            - name: DISABLE_REG_HOST
+              value: 'false'
+            - name: CONSOLE_LOG
+              value: 'true'
+            - name: LOG_LEVEL
+              value: 'info'
+            - name: SEND
+              value: '1'
+            - name: INSECURE_SKIP_VERIFY
+              value: 'true'
+            - name: node_ip
+              valueFrom:
+                fieldRef:
+                  fieldPath: status.hostIP
+      volumes:
+        - name: sys-fs-cgroup
+          hostPath:
+            path: /sys/fs/cgroup
+        - name: sys-kernel-debug
+          hostPath:
+            path: /sys/kernel/debug
+        - name: host-usr
+          hostPath:
+            path: /usr  
+            type: Directory
+        - name: host-var
+          hostPath:
+            path: /var
+            type: Directory
+        - name: host-run
+          hostPath:
+            path: /run
+            type: Directory
+        - name: host-tmp
+          hostPath:
+            path: /tmp
+            type: Directory   
+---
+kind: ClusterRole
+apiVersion: rbac.authorization.k8s.io/v1
+metadata:
+  name: euspace-agent-role
+rules:
+  - apiGroups: [""]
+    resources:
+      - nodes
+      - namespaces
+      - configmaps
+      - services
+      - pods
+      - replicationcontrollers
+    verbs: ["get", "list", "watch"]
+  - apiGroups: ["apps"]
+    resources:
+      - daemonsets
+      - deployments
+      - replicasets
+      - statefulsets
+    verbs: ["get", "list", "watch"]
+  - apiGroups: ["extensions", "networking.k8s.io"]
+    resources: ["ingresses"]
+    verbs: ["get", "list", "watch"]
+  - apiGroups: ["route.openshift.io"]
+    resources: ["routes"]
+    verbs: ["get", "list", "watch"]
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRoleBinding
+metadata:
+  name: cw-agent-view-binding
+subjects:
+  - kind: ServiceAccount
+    name: default
+    namespace: cloudwise
+roleRef:
+  kind: ClusterRole
+  name: euspace-agent-role
+  apiGroup: rbac.authorization.k8s.io

+ 4 - 0
manifests/arm/cloudwise-euspace-k8s/cloudwise-ns.yaml

@@ -0,0 +1,4 @@
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: cloudwise