Skip to content

Commit

Permalink
chore: add docker files
Browse files Browse the repository at this point in the history
  • Loading branch information
dhawal1248 committed Oct 11, 2023
1 parent 761cce5 commit eb598f3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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..."
Expand Down
2 changes: 1 addition & 1 deletion cmd/signozcollector/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions cmd/signozcollectormigrator/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
8 changes: 4 additions & 4 deletions cmd/signozcollectormigrator/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit eb598f3

Please sign in to comment.