From eb598f3ee89f58c9e21dff059424cadfbe7d51b2 Mon Sep 17 00:00:00 2001 From: dhawal1248 Date: Wed, 11 Oct 2023 21:14:33 +0530 Subject: [PATCH] chore: add docker files --- Makefile | 20 ++++++++++++++++++++ cmd/signozcollector/Dockerfile | 2 +- cmd/signozcollectormigrator/Dockerfile | 18 ++++++++++++++++++ cmd/signozcollectormigrator/migrate.go | 8 ++++---- 4 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 cmd/signozcollectormigrator/Dockerfile diff --git a/Makefile b/Makefile index 216f4eb6..73e519cd 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ COMMIT_SHA ?= $(shell git rev-parse HEAD) REPONAME ?= signoz IMAGE_NAME ?= signoz-otel-collector +MIGRATOR_IMAGE_NAME ?= signoz-otel-collector-migrator CONFIG_FILE ?= ./config/default-config.yaml DOCKER_TAG ?= latest @@ -34,6 +35,7 @@ test: .PHONY: build build: CGO_ENABLED=1 go build -tags timetzdata -o .build/${GOOS}-${GOARCH}/signoz-collector -ldflags "-linkmode external -extldflags '-static' -s -w ${LD_FLAGS}" ./cmd/signozcollector + CGO_ENABLED=1 go build -tags timetzdata -o .build/${GOOS}-${GOARCH}/signoz-collector-migrator -ldflags "-linkmode external -extldflags '-static' -s -w ${LD_FLAGS}" ./cmd/signozcollectormigrator .PHONY: amd64 amd64: @@ -73,6 +75,24 @@ build-signoz-collector: --no-cache -f cmd/signozcollector/Dockerfile --progress plain \ --tag $(REPONAME)/$(IMAGE_NAME):$(DOCKER_TAG) . +.PHONY: build-signoz-collector-migrator +build-signoz-collector-migrator: + @echo "------------------" + @echo "--> Build signoz collector migrator docker image" + @echo "------------------" + docker build --build-arg TARGETPLATFORM="linux/amd64" \ + --no-cache -f cmd/signozcollectormigrator/Dockerfile --progress plain \ + --tag $(REPONAME)/$(MIGRATOR_IMAGE_NAME):$(DOCKER_TAG) . + +.PHONY: build-and-push-signoz-collector-migrator +build-and-push-signoz-collector-migrator: + @echo "------------------" + @echo "--> Build and push signoz collector migrator docker image" + @echo "------------------" + docker buildx build --platform linux/amd64,linux/arm64 --progress plain \ + --no-cache --push -f cmd/signozcollectormigrator/Dockerfile \ + --tag $(REPONAME)/$(MIGRATOR_IMAGE_NAME):$(DOCKER_TAG) . + .PHONY: lint lint: @echo "Running linters..." diff --git a/cmd/signozcollector/Dockerfile b/cmd/signozcollector/Dockerfile index 0dbbb0d5..834c295b 100644 --- a/cmd/signozcollector/Dockerfile +++ b/cmd/signozcollector/Dockerfile @@ -14,7 +14,7 @@ USER ${USER_UID} # copy the binaries from the multi-stage build COPY .build/${TARGETOS}-${TARGETARCH}/signoz-collector /signoz-collector -# copy the config and migration files +# copy the config file COPY config/default-config.yaml /etc/otel/config.yaml # expose OTLP ports for the collector diff --git a/cmd/signozcollectormigrator/Dockerfile b/cmd/signozcollectormigrator/Dockerfile new file mode 100644 index 00000000..22e4fb7f --- /dev/null +++ b/cmd/signozcollectormigrator/Dockerfile @@ -0,0 +1,18 @@ +# use a minimal alpine image +FROM alpine:3.17 + +# add ca-certificates in case you need them +RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/* + +# define arguments and default values +ARG TARGETOS TARGETARCH +ARG USER_UID=10001 + +# create a non-root user for running the migrator +USER ${USER_UID} + +# copy the binaries from the multi-stage build +COPY .build/${TARGETOS}-${TARGETARCH}/signoz-collector-migrator /signoz-collector-migrator + +# run the binary as the entrypoint and pass the default config file as a flag +ENTRYPOINT [ "/signoz-collector-migrator" ] diff --git a/cmd/signozcollectormigrator/migrate.go b/cmd/signozcollectormigrator/migrate.go index 541d3388..d39edefc 100644 --- a/cmd/signozcollectormigrator/migrate.go +++ b/cmd/signozcollectormigrator/migrate.go @@ -36,7 +36,7 @@ func main() { } f.String("dsn", "", "Clickhouse DSN") - f.String("cluster-name", "", "Cluster name to use while running migrations") + f.String("cluster-name", "cluster", "Cluster name to use while running migrations") f.Bool("multi-node-cluster", false, "True if the dsn points to a multi node clickhouse cluster, false otherwise. Defaults to false.") f.Bool("disable-duration-sort-feature", false, "Flag to disable the duration sort feature. Defaults to false.") f.Bool("disable-timestamp-sort-feature", false, "Flag to disable the timestamp sort feature. Defaults to false.") @@ -71,10 +71,10 @@ func main() { logger.Fatal("Failed to get disable timestamp sort feature flag from args", zap.Error(err)) } - if dsn == "" || clusterName == "" { - logger.Fatal("dsn and clusterName are required fields") + if dsn == "" { + logger.Fatal("dsn is a required field") } - + // set cluster env so that golang-migrate can use it // the value of this env would replace all occurences of {{.SIGNOZ_CLUSTER}} in the migration files os.Setenv("SIGNOZ_CLUSTER", clusterName)