Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support image multiarch #60

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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