You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2021/11/16 11:11:14 UTC

[skywalking-cli] 01/01: Add cross platform build targets

This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch docker/crossplatform
in repository https://gitbox.apache.org/repos/asf/skywalking-cli.git

commit 870ebe21879b30aad3800a70164302d6649201c9
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Tue Nov 16 17:35:42 2021 +0800

    Add cross platform build targets
---
 .github/workflows/publish-docker.yaml          |  8 +--
 Makefile                                       | 77 +++++++++++++-------------
 cmd/swctl/main.go                              |  3 +-
 internal/commands/install/manifest/manifest.go |  3 +-
 pkg/graphql/dashboard/global.go                |  4 +-
 5 files changed, 46 insertions(+), 49 deletions(-)

diff --git a/.github/workflows/publish-docker.yaml b/.github/workflows/publish-docker.yaml
index 6eda3e0..66684c0 100644
--- a/.github/workflows/publish-docker.yaml
+++ b/.github/workflows/publish-docker.yaml
@@ -20,6 +20,7 @@ on:
   push:
     branches:
       - master
+      - docker/crossplatform
 
 env:
   SKIP_TEST: true
@@ -50,8 +51,5 @@ jobs:
           registry: ${{ env.HUB }}
           username: ${{ github.actor }}
           password: ${{ secrets.GITHUB_TOKEN }}
-      - name: Build docker image
-        run: |
-          make docker.push || make docker.push
-          docker tag $HUB/$APP_NAME:{$VERSION,latest}
-          docker push $HUB/$APP_NAME:latest
+      - name: Build and push docker images
+        run: make docker.push || make docker.push
diff --git a/Makefile b/Makefile
index ef592ff..6433519 100644
--- a/Makefile
+++ b/Makefile
@@ -25,65 +25,65 @@ HUB ?= docker.io/apache
 RELEASE_BIN = skywalking-cli-$(VERSION)-bin
 RELEASE_SRC = skywalking-cli-$(VERSION)-src
 
-OS = $(shell uname)
-
 GO = go
 GO_PATH = $$($(GO) env GOPATH)
 GO_BUILD = $(GO) build
 GO_GET = $(GO) get
 GO_INSTALL = $(GO) install
 GO_TEST = $(GO) test
-GO_LINT = $(GO_PATH)/bin/golangci-lint
-GO_LICENSER = $(GO_PATH)/bin/go-licenser
-ARCH := $(shell uname)
-OSNAME := $(if $(findstring Darwin,$(ARCH)),darwin,linux)
 GO_BUILD_FLAGS = -v
 GO_BUILD_LDFLAGS = -X main.version=$(VERSION)
 
-PLATFORMS := windows linux darwin
-os = $(word 1, $@)
-ARCH = amd64
+GO_LINT = golangci-lint
+LICENSE_EYE = license-eye
 
-SHELL = /bin/bash
+BUILDS := darwin-amd64 darwin-arm64 linux-386 linux-amd64 linux-arm64 windows-386 windows-amd64
+BUILD_RULE = GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO_BUILD) $(GO_BUILD_FLAGS) -ldflags "$(GO_BUILD_LDFLAGS)" -o $(OUT_DIR)/$(BINARY)-$(VERSION)-$(GOOS)-$(GOARCH) cmd/swctl/main.go
 
 all: clean license deps lint test build
 
-tools:
-	mkdir -p $(GO_PATH)/bin
-	$(GO_LINT) version || curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_PATH)/bin
-	$(GO_LICENSER) -version || GO111MODULE=off $(GO_GET) -u github.com/elastic/go-licenser
+.PHONY: $(BUILDS)
+$(BUILDS): GOOS = $(word 1,$(subst -, ,$@))
+$(BUILDS): GOARCH = $(word 2,$(subst -, ,$@))
+$(BUILDS):
+	$(BUILD_RULE)
+
+.PHONY: build
+build: $(BUILDS)
 
-deps: tools
-	$(GO_GET) -v -t -d ./...
+.PHONY: deps
+deps:
+	@$(GO_GET) -v -t -d ./...
 
-.PHONY: $(PLATFORMS)
-$(PLATFORMS): clean
-	mkdir -p $(OUT_DIR)
-	GOOS=$(os) GOARCH=$(ARCH) $(GO_BUILD) $(GO_BUILD_FLAGS) -ldflags "$(GO_BUILD_LDFLAGS)" -o $(OUT_DIR)/$(BINARY)-$(VERSION)-$(os)-$(ARCH) cmd/swctl/main.go
+$(GO_LINT):
+	@$(GO_LINT) version > /dev/null 2>&1 || go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
+$(LICENSE_EYE):
+	@$(LICENSE_EYE) --version > /dev/null 2>&1 || go install github.com/apache/skywalking-eyes/cmd/license-eye@latest
 
 .PHONY: lint
