mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-26 10:24:28 +08:00
perf(query-service): 🔨 improve backend build time (#3658)
* perf(query-service): 🔨 improve backend build time * chore(query-service): 🔧 address comments on image build time --------- Signed-off-by: Prashant Shahi <prashant@signoz.io>
This commit is contained in:
parent
0e04b779a9
commit
e12aef136a
69
Makefile
69
Makefile
@ -8,6 +8,7 @@ BUILD_HASH ?= $(shell git rev-parse --short HEAD)
|
|||||||
BUILD_TIME ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
|
BUILD_TIME ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||||
BUILD_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
|
BUILD_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
|
||||||
DEV_LICENSE_SIGNOZ_IO ?= https://staging-license.signoz.io/api/v1
|
DEV_LICENSE_SIGNOZ_IO ?= https://staging-license.signoz.io/api/v1
|
||||||
|
DEV_BUILD ?= "" # set to any non-empty value to enable dev build
|
||||||
|
|
||||||
# Internal variables or constants.
|
# Internal variables or constants.
|
||||||
FRONTEND_DIRECTORY ?= frontend
|
FRONTEND_DIRECTORY ?= frontend
|
||||||
@ -15,15 +16,15 @@ QUERY_SERVICE_DIRECTORY ?= pkg/query-service
|
|||||||
EE_QUERY_SERVICE_DIRECTORY ?= ee/query-service
|
EE_QUERY_SERVICE_DIRECTORY ?= ee/query-service
|
||||||
STANDALONE_DIRECTORY ?= deploy/docker/clickhouse-setup
|
STANDALONE_DIRECTORY ?= deploy/docker/clickhouse-setup
|
||||||
SWARM_DIRECTORY ?= deploy/docker-swarm/clickhouse-setup
|
SWARM_DIRECTORY ?= deploy/docker-swarm/clickhouse-setup
|
||||||
LOCAL_GOOS ?= $(shell go env GOOS)
|
|
||||||
LOCAL_GOARCH ?= $(shell go env GOARCH)
|
GOOS ?= $(shell go env GOOS)
|
||||||
|
GOARCH ?= $(shell go env GOARCH)
|
||||||
|
GOPATH ?= $(shell go env GOPATH)
|
||||||
|
|
||||||
REPONAME ?= signoz
|
REPONAME ?= signoz
|
||||||
DOCKER_TAG ?= $(subst v,,$(BUILD_VERSION))
|
DOCKER_TAG ?= $(subst v,,$(BUILD_VERSION))
|
||||||
|
|
||||||
FRONTEND_DOCKER_IMAGE ?= frontend
|
FRONTEND_DOCKER_IMAGE ?= frontend
|
||||||
QUERY_SERVICE_DOCKER_IMAGE ?= query-service
|
QUERY_SERVICE_DOCKER_IMAGE ?= query-service
|
||||||
DEV_BUILD ?= ""
|
|
||||||
|
|
||||||
# Build-time Go variables
|
# Build-time Go variables
|
||||||
PACKAGE?=go.signoz.io/signoz
|
PACKAGE?=go.signoz.io/signoz
|
||||||
@ -69,49 +70,71 @@ build-push-frontend: build-frontend-static
|
|||||||
docker buildx build --file Dockerfile --progress plain --push --platform linux/arm64,linux/amd64 \
|
docker buildx build --file Dockerfile --progress plain --push --platform linux/arm64,linux/amd64 \
|
||||||
--tag $(REPONAME)/$(FRONTEND_DOCKER_IMAGE):$(DOCKER_TAG) .
|
--tag $(REPONAME)/$(FRONTEND_DOCKER_IMAGE):$(DOCKER_TAG) .
|
||||||
|
|
||||||
|
# Steps to build static binary of query service
|
||||||
|
.PHONY: build-query-service-static
|
||||||
|
build-query-service-static:
|
||||||
|
@echo "------------------"
|
||||||
|
@echo "--> Building query-service static binary"
|
||||||
|
@echo "------------------"
|
||||||
|
@if [ $(DEV_BUILD) != "" ]; then \
|
||||||
|
cd $(QUERY_SERVICE_DIRECTORY) && \
|
||||||
|
CGO_ENABLED=1 go build -tags timetzdata -a -o ./bin/query-service-${GOOS}-${GOARCH} \
|
||||||
|
-ldflags "-linkmode external -extldflags '-static' -s -w ${LD_FLAGS} ${DEV_LD_FLAGS}"; \
|
||||||
|
else \
|
||||||
|
cd $(QUERY_SERVICE_DIRECTORY) && \
|
||||||
|
CGO_ENABLED=1 go build -tags timetzdata -a -o ./bin/query-service-${GOOS}-${GOARCH} \
|
||||||
|
-ldflags "-linkmode external -extldflags '-static' -s -w ${LD_FLAGS}"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
.PHONY: build-query-service-static-amd64
|
||||||
|
build-query-service-static-amd64:
|
||||||
|
make GOARCH=amd64 build-query-service-static
|
||||||
|
|
||||||
|
.PHONY: build-query-service-static-arm64
|
||||||
|
build-query-service-static-arm64:
|
||||||
|
make CC=aarch64-linux-gnu-gcc GOARCH=arm64 build-query-service-static
|
||||||
|
|
||||||
|
# Steps to build static binary of query service for all platforms
|
||||||
|
.PHONY: build-query-service-static-all
|
||||||
|
build-query-service-static-all: build-query-service-static-amd64 build-query-service-static-arm64
|
||||||
|
|
||||||
# Steps to build and push docker image of query service
|
# Steps to build and push docker image of query service
|
||||||
.PHONY: build-query-service-amd64 build-push-query-service
|
.PHONY: build-query-service-amd64 build-push-query-service
|
||||||
# Step to build docker image of query service in amd64 (used in build pipeline)
|
# Step to build docker image of query service in amd64 (used in build pipeline)
|
||||||
build-query-service-amd64:
|
build-query-service-amd64: build-query-service-static-amd64
|
||||||
@echo "------------------"
|
@echo "------------------"
|
||||||
@echo "--> Building query-service docker image for amd64"
|
@echo "--> Building query-service docker image for amd64"
|
||||||
@echo "------------------"
|
@echo "------------------"
|
||||||
@docker build --file $(QUERY_SERVICE_DIRECTORY)/Dockerfile \
|
@docker build --file $(QUERY_SERVICE_DIRECTORY)/Dockerfile \
|
||||||
-t $(REPONAME)/$(QUERY_SERVICE_DOCKER_IMAGE):$(DOCKER_TAG) \
|
--tag $(REPONAME)/$(QUERY_SERVICE_DOCKER_IMAGE):$(DOCKER_TAG) \
|
||||||
--build-arg TARGETPLATFORM="linux/amd64" --build-arg LD_FLAGS="$(LD_FLAGS)" .
|
--build-arg TARGETPLATFORM="linux/amd64" .
|
||||||
|
|
||||||
# Step to build and push docker image of query in amd64 and arm64 (used in push pipeline)
|
# Step to build and push docker image of query in amd64 and arm64 (used in push pipeline)
|
||||||
build-push-query-service:
|
build-push-query-service: build-query-service-static-all
|
||||||
@echo "------------------"
|
@echo "------------------"
|
||||||
@echo "--> Building and pushing query-service docker image"
|
@echo "--> Building and pushing query-service docker image"
|
||||||
@echo "------------------"
|
@echo "------------------"
|
||||||
@docker buildx build --file $(QUERY_SERVICE_DIRECTORY)/Dockerfile --progress plain \
|
@docker buildx build --file $(QUERY_SERVICE_DIRECTORY)/Dockerfile --progress plain \
|
||||||
--push --platform linux/arm64,linux/amd64 --build-arg LD_FLAGS="$(LD_FLAGS)" \
|
--push --platform linux/arm64,linux/amd64 \
|
||||||
--tag $(REPONAME)/$(QUERY_SERVICE_DOCKER_IMAGE):$(DOCKER_TAG) .
|
--tag $(REPONAME)/$(QUERY_SERVICE_DOCKER_IMAGE):$(DOCKER_TAG) .
|
||||||
|
|
||||||
# Step to build EE docker image of query service in amd64 (used in build pipeline)
|
# Step to build EE docker image of query service in amd64 (used in build pipeline)
|
||||||
build-ee-query-service-amd64:
|
build-ee-query-service-amd64: build-query-service-static-amd64
|
||||||
@echo "------------------"
|
@echo "------------------"
|
||||||
@echo "--> Building query-service docker image for amd64"
|
@echo "--> Building query-service docker image for amd64"
|
||||||
@echo "------------------"
|
@echo "------------------"
|
||||||
@if [ $(DEV_BUILD) != "" ]; then \
|
@docker build --file $(EE_QUERY_SERVICE_DIRECTORY)/Dockerfile \
|
||||||
docker build --file $(EE_QUERY_SERVICE_DIRECTORY)/Dockerfile \
|
--tag $(REPONAME)/$(QUERY_SERVICE_DOCKER_IMAGE):$(DOCKER_TAG) \
|
||||||
-t $(REPONAME)/$(QUERY_SERVICE_DOCKER_IMAGE):$(DOCKER_TAG) \
|
--build-arg TARGETPLATFORM="linux/amd64" .
|
||||||
--build-arg TARGETPLATFORM="linux/amd64" --build-arg LD_FLAGS="${LD_FLAGS} ${DEV_LD_FLAGS}" .; \
|
|
||||||
else \
|
|
||||||
docker build --file $(EE_QUERY_SERVICE_DIRECTORY)/Dockerfile \
|
|
||||||
-t $(REPONAME)/$(QUERY_SERVICE_DOCKER_IMAGE):$(DOCKER_TAG) \
|
|
||||||
--build-arg TARGETPLATFORM="linux/amd64" --build-arg LD_FLAGS="$(LD_FLAGS)" .; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Step to build and push EE docker image of query in amd64 and arm64 (used in push pipeline)
|
# Step to build and push EE docker image of query in amd64 and arm64 (used in push pipeline)
|
||||||
build-push-ee-query-service:
|
build-push-ee-query-service: build-query-service-static-all
|
||||||
@echo "------------------"
|
@echo "------------------"
|
||||||
@echo "--> Building and pushing query-service docker image"
|
@echo "--> Building and pushing query-service docker image"
|
||||||
@echo "------------------"
|
@echo "------------------"
|
||||||
@docker buildx build --file $(EE_QUERY_SERVICE_DIRECTORY)/Dockerfile \
|
@docker buildx build --file $(EE_QUERY_SERVICE_DIRECTORY)/Dockerfile \
|
||||||
--progress plain --push --platform linux/arm64,linux/amd64 \
|
--progress plain --push --platform linux/arm64,linux/amd64 \
|
||||||
--build-arg LD_FLAGS="$(LD_FLAGS)" --tag $(REPONAME)/$(QUERY_SERVICE_DOCKER_IMAGE):$(DOCKER_TAG) .
|
--tag $(REPONAME)/$(QUERY_SERVICE_DOCKER_IMAGE):$(DOCKER_TAG) .
|
||||||
|
|
||||||
dev-setup:
|
dev-setup:
|
||||||
mkdir -p /var/lib/signoz
|
mkdir -p /var/lib/signoz
|
||||||
@ -122,7 +145,7 @@ dev-setup:
|
|||||||
@echo "------------------"
|
@echo "------------------"
|
||||||
|
|
||||||
run-local:
|
run-local:
|
||||||
@LOCAL_GOOS=$(LOCAL_GOOS) LOCAL_GOARCH=$(LOCAL_GOARCH) docker-compose -f \
|
@docker-compose -f \
|
||||||
$(STANDALONE_DIRECTORY)/docker-compose-core.yaml -f $(STANDALONE_DIRECTORY)/docker-compose-local.yaml \
|
$(STANDALONE_DIRECTORY)/docker-compose-core.yaml -f $(STANDALONE_DIRECTORY)/docker-compose-local.yaml \
|
||||||
up --build -d
|
up --build -d
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ services:
|
|||||||
dockerfile: "./Dockerfile"
|
dockerfile: "./Dockerfile"
|
||||||
args:
|
args:
|
||||||
LDFLAGS: ""
|
LDFLAGS: ""
|
||||||
TARGETPLATFORM: "${LOCAL_GOOS}/${LOCAL_GOARCH}"
|
TARGETPLATFORM: "${GOOS}/${GOARCH}"
|
||||||
container_name: signoz-query-service
|
container_name: signoz-query-service
|
||||||
environment:
|
environment:
|
||||||
- ClickHouseUrl=tcp://clickhouse:9000
|
- ClickHouseUrl=tcp://clickhouse:9000
|
||||||
@ -52,8 +52,8 @@ services:
|
|||||||
context: "../../../frontend"
|
context: "../../../frontend"
|
||||||
dockerfile: "./Dockerfile"
|
dockerfile: "./Dockerfile"
|
||||||
args:
|
args:
|
||||||
TARGETOS: "${LOCAL_GOOS}"
|
TARGETOS: "${GOOS}"
|
||||||
TARGETPLATFORM: "${LOCAL_GOARCH}"
|
TARGETPLATFORM: "${GOARCH}"
|
||||||
container_name: signoz-frontend
|
container_name: signoz-frontend
|
||||||
environment:
|
environment:
|
||||||
- FRONTEND_API_ENDPOINT=http://query-service:8080
|
- FRONTEND_API_ENDPOINT=http://query-service:8080
|
||||||
|
@ -1,43 +1,23 @@
|
|||||||
FROM golang:1.21-bookworm AS builder
|
|
||||||
|
|
||||||
# LD_FLAGS is passed as argument from Makefile. It will be empty, if no argument passed
|
|
||||||
ARG LD_FLAGS
|
|
||||||
ARG TARGETPLATFORM
|
|
||||||
|
|
||||||
ENV CGO_ENABLED=1
|
|
||||||
ENV GOPATH=/go
|
|
||||||
|
|
||||||
RUN export GOOS=$(echo ${TARGETPLATFORM} | cut -d / -f1) && \
|
|
||||||
export GOARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2)
|
|
||||||
|
|
||||||
# Prepare and enter src directory
|
|
||||||
WORKDIR /go/src/github.com/signoz/signoz
|
|
||||||
|
|
||||||
# Add the sources and proceed with build
|
|
||||||
ADD . .
|
|
||||||
RUN cd ee/query-service \
|
|
||||||
&& go build -tags timetzdata -a -o ./bin/query-service \
|
|
||||||
-ldflags "-linkmode external -extldflags '-static' -s -w $LD_FLAGS" \
|
|
||||||
&& chmod +x ./bin/query-service
|
|
||||||
|
|
||||||
|
|
||||||
# use a minimal alpine image
|
# use a minimal alpine image
|
||||||
FROM alpine:3.16.7
|
FROM alpine:3.17
|
||||||
|
|
||||||
# Add Maintainer Info
|
# Add Maintainer Info
|
||||||
LABEL maintainer="signoz"
|
LABEL maintainer="signoz"
|
||||||
|
|
||||||
|
# define arguments that can be passed during build time
|
||||||
|
ARG TARGETOS TARGETARCH
|
||||||
|
|
||||||
# add ca-certificates in case you need them
|
# add ca-certificates in case you need them
|
||||||
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
|
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
# set working directory
|
# set working directory
|
||||||
WORKDIR /root
|
WORKDIR /root
|
||||||
|
|
||||||
# copy the binary from builder
|
# copy the query-service binary
|
||||||
COPY --from=builder /go/src/github.com/signoz/signoz/ee/query-service/bin/query-service .
|
COPY ee/pkg/query-service/bin/query-service-${TARGETOS}-${TARGETARCH} /root/query-service
|
||||||
|
|
||||||
# copy prometheus YAML config
|
# copy prometheus YAML config
|
||||||
COPY pkg/query-service/config/prometheus.yml /root/config/prometheus.yml
|
COPY ee/pkg/query-service/config/prometheus.yml /root/config/prometheus.yml
|
||||||
|
|
||||||
# Make query-service executable for non-root users
|
# Make query-service executable for non-root users
|
||||||
RUN chmod 755 /root /root/query-service
|
RUN chmod 755 /root /root/query-service
|
||||||
@ -45,7 +25,6 @@ RUN chmod 755 /root /root/query-service
|
|||||||
# run the binary
|
# run the binary
|
||||||
ENTRYPOINT ["./query-service"]
|
ENTRYPOINT ["./query-service"]
|
||||||
|
|
||||||
CMD ["-config", "../config/prometheus.yml"]
|
CMD ["-config", "/root/config/prometheus.yml"]
|
||||||
# CMD ["./query-service -config /root/config/prometheus.yml"]
|
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
@ -1,45 +1,20 @@
|
|||||||
FROM golang:1.21-bookworm AS builder
|
|
||||||
|
|
||||||
# LD_FLAGS is passed as argument from Makefile. It will be empty, if no argument passed
|
|
||||||
ARG LD_FLAGS
|
|
||||||
ARG TARGETPLATFORM
|
|
||||||
|
|
||||||
ENV CGO_ENABLED=1
|
|
||||||
ENV GOPATH=/go
|
|
||||||
|
|
||||||
RUN export GOOS=$(echo ${TARGETPLATFORM} | cut -d / -f1) && \
|
|
||||||
export GOARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2)
|
|
||||||
|
|
||||||
# Prepare and enter src directory
|
|
||||||
WORKDIR /go/src/github.com/signoz/signoz
|
|
||||||
|
|
||||||
# Cache dependencies
|
|
||||||
ADD go.mod .
|
|
||||||
ADD go.sum .
|
|
||||||
RUN go mod download -x
|
|
||||||
|
|
||||||
# Add the sources and proceed with build
|
|
||||||
ADD . .
|
|
||||||
RUN cd pkg/query-service \
|
|
||||||
&& go build -tags timetzdata -a -o ./bin/query-service \
|
|
||||||
-ldflags "-linkmode external -extldflags '-static' -s -w $LD_FLAGS" \
|
|
||||||
&& chmod +x ./bin/query-service
|
|
||||||
|
|
||||||
|
|
||||||
# use a minimal alpine image
|
# use a minimal alpine image
|
||||||
FROM alpine:3.16.7
|
FROM alpine:3.17
|
||||||
|
|
||||||
# Add Maintainer Info
|
# Add Maintainer Info
|
||||||
LABEL maintainer="signoz"
|
LABEL maintainer="signoz"
|
||||||
|
|
||||||
|
# define arguments that can be passed during build time
|
||||||
|
ARG TARGETOS TARGETARCH
|
||||||
|
|
||||||
# add ca-certificates in case you need them
|
# add ca-certificates in case you need them
|
||||||
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
|
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
# set working directory
|
# set working directory
|
||||||
WORKDIR /root
|
WORKDIR /root
|
||||||
|
|
||||||
# copy the binary from builder
|
# copy the query-service binary
|
||||||
COPY --from=builder /go/src/github.com/signoz/signoz/pkg/query-service/bin/query-service .
|
COPY pkg/query-service/bin/query-service-${TARGETOS}-${TARGETARCH} /root/query-service
|
||||||
|
|
||||||
# copy prometheus YAML config
|
# copy prometheus YAML config
|
||||||
COPY pkg/query-service/config/prometheus.yml /root/config/prometheus.yml
|
COPY pkg/query-service/config/prometheus.yml /root/config/prometheus.yml
|
||||||
@ -51,6 +26,5 @@ RUN chmod 755 /root /root/query-service
|
|||||||
ENTRYPOINT ["./query-service"]
|
ENTRYPOINT ["./query-service"]
|
||||||
|
|
||||||
CMD ["-config", "/root/config/prometheus.yml"]
|
CMD ["-config", "/root/config/prometheus.yml"]
|
||||||
# CMD ["./query-service -config /root/config/prometheus.yml"]
|
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
Loading…
x
Reference in New Issue
Block a user