Skip to content

Commit

Permalink
support image multiarch (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaByte875 authored Mar 21, 2024
1 parent 49a3284 commit 27d7572
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM centos:7.6.1810
FROM alpine:3.18.2

COPY nebula-stats-exporter /
RUN chmod +x /nebula-stats-exporter
ARG TARGETPLATFORM
ARG TARGETARCH

COPY bin/${TARGETPLATFORM}/nebula-stats-exporter /
ENTRYPOINT [ "/nebula-stats-exporter" ]
50 changes: 37 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,61 @@
PROJECT="nebula-exporter"

GO ?= go
VERSION ?= v3.3.0
DockerUser=vesoft
IMAGE_TAG ?= v3.3.0
DOCKER_REPO=vesoft

export GO111MODULE := on
LDFLAGS = $(if $(DEBUGGER),,-s -w)
GOOS := $(if $(GOOS),$(GOOS),linux)
GOARCH := $(if $(GOARCH),$(GOARCH),amd64)
GOENV := GO15VENDOREXPERIMENT="1" CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH)
GO := $(GOENV) go
GO_BUILD := $(GO) build -trimpath
TARGETDIR := "$(GOOS)/$(GOARCH)"
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

all: check build docker-build docker-push clean
PLATFORMS = arm64 amd64
BUILDX_PLATFORMS = linux/arm64,linux/amd64

ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

all: check build-exporter helm-chart image-multiarch clean

check: fmt vet lint

build:
go build -o nebula-stats-exporter main.go
build-exporter:
$(GO_BUILD) -ldflags '$(LDFLAGS)' -o bin/$(TARGETDIR)/nebula-stats-exporter main.go

build-helm:
helm-chart:
helm repo index charts --url https://vesoft-inc.github.io/nebula-stats-exporter/charts
helm package charts/nebula-exporter
mv nebula-exporter-*.tgz charts/

docker-build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o nebula-stats-exporter main.go
docker build -t $(DockerUser)/nebula-stats-exporter:$(VERSION) .

docker-push:
docker push $(DockerUser)/nebula-stats-exporter:$(VERSION)
image-multiarch:
$(foreach PLATFORM,$(PLATFORMS), echo -n "$(PLATFORM)..."; GOARCH=$(PLATFORM) make build-exporter;)
echo "Building and pushing nebula-exporter image... $(BUILDX_PLATFORMS)"
docker buildx rm exporter || true
docker buildx create --driver-opt network=host --use --name=exporter
docker buildx build \
--no-cache \
--pull \
--push \
--progress plain \
--platform $(BUILDX_PLATFORMS) \
-t "${DOCKER_REPO}/nebula-stats-exporter:${IMAGE_TAG}" .

clean:
rm -rf nebula-stats-exporter
docker rmi -f $(DockerUser)/nebula-stats-exporter:$(VERSION)
docker rmi -f $(DOCKER_REPO)/nebula-stats-exporter:$(IMAGE_TAG)

fmt:
go fmt .
Expand Down

0 comments on commit 27d7572

Please sign in to comment.