-lint: tools
+lint: $(GO_LINT)
 	$(GO_LINT) run -v --timeout 5m ./...
+.PHONY: fix-lint
+fix-lint: $(GO_LINT)
+	$(GO_LINT) run -v --fix ./...
+
+.PHONY: license
+license: clean $(LICENSE_EYE)
+	@$(LICENSE_EYE) header check
+.PHONY: fix-license
+fix-license: clean $(LICENSE_EYE)
+	@$(LICENSE_EYE) header fix
+
+.PHONY: fix
+fix: fix-lint fix-license
 
 .PHONY: test
 test: clean
 	$(GO_TEST) ./... -coverprofile=coverage.txt -covermode=atomic
 
-.PHONY: build
-build: deps windows linux darwin
-
-.PHONY: license
-license: clean tools
-	$(GO_LICENSER) -d -licensor='Apache Software Foundation (ASF)' .
-
 .PHONY: verify
 verify: clean license lint test
 
-.PHONY: fix
-fix: tools
-	$(GO_LINT) run -v --fix ./...
-	$(GO_LICENSER) -licensor='Apache Software Foundation (ASF)' .
-
 .PHONY: coverage
 coverage: test
 	bash <(curl -s https://codecov.io/bash) -t a5af28a3-92a2-4b35-9a77-54ad99b1ae00
@@ -137,16 +137,17 @@ check-codegen:
 	fi
 
 .PHONY: docker
-docker: clean
-	docker build --build-arg VERSION=$(VERSION) . -t $(HUB)/$(APP_NAME):$(VERSION)
+docker:
+	docker buildx build $(PUSH) --platform linux/386,linux/amd64,linux/arm64 --build-arg VERSION=$(VERSION) . -t $(HUB)/$(APP_NAME):$(VERSION) -t $(HUB)/$(APP_NAME):latest
 
 .PHONY: docker.push
+docker.push: PUSH = --push
 docker.push: docker
-	docker push $(HUB)/$(APP_NAME):$(VERSION)
 
 .PHONY: install
-install: $(OSNAME)
-	-cp $(OUT_DIR)/$(BINARY)-$(VERSION)-$(OSNAME)-$(ARCH) $(DESTDIR)/swctl
+install: clean
+	$(BUILD_RULE)
+	-cp $(OUT_DIR)/$(BINARY)-$(VERSION)-$(OSNAME)-* $(DESTDIR)/swctl
 
 .PHONY: uninstall
 uninstall: $(OSNAME)
diff --git a/cmd/swctl/main.go b/cmd/swctl/main.go
index 65b7bdb..f52ea7e 100644
--- a/cmd/swctl/main.go
+++ b/cmd/swctl/main.go
@@ -18,7 +18,6 @@
 package main
 
 import (
-	"io/ioutil"
 	"os"
 	"runtime"
 
@@ -192,7 +191,7 @@ func expandConfigFile(c *cli.Context) error {
 func tryConfigFile(flags []cli.Flag) cli.BeforeFunc {
 	return func(c *cli.Context) error {
 		configFile := c.String("config")
-		if bytes, err := ioutil.ReadFile(configFile); err == nil {
+		if bytes, err := os.ReadFile(configFile); err == nil {
 			log.Debug("Using configurations:\n", string(bytes))
 
 			err = altsrc.InitInputSourceWithContext(flags, altsrc.NewYamlSourceFromFlagFunc("config"))(c)
diff --git a/internal/commands/install/manifest/manifest.go b/internal/commands/install/manifest/manifest.go
index 1e76779..2d1b72d 100644
--- a/internal/commands/install/manifest/manifest.go
+++ b/internal/commands/install/manifest/manifest.go
@@ -21,7 +21,6 @@ import (
 	"bufio"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"os"
 	"strings"
 
@@ -98,7 +97,7 @@ func loadOverlay(file string, in io.Reader, out interface{}) error {
 			}
 		}
 	} else {
-		b, err := ioutil.ReadFile(file)
+		b, err := os.ReadFile(file)
 		if err != nil {
 			return err
 		}
diff --git a/pkg/graphql/dashboard/global.go b/pkg/graphql/dashboard/global.go
index 3586de4..13b1aad 100644
--- a/pkg/graphql/dashboard/global.go
+++ b/pkg/graphql/dashboard/global.go
@@ -19,7 +19,7 @@ package dashboard
 
 import (
 	"bytes"
-	"io/ioutil"
+	"os"
 	"strings"
 	"sync"
 
@@ -100,7 +100,7 @@ func LoadTemplate(filename string) (*GlobalTemplate, error) {
 	if filename == DefaultTemplatePath {
 		byteValue = []byte(assets.Read(filename))
 	} else {
-		byteValue, err = ioutil.ReadFile(filename)
+		byteValue, err = os.ReadFile(filename)
 		if err != nil {
 			return nil, err
 		}