Skip to content
Draft

wip #813

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions sidecar/otelcol/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
bin/
cmd/
dist/
builder-config.yaml
92 changes: 0 additions & 92 deletions sidecar/otelcol/.goreleaser.yaml

This file was deleted.

86 changes: 79 additions & 7 deletions sidecar/otelcol/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,80 @@
# Prepare the necessary directories in an Alpine container where we have the necessary tooling
FROM alpine:3.21.3 AS directories
RUN mkdir /etc/otel/
RUN mkdir /var/lib/otc
RUN touch /var/log/otelcol.log
ARG ALPINE_VERSION=3.22.1
ARG GO_VERSION=1.24.5
ARG OCB_VERSION=0.130.0
ARG YQ_VERSION=4.46.1

#################################################################################
# Set version information in builder config.
#################################################################################
FROM mikefarah/yq:${YQ_VERSION} AS config

ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG VERSION
ARG OCB_VERSION

RUN echo "I am running on ${BUILDPLATFORM}, building for ${TARGETPLATFORM}"

# Temporarily switch to root to install required packages
USER root
# hadolint ignore=DL3018
RUN apk add --no-cache bash
USER yq

WORKDIR /workdir

# Copy the builder template and generate builder config script to the stage
COPY builder-template.yaml builder-template.yaml
COPY generate-builder-config.sh /usr/local/bin/generate-builder-config.sh

ENV DIST_VERSION=${VERSION}
ENV OT_VERSION=${OCB_VERSION}

RUN generate-builder-config.sh

#################################################################################
# Generate the collector source.
#################################################################################
FROM otel/opentelemetry-collector-builder:${OCB_VERSION} AS source

# Temporarily switch to root to install required packages
USER root
# hadolint ignore=DL3018
RUN apk add --no-cache git
USER ocb

WORKDIR /build

# Copy the builder config
COPY --from=config /workdir/builder-config.yaml /build/config.yaml

RUN ocb --config=config.yaml --skip-compilation=true

#################################################################################
# Build the collector.
#################################################################################
FROM golang:${GO_VERSION} AS builder

WORKDIR /go

# Copy the collector source code
COPY --from=source --chown=root:root /build/cmd .

ENV CGO_ENABLED=0

RUN go build .

#################################################################################
# Prepare the necessary directories in an Alpine container where we have the
# necessary tooling.
#################################################################################
FROM alpine:${ALPINE_VERSION} AS directories
RUN mkdir /etc/otel /var/lib/otc && touch /var/log/otelcol.log

#################################################################################
# Build a minimal image from scratch, copying over the binary & directories from
# the previous stages.
#################################################################################
FROM scratch

ARG USER_UID=10001
Expand All @@ -13,9 +84,10 @@ COPY --from=directories --chown=${USER_UID}:${USER_UID} /etc/otel/ /etc/otel/
COPY --from=directories --chown=${USER_UID}:${USER_UID} /var/lib/otc /var/lib/otc
COPY --from=directories --chown=${USER_UID}:${USER_UID} /var/log/otelcol.log /var/log/otelcol.log

# copy the default tailing-sidecar configuration file
COPY --from=builder /go/sidecar /otelcol

# Copy the default tailing-sidecar configuration file
COPY ./config.yaml /etc/otel/config.yaml

COPY otelcol-sidecar /otelcol
ENTRYPOINT ["/otelcol"]
CMD ["--config", "/etc/otel/config.yaml"]
93 changes: 16 additions & 77 deletions sidecar/otelcol/Makefile
Original file line number Diff line number Diff line change
@@ -1,87 +1,26 @@
BINARY_NAME ?= otelcol-sidecar
OTELCOL_VERSION ?= 0.90.1
BUILDER_REPO ?= github.com/open-telemetry/opentelemetry-collector
GO ?= go

OS ?= $(shell uname -s | tr A-Z a-z)
ARCH ?= $(shell uname -m | sed s/aarch64/arm64/ | sed s/x86_64/amd64/)
LOCALBIN ?= $(shell pwd)/bin

GORELEASER ?= $(LOCALBIN)/goreleaser

BUILDER_BIN_NAME ?= opentelemetry-collector-builder$(BUILDER_BIN_EXT)
BUILDER_BIN_PATH ?= $(LOCALBIN)
BUILDER=$(BUILDER_BIN_PATH)/$(BUILDER_BIN_NAME)

INSTALLED_VERSION := $(shell $(BUILDER) version 2>&1)

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
go get -d $(2)@$(3) ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef

