generated from replicatedhq/krew-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update build routines based on and inspired by ketall code
- Loading branch information
Caio Begotti
committed
Dec 15, 2019
1 parent
4db1213
commit 1488552
Showing
3 changed files
with
129 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,6 @@ | |
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
out/ | ||
bin/ | ||
pod-dive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,138 @@ | ||
# Copyright 2019 Cornelius Weig (from ketall) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
export GO111MODULE=on | ||
export GOROOT=$(PWD) | ||
export GO111MODULE ?= on | ||
export GOARCH ?= amd64 | ||
export CGO_ENABLED ?= 0 | ||
|
||
.PHONY: bin | ||
bin: fmt vet | ||
go build -o bin/pod-dive github.com/caiobegotti/pod-dive/cmd/plugin | ||
PROJECT ?= pod-dive | ||
REPOPATH ?= github.com/caiobegotti/$(PROJECT) | ||
COMMIT := $(shell git rev-parse HEAD) | ||
VERSION ?= $(shell git describe --always --tags --dirty="-WIP") | ||
GOOS ?= $(shell go env GOOS) | ||
GOPATH ?= $(shell go env GOPATH) | ||
|
||
BUILDDIR := out | ||
PLATFORMS ?= darwin/amd64 windows/amd64 linux/amd64 | ||
DISTFILE := $(BUILDDIR)/$(VERSION).tar.gz | ||
ASSETS := $(BUILDDIR)/pod-dive-$(GOARCH)-darwin.tar.gz $(BUILDDIR)/pod-dive-$(GOARCH)-linux.tar.gz $(BUILDDIR)/pod-dive-$(GOARCH)-windows.zip | ||
CHECKSUMS := $(patsubst %,%.sha256,$(ASSETS)) | ||
|
||
VERSION_PACKAGE := $(REPOPATH)/pkg/pod-dive/version | ||
|
||
DATE_FMT = %Y-%m-%dT%H:%M:%SZ | ||
ifdef SOURCE_DATE_EPOCH | ||
# GNU and BSD date require different options for a fixed date | ||
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null) | ||
else | ||
BUILD_DATE ?= $(shell date "+$(DATE_FMT)") | ||
endif | ||
GO_LDFLAGS :="-s -w | ||
GO_LDFLAGS += -X $(VERSION_PACKAGE).version=$(VERSION) | ||
GO_LDFLAGS += -X $(VERSION_PACKAGE).buildDate=$(BUILD_DATE) | ||
GO_LDFLAGS += -X $(VERSION_PACKAGE).gitCommit=$(COMMIT) | ||
GO_LDFLAGS +=" | ||
|
||
ifdef ZOPFLI | ||
COMPRESS:=zopfli -c | ||
else | ||
COMPRESS:=gzip --best -k -c | ||
endif | ||
|
||
GO_FILES := $(shell find . -type f -name '*.go') | ||
|
||
.PHONY: all | ||
all: clean lint test dev | ||
|
||
.PHONY: test | ||
test: | ||
go test ./pkg/... ./cmd/... -coverprofile cover.out | ||
go test ./... | ||
|
||
.PHONY: fmt | ||
fmt: | ||
go fmt ./pkg/... ./cmd/... | ||
.PHONY: help | ||
help: | ||
@echo 'Valid make targets:' | ||
@echo ' - all: build binaries for all supported platforms' | ||
@echo ' - clean: clean up build directory' | ||
@echo ' - coverage: run unit tests with coverage' | ||
@echo ' - deploy: build artifacts for a new deployment' | ||
@echo ' - dev: build the binary for the current platform' | ||
@echo ' - dist: create a tar archive of the source code' | ||
@echo ' - help: print this help' | ||
@echo ' - lint: run fmt and vet' | ||
@echo ' - test: run unit tests' | ||
@echo ' - build: build binaries for all supported platforms' | ||
|
||
.PHONY: coverage | ||
coverage: $(BUILDDIR) | ||
go test -coverprofile=$(BUILDDIR)/coverage.txt -covermode=atomic ./... | ||
|
||
.PHONY: dev | ||
dev: CGO_ENABLED := 1 | ||
dev: GO_LDFLAGS := $(subst -s -w,,$(GO_LDFLAGS)) | ||
|
||
# go get k8s.io/client-go@v11.0.0 | ||
# go get k8s.io/api@kubernetes-1.14.0 | ||
# go get k8s.io/apimachinery@kubernetes-1.14.0 | ||
# go get k8s.io/cli-runtime@kubernetes-1.14.0 | ||
dev: | ||
go build -race -ldflags $(GO_LDFLAGS) -o pod-dive $(REPOPATH)/cmd/plugin | ||
|
||
.PHONY: vet | ||
vet: | ||
build: $(GO_FILES) $(BUILDDIR) | ||
gox -osarch="$(PLATFORMS)" -ldflags $(GO_LDFLAGS) -output="out/pod-dive-{{.Arch}}-{{.OS}}" $(REPOPATH)/cmd/plugin | ||
|
||
.PHONY: lint | ||
lint: | ||
go fmt ./pkg/... ./cmd/... | ||
go vet ./pkg/... ./cmd/... | ||
|
||
.PHONY: kubernetes-deps | ||
kubernetes-deps: | ||
go get k8s.io/client-go@v11.0.0 | ||
go get k8s.io/api@kubernetes-1.14.0 | ||
go get k8s.io/apimachinery@kubernetes-1.14.0 | ||
go get k8s.io/cli-runtime@kubernetes-1.14.0 | ||
.PRECIOUS: %.zip | ||
%.zip: %.exe | ||
cp LICENSE $(BUILDDIR) && \ | ||
cd $(BUILDDIR) && \ | ||
zip $(patsubst $(BUILDDIR)/%, %, $@) LICENSE $(patsubst $(BUILDDIR)/%, %, $<) | ||
|
||
.PRECIOUS: %.gz | ||
%.gz: % | ||
$(COMPRESS) "$<" > "$@" | ||
|
||
%.tar: % | ||
cp LICENSE $(BUILDDIR) | ||
tar cf "$@" -C $(BUILDDIR) LICENSE $(patsubst $(BUILDDIR)/%,%,$^) | ||
|
||
$(BUILDDIR): | ||
mkdir -p "$@" | ||
|
||
%.sha256: % | ||
shasum -a 256 $< > $@ | ||
|
||
.INTERMEDIATE: $(DISTFILE:.gz=) | ||
$(DISTFILE:.gz=): $(BUILDDIR) | ||
git archive --prefix="pod-dive-$(VERSION)/" --format=tar HEAD > "$@" | ||
|
||
.PHONY: deploy | ||
deploy: $(CHECKSUMS) | ||
$(RM) $(BUILDDIR)/LICENSE | ||
|
||
.PHONY: dist | ||
dist: $(DISTFILE) | ||
|
||
.PHONY: setup | ||
setup: | ||
make -C setup | ||
.PHONY: clean | ||
clean: | ||
$(RM) -r $(BUILDDIR) pod-dive | ||
|
||
# https://github.com/guessi/kubectl-grep/blo | ||
$(BUILDDIR)/pod-dive-amd64-linux: build | ||
$(BUILDDIR)/pod-dive-amd64-darwin: build | ||
$(BUILDDIR)/pod-dive-amd64-windows.exe: build | ||
|
||
# https://github.com/corneliusweig/ketall/blob/master/Makefile | ||
# https://github.com/guessi/kubectl-grep/blo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters