diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b344c68..5b9b73f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,10 +26,7 @@ jobs: go-version: '1.26.1' - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y protobuf-compiler - make -C agent setup proto + run: make -C agent install proto - name: Run Agent tests run: make -C agent test @@ -54,10 +51,7 @@ jobs: go-version: '1.26.1' - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y protobuf-compiler - make -C agent setup proto + run: make -C agent install proto - name: Build Agent Local Image run: | diff --git a/Makefile b/Makefile index 0a04bcc..568decb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: setup +all: install make -C agent make -C sdks/python @@ -18,10 +18,11 @@ docker-build: docker/Dockerfile docker build -t $(DOCKER_TAG) --progress=plain -f $< . .PHONY: docker-build -setup: - $(MAKE) -C agent setup +install: + $(MAKE) -C agent install + $(MAKE) -C sdks/python install -.PHONY: setup +.PHONY: install test: $(MAKE) -C agent test diff --git a/agent/Makefile b/agent/Makefile index 8caf507..ac957f7 100644 --- a/agent/Makefile +++ b/agent/Makefile @@ -3,7 +3,7 @@ PYTHON_SDK_DIR = ../sdks/python/ GENERATED_DIR = .generated/proto GENERATED_PATH=$(GENERATED_DIR)/github.com/cortexapps/axon -all: setup proto build test +all: install proto build test PROTO_FILES := $(wildcard proto/*.proto) GO_FILES := $(patsubst proto/%.proto,$(GENERATED_PATH)/%.pb.go,$(PROTO_FILES)) @@ -11,7 +11,7 @@ GO_FILES := $(patsubst proto/%.proto,$(GENERATED_PATH)/%.pb.go,$(PROTO_FILES)) GOPATH ?= $(HOME)/go GOBIN ?= $(GOPATH)/bin -proto: setup $(GO_FILES) version +proto: install $(GO_FILES) version version: $(GO_SDK_DIR)/version/agentversion.txt $(PYTHON_SDK_DIR)/cortex_axon/agentversion.py @@ -33,15 +33,18 @@ $(GENERATED_PATH)/%.pb.go: proto/%.proto @mkdir -p $(GO_SDK_DIR)/.generated @cp -R $(GENERATED_DIR) $(GO_SDK_DIR)/.generated -setup: +install: @if ! command -v $(GOBIN)/protoc-gen-go >/dev/null; then echo "Installing protoc-gen-go..."; go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.6; fi @if ! command -v $(GOBIN)/protoc-gen-go-grpc >/dev/null; then echo "Installing protoc-gen-go-grpc..."; go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1; fi - @if ! which protoc >/dev/null; then \ - if which brew >/dev/null; then \ - brew install protobuf; \ - else \ - apt update && apt install -y protobuf-compiler; \ - fi; \ + @if which brew >/dev/null; then \ + if ! which protoc >/dev/null; then brew install protobuf; fi; \ + elif [ "$$(uname)" = "Linux" ]; then \ + PKGS=""; \ + if ! which protoc >/dev/null; then PKGS="protobuf-compiler"; fi; \ + if ! test -f /usr/include/google/protobuf/timestamp.proto; then PKGS="$$PKGS libprotobuf-dev"; fi; \ + if [ -n "$$PKGS" ]; then sudo apt-get update && sudo apt-get install -y $$PKGS; fi; \ + else \ + echo "WARNING: Unrecognized platform $$(uname) -- not installing protobuf dependencies"; \ fi build: @@ -89,4 +92,4 @@ run: proto go run main.go serve -.PHONY: setup test build +.PHONY: install test build diff --git a/docker/Dockerfile b/docker/Dockerfile index a3c561c..dda830d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -36,7 +36,7 @@ ENV GOPROXY="https://proxy.golang.org,direct" ENV PATH="${GOROOT}/bin:${GOPATH}/bin:${PATH}:/agent" COPY agent/. /build/. -RUN make -C /build setup proto +RUN make -C /build install proto RUN cd /build && go build -o /agent/cortex-axon-agent RUN rm -rf /build diff --git a/sdks/python/Makefile b/sdks/python/Makefile index d36e72f..9120d1f 100644 --- a/sdks/python/Makefile +++ b/sdks/python/Makefile @@ -1,3 +1,7 @@ +# Unset VIRTUAL_ENV to prevent Poetry from using a stale/broken venv +# (e.g. /lsiopy set by container init systems like s6-overlay) +unexport VIRTUAL_ENV + all: clean install proto install: .venv @@ -5,6 +9,10 @@ install: .venv .venv: pyproject.toml @echo "Installing python dependencies" + @if ! which python >/dev/null && which python3 >/dev/null; then \ + echo "python not found, creating python -> python3 symlink..."; \ + sudo ln -sf $$(which python3) /usr/local/bin/python; \ + fi @if ! which poetry >/dev/null; then \ curl -sSL https://install.python-poetry.org | python3 -; \ fi