Skip to content

Commit d310616

Browse files
committed
feat(docker): add Dockerfile and image build support
1 parent fce1def commit d310616

File tree

4 files changed

+101
-7
lines changed

4 files changed

+101
-7
lines changed

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
_run:
1919
@$(MAKE) --warn-undefined-variables \
20-
-f tools/make/common.mk \
21-
-f tools/make/golang.mk \
22-
-f tools/make/linter.mk \
23-
-f tools/make/tools.mk \
24-
$(MAKECMDGOALS)
20+
-f tools/make/common.mk \
21+
-f tools/make/golang.mk \
22+
-f tools/make/linter.mk \
23+
-f tools/make/image.mk \
24+
-f tools/make/tools.mk \
25+
$(MAKECMDGOALS)
2526

2627
.PHONY: _run
2728

docker-compose.yml renamed to tools/docker/docker-compose/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ services:
1919

2020
# collector go service
2121
hertzbeat-collector:
22-
image: hertzbeat/hertzbeat-collector-go:latest
22+
image: hertzbeat-collector-go:latest
2323
container_name: hertzbeat-collector-go
2424
restart: on-failure
2525
ports:
26-
- "8090:8090"
26+
- "8080:8080"
2727
networks:
2828
hcg-network:
2929

tools/docker/hcg/Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
FROM docker.io/library/busybox@sha256:ab33eacc8251e3807b85bb6dba570e4698c3998eca6f0fc2ccb60575a563ea74 AS builder
19+
20+
# prepare hertzbeat data dir
21+
RUN mkdir -p /var/hertzbeat
22+
23+
# Use distroless as minimal base image to package the manager binary
24+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
25+
FROM gcr.io/distroless/base-nossl:nonroot@sha256:8981b63f968e829d21351ea9d28cc21127e5f034707f1d8483d2993d9577be0b
26+
27+
COPY --from=builder /var/hertzbeat/ /var/hertzbeat/
28+
29+
# copy binary to image, run make build to generate binary.
30+
COPY bin /usr/local/bin/
31+
COPY etc /var/hertzbeat/config/
32+
33+
USER 65532:65532
34+
35+
ENTRYPOINT ["/usr/local/bin/collector", "server", "--config", "/var/hertzbeat/config/hertzbeat-collector.yaml"]

tools/make/image.mk

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# This is a wrapper to build and push docker image
18+
#
19+
20+
# All make targets related to docker image are defined in this file.
21+
22+
REGISTRY ?= docker.io
23+
24+
TAG ?= $(shell git rev-parse HEAD)
25+
26+
DOCKER := docker
27+
DOCKER_SUPPORTED_API_VERSION ?= 1.32
28+
29+
IMAGES_DIR ?= $(wildcard tools/docker/hcg)
30+
31+
IMAGES ?= hertzbeat-collector-go
32+
IMAGE_PLATFORMS ?= amd64 arm64
33+
34+
BUILDX_CONTEXT = hcg-build-tools-builder
35+
36+
##@ Image
37+
38+
# todo: multi-platform build
39+
40+
.PHONY: image-build
41+
image-build: ## Build docker image
42+
image-build: IMAGE_PLATFORMS = ${shell uname -m}
43+
image-build:
44+
@$(LOG_TARGET)
45+
make build
46+
$(DOCKER) buildx create --name $(BUILDX_CONTEXT) --use; \
47+
$(DOCKER) buildx use $(BUILDX_CONTEXT); \
48+
$(DOCKER) buildx build --load \
49+
-t $(REGISTRY)/${IMAGES}:$(TAG) \
50+
--platform linux/${IMAGE_PLATFORMS} \
51+
--file $(IMAGES_DIR)/Dockerfile . ; \
52+
$(DOCKER) buildx rm $(BUILDX_CONTEXT)
53+
54+
.PHONY: image-push
55+
image-push: ## Push docker image
56+
image-push:
57+
@$(LOG_TARGET)
58+
$(DOCKER) push $(REGISTRY)/$${image}:$(TAG)-$${platform}; \

0 commit comments

Comments
 (0)