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 12:06:03 UTC

[skywalking-cli] branch master updated: Add cross platform build targets (#129)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 8c5725f  Add cross platform build targets (#129)
8c5725f is described below

commit 8c5725f2c4c47de6091748c1b4747f0d6047ad8e
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Tue Nov 16 20:05:56 2021 +0800

    Add cross platform build targets (#129)
---
 .github/workflows/go.yml                       |  2 +
 .github/workflows/publish-docker.yaml          |  7 +--
 Makefile                                       | 78 ++++++++++++++------------
 cmd/swctl/main.go                              |  3 +-
 docs/How-to-release.md                         |  5 +-
 internal/commands/install/manifest/manifest.go |  3 +-
 pkg/graphql/dashboard/global.go                |  4 +-
 7 files changed, 53 insertions(+), 49 deletions(-)

diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 3a44d84..814d8ed 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -54,3 +54,5 @@ jobs:
       - name: Build
         run: make build -j3
 
+      - name: Build Docker images
+        run: make docker
diff --git a/.github/workflows/publish-docker.yaml b/.github/workflows/publish-docker.yaml
index 6eda3e0..a95013f 100644
--- a/.github/workflows/publish-docker.yaml
+++ b/.github/workflows/publish-docker.yaml
@@ -50,8 +50,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..1642395 100644
--- a/Makefile
+++ b/Makefile
@@ -25,65 +25,67 @@ 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 +139,18 @@ check-codegen:
 	fi
 
 .PHONY: docker
-docker: clean
-	docker build --build-arg VERSION=$(VERSION) . -t $(HUB)/$(APP_NAME):$(VERSION)
+docker:
+	docker buildx create --use
+	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/docs/How-to-release.md b/docs/How-to-release.md
index f1426a4..acdb878 100644
--- a/docs/How-to-release.md
+++ b/docs/How-to-release.md
@@ -195,7 +195,10 @@ Vote result should follow these:
     svn mv https://dist.apache.org/repos/dist/dev/skywalking/cli/$VERSION https://dist.apache.org/repos/dist/release/skywalking/cli -m"Release SkyWalking CLI $VERSION"
     ```
 
-1. Push Docker images.
+2. Push Docker images.
+
+In order to publish the Docker images, you
+have [to enable BuildKit in the Docker daemon](https://docs.docker.com/develop/develop-images/build_enhancements/.
 
 ```shell
 make docker.push
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
 		}