diff --git a/Makefile b/Makefile index 2f3d21a..cbc0b5b 100644 --- a/Makefile +++ b/Makefile @@ -1,79 +1,26 @@ -default: all -GOFLAGS=-ldflags=-w -ldflags=-s -SYNTEST_PLUGIN_SUBDIRS = $(notdir $(wildcard ./agent/plugins/syntests/*)) - -LOCAL_BUILD_PATH=./bin - -## Proto -build-go-proto: - @echo Building Golang proto files... - protoc --go_out=plugins=grpc:common/proto/ common/proto/syntest.proto --proto_path=common/proto/ - -## Agent -build-go-syntest-plugins: - @echo "Building Go syntest plugins" - cd agent && \ - for dir in $(SYNTEST_PLUGIN_SUBDIRS); do \ - echo "Building plugin: $$dir" && \ - CGO_ENABLED=0 go build $(GOFLAGS) -o $(LOCAL_BUILD_PATH)/plugins/test-$$dir ./plugins/syntests/$$dir/ && \ - echo "$$dir compiled!" || { echo "$$dir failed!"; exit 1; }; \ - done - -build-agent-only: - @echo "Building agent" - cd agent && CGO_ENABLED=0 go build $(GOFLAGS) -o $(LOCAL_BUILD_PATH)/agent . - -.PHONY: build-agent -build-agent: build-agent-only build-go-syntest-plugins +default: docker-all docker-agent: @echo "Building agent container image" - cd agent && podman build -f Dockerfile -t synheart-agent:dev_latest .. - -## Rest Api -build-restapi: - @echo "Building restapi binary" - cd restapi && CGO_ENABLED=0 go build $(GOFLAGS) -o $(LOCAL_BUILD_PATH)/restapi . + cd agent && podman build -f Dockerfile-NoPlugins -t synheart-agent:dev-latest-no-plugins .. + cd agent && podman build -f Dockerfile -t synheart-agent:dev-latest .. .PHONY: docker-restapi docker-restapi: @echo "Building restapi container image" - cd restapi && podman build -f Dockerfile -t synheart-restapi:dev_latest .. + cd restapi && podman build -f Dockerfile -t synheart-restapi:dev-latest .. ## Controller .PHONY: docker-controller docker-controller: @echo "Building controller container image" - cd controller && podman build -f Dockerfile -t synheart-controller:dev_latest .. + cd controller && podman build -f Dockerfile -t synheart-controller:dev-latest .. .PHONY : docker-all docker-all: docker-agent docker-restapi docker-controller -#.PHONY : test -#test: build-dummy-test-plugins build-syn-heart -# go test -race -v synthetic-heart/agent -# go test -race -v synthetic-heart/broadcaster - - -## SDK - Creating new syntest plugin -.PHONY : new-go-test -new-go-test: - @echo Creating Directory plugins/syntests/$(name) - mkdir agent/plugins/syntests/$(name) - - @echo Creating file plugins/syntests/$(name)/$(name).go - cp agent/plugins/templates/go/test.tpl.go plugins/syntests/$(name)/$(name).go - - sed -i .backup s/{{TestName}}/$(call capitalize,$(name))/g plugins/syntests/$(name)/$(name).go - rm agent/plugins/syntests/$(name)/$(name).go.backup - - .PHONY : clean clean: rm -rf agent/bin rm -rf controller/bin - rm -rf restapi/bin - -define capitalize -$(shell echo $(1) | awk '{$$1=toupper(substr($$1,0,1))substr($$1,2); print $$0}') -endef + rm -rf restapi/bin \ No newline at end of file diff --git a/agent/Dockerfile b/agent/Dockerfile index b7e4e9b..b8258a0 100644 --- a/agent/Dockerfile +++ b/agent/Dockerfile @@ -4,19 +4,11 @@ FROM docker.io/library/golang:1.22-alpine3.19 as builder # Install git + SSL ca certificates + make -# Git is required for fetching the dependencies. -# Ca-certificates is required to call HTTPS endpoints. -# Make to build go application -ARG TARGETARCH -RUN if [ "$TARGETARCH" = "arm64" ]; then ln -s /bin/run-parts /usr/bin/run-parts; fi RUN apk update && apk upgrade && apk add --no-cache git ca-certificates make unzip g++ && update-ca-certificates && apk --no-cache add openssl wget && rm -rf /var/cache/apk/* # Create appuser RUN adduser -D -g '' appuser -# Install curl -RUN apk add --no-cache curl - # Install protoc RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.20.1/protoc-3.20.1-linux-x86_64.zip RUN unzip protoc-3.20.1-linux-x86_64.zip @@ -38,29 +30,19 @@ COPY . . # Build the binary RUN mkdir -p /app/synthetic-heart/ -RUN touch /app/synthetic-heart/.emptyfile # Compile the binary -RUN make build-agent +RUN cd agent/ && make build-go-syntest-plugins RUN mv agent/bin/* /app/synthetic-heart ############################ -# STEP 2 build a small image with only the executable +# STEP 2 build a small image with only the executables ############################ -FROM gcr.io/distroless/static:nonroot +FROM localhost/synheart-agent:dev-latest-no-plugins # Copy our static executables -COPY --from=builder /app/synthetic-heart /app/synthetic-heart - -# COPY curl for curl syntest -COPY --from=builder /usr/bin/curl /usr/bin/curl - -# Create a /tmp/ diretctory (required for go plugin for Unix Domain Socket) -COPY --from=builder /app/synthetic-heart/.emptyfile /tmp/.emptyfile - -WORKDIR /app/synthetic-heart - -# Run the hello binary. -ENTRYPOINT ["./agent"] +COPY --from=builder /app/synthetic-heart/plugins/* /app/synthetic-heart/plugins/* +# Install CURL for syntest +RUN apk add curl \ No newline at end of file diff --git a/agent/Dockerfile-NoPlugins b/agent/Dockerfile-NoPlugins new file mode 100644 index 0000000..b9c7bb6 --- /dev/null +++ b/agent/Dockerfile-NoPlugins @@ -0,0 +1,56 @@ +############################ +# STEP 1 build the image for creating the executable +############################ +FROM docker.io/library/golang:1.22-alpine3.19 as builder + +# Install git + SSL ca certificates + make +RUN apk update && apk upgrade && apk add --no-cache git ca-certificates make unzip g++ && update-ca-certificates && apk --no-cache add openssl wget && rm -rf /var/cache/apk/* + +# Create appuser +RUN adduser -D -g '' appuser + +# Install protoc +RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.20.1/protoc-3.20.1-linux-x86_64.zip +RUN unzip protoc-3.20.1-linux-x86_64.zip +RUN cp ./bin/protoc /usr/local/bin/protoc +RUN cp -a ./include/. /usr/local/include/ + +# Install GRPC golang-plugin for protoc +RUN go install github.com/golang/protobuf/protoc-gen-go@v1.5.2 + +WORKDIR /app + +COPY agent/go.mod agent/. +COPY agent/go.sum agent/. +COPY common/go.mod common/. +COPY common/go.sum common/. +RUN cd agent && go mod download + +COPY . . + +# Build the binary +RUN mkdir -p /app/synthetic-heart/ +RUN touch /app/synthetic-heart/.emptyfile + +# Compile the binary +RUN cd agent/ && make build-agent-only + +RUN mv agent/bin/* /app/synthetic-heart +RUN mkdir /app/synthetic-heart/plugins + +############################ +# STEP 2 build a small image with only the executable +############################ +FROM docker.io/library/alpine:3.19 + +# Copy our static executables +COPY --from=builder /app/synthetic-heart /app/synthetic-heart + +# Create a /tmp/ diretctory (required for go plugin for Unix Domain Socket) +COPY --from=builder /app/synthetic-heart/.emptyfile /tmp/.emptyfile + +WORKDIR /app/synthetic-heart + +# Run the hello binary. +ENTRYPOINT ["./agent"] + diff --git a/agent/Makefile b/agent/Makefile index 69d5685..472a850 100644 --- a/agent/Makefile +++ b/agent/Makefile @@ -1,3 +1,23 @@ +GOFLAGS=-ldflags=-w -ldflags=-s +SYNTEST_PLUGIN_SUBDIRS = $(notdir $(wildcard ./plugins/syntests/*)) +LOCAL_BUILD_PATH=./bin + +## Agent +build-go-syntest-plugins: + @echo "Building Go syntest plugins" + for dir in $(SYNTEST_PLUGIN_SUBDIRS); do \ + echo "Building plugin: $$dir" && \ + CGO_ENABLED=0 go build $(GOFLAGS) -o $(LOCAL_BUILD_PATH)/plugins/test-$$dir ./plugins/syntests/$$dir/ && \ + echo "$$dir compiled!" || { echo "$$dir failed!"; exit 1; }; \ + done + +build-agent-only: + @echo "Building agent" + CGO_ENABLED=0 go build $(GOFLAGS) -o $(LOCAL_BUILD_PATH)/agent . + +.PHONY: build-agent +build-agent: build-agent-only build-go-syntest-plugins + ## SDK - Creating new syntest plugin .PHONY : new-go-syntest new-go-syntest: diff --git a/agent/README.md b/agent/README.md index 65bb5f4..06895fe 100644 --- a/agent/README.md +++ b/agent/README.md @@ -16,7 +16,15 @@ storage: # External storage configuration type: redis # Type of external storage address: redis:6379 # Address of the external storage buffer: 1000 # The size on import buffer (approximately: no_of_nodes) - exportRate: 15s # How often to export health status of plugins/agent + exportRate: 15s # How often to export health statugracePeriod: 3s # When the agent is exiting, how long to wait to process/export any pending test results +syncFrequency: 30s # How often to poll external storage for new syntest configs + +storage: # External storage configuration + type: redis # Type of external storage + address: redis:6379 # Address of the external storage + buffer: 1000 # The size on import buffer (approximately: no_of_nodes) + exportRate: 15s # How often to export health status of plugins/agent + pollRate: 60s # How often to poll for new test runss of plugins/agent pollRate: 60s # How often to poll for new test runs prometheus: # Whether to run prometheus exporter diff --git a/agent/pluginmanager/pluginManager.go b/agent/pluginmanager/pluginManager.go index 93be37b..1b13f3b 100644 --- a/agent/pluginmanager/pluginManager.go +++ b/agent/pluginmanager/pluginManager.go @@ -88,6 +88,7 @@ func NewPluginManager(configPath string) (*PluginManager, error) { if err != nil { return nil, errors.Wrap(err, "error discovering plugins") } + pm.logger.Info("discovered plugins", "plugins", plugins) pm.config.EnabledPlugins = plugins } // register all the plugins diff --git a/chart/synthetic-heart/values.yaml b/chart/synthetic-heart/values.yaml index 653c394..7f26242 100644 --- a/chart/synthetic-heart/values.yaml +++ b/chart/synthetic-heart/values.yaml @@ -4,7 +4,7 @@ controller: logLevel: INFO image: repository: bakshi41c/synheart-controller - tag: "1715904641" + tag: "v1.2.0-dev2" pullPolicy: IfNotPresent ports: - containerPort: 2112 # For prometheus @@ -28,7 +28,7 @@ agent: exportRate: 15s # How often to export health status of plugins/agent image: repository: bakshi41c/synheart-agent - tag: "1715904641" + tag: "v1.2.0-dev2" pullPolicy: IfNotPresent ports: - containerPort: 2112 # For prometheus @@ -60,7 +60,7 @@ restapi: logLevel: INFO image: repository: bakshi41c/synheart-restapi - tag: "1715904641" + tag: "v1.2.0-dev2" pullPolicy: IfNotPresent annotations: {} ports: diff --git a/push.sh b/push.sh index d4d4b3f..a204bd4 100644 --- a/push.sh +++ b/push.sh @@ -1,8 +1,24 @@ -export TAG=$(date +%s) -podman tag localhost/synheart-controller:dev_latest bakshi41c/synheart-controller:$TAG -podman tag localhost/synheart-restapi:dev_latest bakshi41c/synheart-restapi:$TAG -podman tag localhost/synheart-agent:dev_latest bakshi41c/synheart-agent:$TAG +echo $1 +export TAG=$1 + +podman tag localhost/synheart-controller:dev-latest bakshi41c/synheart-controller:$TAG +podman tag localhost/synheart-restapi:dev-latest bakshi41c/synheart-restapi:$TAG +podman tag localhost/synheart-agent:dev-latest bakshi41c/synheart-agent:$TAG +podman tag localhost/synheart-agent:dev-latest-no-plugins bakshi41c/synheart-agent:$TAG-no-plugins + +podman tag localhost/synheart-controller:dev-latest containers.cisco.com/synthetic-heart/controller:$TAG +podman tag localhost/synheart-restapi:dev-latest containers.cisco.com/synthetic-heart/restapi:$TAG +podman tag localhost/synheart-agent:dev-latest containers.cisco.com/synthetic-heart/agent:$TAG +podman tag localhost/synheart-agent:dev-latest-no-plugins containers.cisco.com/synthetic-heart/agent:$TAG-no-plugins + podman push bakshi41c/synheart-controller:$TAG podman push bakshi41c/synheart-restapi:$TAG podman push bakshi41c/synheart-agent:$TAG -echo $TAG \ No newline at end of file +podman push bakshi41c/synheart-agent:$TAG-no-plugins + +podman push containers.cisco.com/synthetic-heart/controller:$TAG +podman push containers.cisco.com/synthetic-heart/restapi:$TAG +podman push containers.cisco.com/synthetic-heart/agent:$TAG +podman push containers.cisco.com/synthetic-heart/agent:$TAG-no-plugins + +echo $1 \ No newline at end of file diff --git a/restapi/Dockerfile b/restapi/Dockerfile index 2a59307..e1d5440 100644 --- a/restapi/Dockerfile +++ b/restapi/Dockerfile @@ -7,9 +7,7 @@ FROM docker.io/library/golang:1.22-alpine3.19 as builder # Git is required for fetching the dependencies. # Ca-certificates is required to call HTTPS endpoints. # Make to build go application -ARG TARGETARCH -RUN if [ "$TARGETARCH" = "arm64" ]; then ln -s /bin/run-parts /usr/bin/run-parts; fi -RUN apk update && apk add --no-cache git ca-certificates make unzip g++ && update-ca-certificates +RUN apk update && apk upgrade && apk add --no-cache git ca-certificates make unzip g++ && update-ca-certificates && apk --no-cache add openssl wget && rm -rf /var/cache/apk/* # Create appuser RUN adduser -D -g '' appuser @@ -18,7 +16,7 @@ WORKDIR /app COPY . . # Compile the binary -RUN make build-restapi +RUN cd restapi && make build-restapi ############################ # STEP 2 build a small image with only the executable diff --git a/restapi/Makefile b/restapi/Makefile new file mode 100644 index 0000000..f9e55b1 --- /dev/null +++ b/restapi/Makefile @@ -0,0 +1,7 @@ +GOFLAGS=-ldflags=-w -ldflags=-s +LOCAL_BUILD_PATH=./bin + +## Rest Api +build-restapi: + @echo "Building restapi binary" + CGO_ENABLED=0 go build $(GOFLAGS) -o $(LOCAL_BUILD_PATH)/restapi . \ No newline at end of file