This is an automated email from the ASF dual-hosted git repository. liuhongyu pushed a commit to branch fix/revert_commites in repository https://gitbox.apache.org/repos/asf/hertzbeat-collector-go.git
commit d3106168e4a277976701b53e5ab84009b5abd48b Author: liuhy <[email protected]> AuthorDate: Thu Oct 9 18:48:31 2025 +0800 feat(docker): add Dockerfile and image build support --- Makefile | 11 ++-- .../docker/docker-compose/docker-compose.yml | 4 +- Makefile => tools/docker/hcg/Dockerfile | 25 ++++++---- tools/make/image.mk | 58 ++++++++++++++++++++++ 4 files changed, 82 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index cd02530..6b33134 100644 --- a/Makefile +++ b/Makefile @@ -17,11 +17,12 @@ _run: @$(MAKE) --warn-undefined-variables \ - -f tools/make/common.mk \ - -f tools/make/golang.mk \ - -f tools/make/linter.mk \ - -f tools/make/tools.mk \ - $(MAKECMDGOALS) + -f tools/make/common.mk \ + -f tools/make/golang.mk \ + -f tools/make/linter.mk \ + -f tools/make/image.mk \ + -f tools/make/tools.mk \ + $(MAKECMDGOALS) .PHONY: _run diff --git a/docker-compose.yml b/tools/docker/docker-compose/docker-compose.yml similarity index 93% rename from docker-compose.yml rename to tools/docker/docker-compose/docker-compose.yml index 7c158b5..427b692 100644 --- a/docker-compose.yml +++ b/tools/docker/docker-compose/docker-compose.yml @@ -19,11 +19,11 @@ services: # collector go service hertzbeat-collector: - image: hertzbeat/hertzbeat-collector-go:latest + image: hertzbeat-collector-go:latest container_name: hertzbeat-collector-go restart: on-failure ports: - - "8090:8090" + - "8080:8080" networks: hcg-network: diff --git a/Makefile b/tools/docker/hcg/Dockerfile similarity index 51% copy from Makefile copy to tools/docker/hcg/Dockerfile index cd02530..2bb553d 100644 --- a/Makefile +++ b/tools/docker/hcg/Dockerfile @@ -15,14 +15,21 @@ # specific language governing permissions and limitations # under the License. -_run: - @$(MAKE) --warn-undefined-variables \ - -f tools/make/common.mk \ - -f tools/make/golang.mk \ - -f tools/make/linter.mk \ - -f tools/make/tools.mk \ - $(MAKECMDGOALS) +FROM docker.io/library/busybox@sha256:ab33eacc8251e3807b85bb6dba570e4698c3998eca6f0fc2ccb60575a563ea74 AS builder -.PHONY: _run +# prepare hertzbeat data dir +RUN mkdir -p /var/hertzbeat -$(if $(MAKECMDGOALS),$(MAKECMDGOALS): %: _run) +# Use distroless as minimal base image to package the manager binary +# Refer to https://github.com/GoogleContainerTools/distroless for more details +FROM gcr.io/distroless/base-nossl:nonroot@sha256:8981b63f968e829d21351ea9d28cc21127e5f034707f1d8483d2993d9577be0b + +COPY --from=builder /var/hertzbeat/ /var/hertzbeat/ + +# copy binary to image, run make build to generate binary. +COPY bin /usr/local/bin/ +COPY etc /var/hertzbeat/config/ + +USER 65532:65532 + +ENTRYPOINT ["/usr/local/bin/collector", "server", "--config", "/var/hertzbeat/config/hertzbeat-collector.yaml"] diff --git a/tools/make/image.mk b/tools/make/image.mk new file mode 100644 index 0000000..fc37001 --- /dev/null +++ b/tools/make/image.mk @@ -0,0 +1,58 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This is a wrapper to build and push docker image +# + +# All make targets related to docker image are defined in this file. + +REGISTRY ?= docker.io + +TAG ?= $(shell git rev-parse HEAD) + +DOCKER := docker +DOCKER_SUPPORTED_API_VERSION ?= 1.32 + +IMAGES_DIR ?= $(wildcard tools/docker/hcg) + +IMAGES ?= hertzbeat-collector-go +IMAGE_PLATFORMS ?= amd64 arm64 + +BUILDX_CONTEXT = hcg-build-tools-builder + +##@ Image + +# todo: multi-platform build + +.PHONY: image-build +image-build: ## Build docker image +image-build: IMAGE_PLATFORMS = ${shell uname -m} +image-build: + @$(LOG_TARGET) + make build + $(DOCKER) buildx create --name $(BUILDX_CONTEXT) --use; \ + $(DOCKER) buildx use $(BUILDX_CONTEXT); \ + $(DOCKER) buildx build --load \ + -t $(REGISTRY)/${IMAGES}:$(TAG) \ + --platform linux/${IMAGE_PLATFORMS} \ + --file $(IMAGES_DIR)/Dockerfile . ; \ + $(DOCKER) buildx rm $(BUILDX_CONTEXT) + +.PHONY: image-push +image-push: ## Push docker image +image-push: + @$(LOG_TARGET) + $(DOCKER) push $(REGISTRY)/$${image}:$(TAG)-$${platform}; \ --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