.PHONY: install-builder
install-builder:
@mkdir -p "$(BUILDER_BIN_PATH)"
curl -L -o "$(BUILDER_BIN_PATH)/$(BUILDER_BIN_NAME)" https://$(BUILDER_REPO)/releases/download/cmd/builder/v$(OTELCOL_VERSION)/ocb_$(OTELCOL_VERSION)_$(OS)_$(ARCH)$(BUILDER_BIN_EXT)
@chmod +x "$(BUILDER_BIN_PATH)/$(BUILDER_BIN_NAME)"
@$(MAKE) ensure-correct-builder-version

.PHONY: install-goreleaser
install-goreleaser:
$(call go-get-tool,$(GORELEASER),github.com/goreleaser/goreleaser,latest)


.PHONY: ensure-correct-builder-version
ensure-correct-builder-version:
ifneq ($(lastword $(INSTALLED_VERSION)),$(OTELCOL_VERSION))
@$(error Installed opentelemetry-collector-builder version \
"$(INSTALLED_VERSION)" \
does not match the requested "$(OTELCOL_VERSION)" \
Please check if "$(BUILDER_BIN_PATH)" can be found in your PATH \
and if not, then install it using 'make install-builder' from otelcolbuilder's directory\
)
endif
DOCKER ?= docker

.PHONY: build
build: ensure-correct-builder-version install-goreleaser
@$(GORELEASER) release --snapshot --clean
build: TARGET ?= local
build: export TAG = $(shell git describe --tags --always)
build: export VERSION = $(TAG:v%=%)
build:
$(DOCKER) bake $(TARGET)

.PHONY: release-dev
release-dev: TAG = $(shell git describe --tags --always)
release-dev: ensure-correct-builder-version install-goreleaser
git tag "$(TAG)"
GORELEASER_CURRENT_TAG=$(TAG) \
ECR_IMAGE=public.ecr.aws/sumologic/tailing-sidecar-otel-dev \
GHCR_IMAGE=ghcr.io/sumologic/tailing-sidecar-otel \
DOCKERHUB_IMAGE=sumologic/tailing-sidecar-otel-dev \
make release
git tag -d "$(TAG)"
release-dev:
make build TARGET=dev

.PHONY: release
release: ensure-correct-builder-version install-goreleaser
@$(GORELEASER) release --clean
release:
make build TARGET=prod

.PHONY: build-test-image
build-test-image: GHCR_IMAGE = ghcr.io/sumologic/tailing-sidecar-otel
build-test-image: build
docker tag $(GHCR_IMAGE):main-$(ARCH) $(TAG)

.PHONY: generate-sources
generate-sources:
$(BUILDER) \
--go $(GO) \
--version "$(VERSION)" \
--config .otelcol-builder.yaml \
--skip-compilation=true
build-test-image:
make build TARGET=test

.PHONY: print-tag
print-tag: TAG = $(shell git describe --tags --always)
print-tag:
@echo $(TAG)
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,23 @@ dist:
# the module name for the new distribution, following Go mod conventions. Optional, but recommended.
module: github.com/SumoLogic/tailing-sidecar/sidecar
# the OpenTelemetry Collector version to use as base for the distribution.
otelcol_version: 0.90.1
version: ${DIST_VERSION}
# the path to write the output (sources and binary).
output_path: ./cmd

exporters:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter v0.90.1
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter v${OT_VERSION}

# Note: These components aren't strictly necessary, but they don't measurably increase the binary size
processors:
- gomod: go.opentelemetry.io/collector/processor/batchprocessor v0.90.1
- gomod: go.opentelemetry.io/collector/processor/memorylimiterprocessor v0.90.1
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/groupbyattrsprocessor v0.90.1
- gomod: go.opentelemetry.io/collector/processor/batchprocessor v${OT_VERSION}
- gomod: go.opentelemetry.io/collector/processor/memorylimiterprocessor v${OT_VERSION}
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/groupbyattrsprocessor v${OT_VERSION}

receivers:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver v0.90.1
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver v${OT_VERSION}

extensions:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension v0.90.1
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage v0.90.1
import: github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/filestorage
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding v0.90.1
import: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension

# Replacement paths are relative to the output_path (location of source files)
replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter => github.com/SumoLogic/opentelemetry-collector-contrib/exporter/fileexporter 687035f9f64c57e96d74d523b398f526e698f9e4
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension => github.com/SumoLogic/opentelemetry-collector-contrib/extension/encoding/textencodingextension 687035f9f64c57e96d74d523b398f526e698f9e4
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension v${OT_VERSION}
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/filestorage v${OT_VERSION}
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension v${OT_VERSION}
Loading
Loading