Skip to content

Commit

Permalink
fix(makefile): update versioning mechanism for OpenTelemetry Collector
Browse files Browse the repository at this point in the history
  • Loading branch information
nslaughter committed Jun 24, 2024
1 parent 8a723fe commit 42dc315
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions collector/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ BASE_SPACE:=$(shell pwd)
BUILD_SPACE:=$(BASE_SPACE)/build
BUCKET_NAME:=lambda-artifacts-$(shell dd if=/dev/random bs=8 count=1 2>/dev/null | od -An -tx1 | tr -d ' \t\n')
LAYER_NAME:=otel-collector
VERSION=$(shell curl -s https://raw.githubusercontent.com/open-telemetry/opentelemetry-collector-contrib/main/versions.yaml | grep 'version:' | head -1 | awk '{print $$2}')
OTELCOL_VERSION="UNSET" # run recipe set-otelcol-version to get this
GIT_SHA=$(shell git rev-parse HEAD)
GOARCH ?= amd64
GOBUILD=GO111MODULE=on CGO_ENABLED=0 installsuffix=cgo go build -trimpath
BUILD_INFO_IMPORT_PATH=main

LDFLAGS=-ldflags "-s -w -X $(BUILD_INFO_IMPORT_PATH).GitHash=$(GIT_SHA) -X $(BUILD_INFO_IMPORT_PATH).Version=$(VERSION) \
LDFLAGS=-ldflags "-s -w -X $(BUILD_INFO_IMPORT_PATH).GitHash=$(GIT_SHA) -X $(BUILD_INFO_IMPORT_PATH).Version=$(OTELCOL_VERSION) \
-X github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter.collectorDistribution=opentelemetry-collector-lambda"

TOOLS_MOD_DIR := ./internal/tools
Expand All @@ -33,11 +33,10 @@ clean:
rm -rf build/

.PHONY: build
build: clean
build: clean set-otelcol-version
@echo Building otel collector extension
mkdir -p $(BUILD_SPACE)/extensions
GOOS=linux GOARCH=$(GOARCH) $(GOBUILD) $(LDFLAGS) -o $(BUILD_SPACE)/extensions .
@$(MAKE) update-collector-version

.PHONY: package
package: build
Expand All @@ -56,11 +55,10 @@ publish-layer: package
aws lambda publish-layer-version --layer-name $(LAYER_NAME) --zip-file fileb://$(BUILD_SPACE)/opentelemetry-collector-layer-$(GOARCH).zip --compatible-runtimes nodejs14.x nodejs16.x nodejs18.x java11 python3.8 python3.9 python3.10 python3.11 --query 'LayerVersionArn' --output text
@echo OpenTelemetry Collector layer published.

.PHONY: update-collector-version
update-collector-version:
@latest_version=$(shell curl -s https://raw.githubusercontent.com/open-telemetry/opentelemetry-collector-contrib/main/versions.yaml | grep 'version:' | head -1 | awk '{print $$2}'); \
echo $$latest_version > VERSION; \
echo "Updated to OpenTelemetry Collector version from $(PRIOR_BUIlD_VERSION) $$latest_version"
.PHONY: set-otelcol-version
set-otelcol-version:
@OTELCOL_VERSION=$$(grep "go.opentelemetry.io/collector/otelcol v" go.mod | awk '{print $$2; exit}'); \
echo $$OTELCOL_VERSION > VERSION; \

.PHONY: gotidy
gotidy:
Expand Down

0 comments on commit 42dc315

Please sign in to comment.