Skip to content

Commit

Permalink
add a build flag "containers_image_openpgp" to prevent dependency on …
Browse files Browse the repository at this point in the history
…gpgme

Signed-off-by: 24sama <jacksama@foxmail.com>
  • Loading branch information
24sama committed Mar 29, 2022
1 parent c81fe6f commit b1c4153
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
25 changes: 15 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,18 +90,18 @@ 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

##@ 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} .
Expand Down Expand Up @@ -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 \
Expand All @@ -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 \
Expand All @@ -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
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b1c4153

Please sign in to comment.