add a build flag "containers_image_openpgp" to prevent dependency on gpgme

Signed-off-by: 24sama <jacksama@foxmail.com>
This commit is contained in:
24sama 2022-03-29 16:21:57 +08:00
parent c81fe6f7f3
commit b1c4153ca4
4 changed files with 21 additions and 14 deletions

View File

@ -43,10 +43,10 @@ jobs:
fi
- name: Build operator manager
run: go build -v -o output/manager ./main.go
run: CGO_ENABLED=0 go build -tags='containers_image_openpgp' -v -o output/manager ./main.go
- name: Build command-line tool
run: go build -v -o output/kk ./cmd/main.go
run: CGO_ENABLED=0 go build -tags='containers_image_openpgp' -v -o output/kk ./cmd/main.go
- uses: actions/upload-artifact@v2
if: github.event_name == 'push'

View File

@ -10,6 +10,8 @@ builds:
- arm64
goos:
- linux
tags:
containers_image_openpgp
ldflags:
- -X github.com/kubesphere/kubekey/version.version={{.Version}}
- -X github.com/kubesphere/kubekey/version.gitCommit={{.ShortCommit}}

View File

@ -55,6 +55,11 @@ endif
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
BUILDFLAGS = -tags='containers_image_openpgp'
all: build
##@ General
@ -85,7 +90,7 @@ fmt: ## Run go fmt against code.
go fmt ./...
vet: ## Run go vet against code.
go vet ./...
go vet $(BUILDFLAGS) ./...
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
@ -93,10 +98,10 @@ test: manifests generate fmt vet envtest ## Run tests.
##@ Build
build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
go build $(BUILDFLAGS) -o bin/manager main.go
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go
go run $(BUILDFLAGS) ./main.go
docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .
@ -223,7 +228,7 @@ LDFLAGS += -X github.com/kubesphere/kubekey/version.metadata=${VERSION_METADATA}
LDFLAGS += -X github.com/kubesphere/kubekey/version.gitCommit=${GIT_COMMIT}
LDFLAGS += -X github.com/kubesphere/kubekey/version.gitTreeState=${GIT_DIRTY}
# see also kk-linux and kk-darwin
# see kk
binary:
docker run --rm \
-v $(shell pwd):/usr/src/myapp \
@ -232,7 +237,7 @@ binary:
-e CGO_ENABLED=0 \
-e GO111MODULE=on \
-w /usr/src/myapp golang:1.17 \
go build -ldflags '$(LDFLAGS)' -v -o output/linux/amd64/kk ./cmd/main.go # linux
go build $(BUILDFLAGS) -ldflags '$(LDFLAGS)' -v -o output/linux/amd64/kk ./cmd/main.go # linux
sha256sum output/linux/amd64/kk || shasum -a 256 output/linux/amd64/kk
docker run --rm \
@ -242,13 +247,13 @@ binary:
-e CGO_ENABLED=0 \
-e GO111MODULE=on \
-w /usr/src/myapp golang:1.17 \
go build -ldflags '$(LDFLAGS)' -v -o output/linux/arm64/kk ./cmd/main.go # linux
go build $(BUILDFLAGS) -ldflags '$(LDFLAGS)' -v -o output/linux/arm64/kk ./cmd/main.go # linux
sha256sum output/linux/arm64/kk || shasum -a 256 output/linux/arm64/kk
# build the binary file of kk
kk-linux:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 GO111MODULE=on go build -ldflags '$(LDFLAGS)' -o bin/linux/amd64/kk ./cmd/main.go
kk-darwin:
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 GO111MODULE=on go build -ldflags '$(LDFLAGS)' -o bin/darwin/amd64/kk ./cmd/main.go
kk: fmt vet
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 GO111MODULE=on go build $(BUILDFLAGS) -ldflags '$(LDFLAGS)' \
-o bin/$(GOOS)/$(GOARCH)/kk ./cmd/main.go;
go-releaser-test:
goreleaser release --rm-dist --skip-publish --snapshot

View File

@ -24,10 +24,10 @@ LDFLAGS="-X github.com/kubesphere/kubekey/version.version=${VERSION}
if [ -n "$1" ]; then
if [ "$1" == "-p" ] || [ "$1" == "--proxy" ]; then
# Using the most trusted Go module proxy in China
docker run --rm -e GO111MODULE=on -e GOPROXY=https://goproxy.cn -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang:1.17 go build -ldflags "$LDFLAGS" -v -o output/kk ./cmd/main.go
docker run --rm -e GO111MODULE=on -e GOPROXY=https://goproxy.cn -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang:1.17 go build -tags='containers_image_openpgp' -ldflags "$LDFLAGS" -v -o output/kk ./cmd/main.go
else
echo "The option should be '-p' or '--proxy'"
fi
else
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang:1.17 go build -ldflags "$LDFLAGS" -v -o output/kk ./cmd/main.go
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang:1.17 go build -tags='containers_image_openpgp' -ldflags "$LDFLAGS" -v -o output/kk ./cmd/main.go
fi