-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Marco Franssen <[email protected]>
- Loading branch information
1 parent
294de9d
commit 84f25ac
Showing
4 changed files
with
135 additions
and
79 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
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
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,92 +1,148 @@ | ||
PLUGIN_NAME="ksops" | ||
|
||
# Default to installing KSOPS | ||
default: install | ||
GOPATH ?= $(shell go env GOPATH) | ||
STATICCHECK := $(GOPATH)/bin/staticcheck | ||
KUSTOMIZE := $(GOPATH)/bin/kustomize | ||
SOPS := $(GOPATH)/bin/sops | ||
GO_MOD_OUTDATED := $(GOPATH)/bin/go-mod-outdated | ||
PREREQS := $(STATICCHECK) $(KUSTOMIZE) $(GO_MOD_OUTDATED) | ||
|
||
.PHONY: install | ||
install: go-install clean build install-plugin | ||
GIT_HOOKS := pre-push pre-commit | ||
|
||
.PHONY: install-plugin | ||
install-plugin: | ||
./scripts/install-ksops.sh | ||
GO_LD_FLAGS := "-w -s" | ||
GO_BUILD_FLAGS := -trimpath -ldflags $(GO_LD_FLAGS) | ||
|
||
.PHONY: build | ||
build: | ||
go build -o $(PLUGIN_NAME) | ||
IMAGE ?= viaductai/ksops | ||
RELEASE ?= | ||
BUILDX_ARGS ?= $(if $(RELEASE),--platform $(PLATFORMS) --push,--load) | ||
GO_VERSION := $(shell cat go.mod | grep -m1 'go' | awk '{print $$2}') | ||
GIT_VERSION ?= $(shell git describe --tags --always --dirty) | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f $(PLUGIN_NAME) | ||
rm -rf $(XDG_CONFIG_HOME)/kustomize/plugin/viaduct.ai/v1/ || true | ||
rm -rf $(HOME)/sigs.k8s.io/kustomize/plugin/viaduct.ai/v1/ || true | ||
rm -f $(shell command -v $(PLUGIN_NAME)) | ||
.PHONY: help | ||
help: ## Display this help. | ||
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-18s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | ||
|
||
.PHONY: kustomize | ||
kustomize: | ||
./scripts/install-kustomize.sh | ||
.PHONY: FORCE | ||
FORCE: ; | ||
|
||
.PHONY: sops | ||
sops: | ||
go get -u go.mozilla.org/sops/cmd/sops | ||
##@ Prerequisites: | ||
|
||
.PHONY: download-dependencies | ||
download-dependencies: | ||
go mod download | ||
go mod tidy | ||
go install honnef.co/go/tools/cmd/staticcheck@latest | ||
.PHONY: deps | ||
deps: ## Download go modules | ||
@echo "Downloading go modules…" | ||
@go mod download | ||
|
||
$(STATICCHECK): FORCE | ||
@echo "Installing staticcheck…" | ||
@go install honnef.co/go/tools/cmd/staticcheck@latest | ||
|
||
$(GO_MOD_OUTDATED): FORCE | ||
@echo "Installing go-mod-outdated…" | ||
@go install github.com/psampaz/go-mod-outdated@latest | ||
|
||
$(SOPS): FORCE | ||
@echo "Installing sops…" | ||
@go install go.mozilla.org/sops/cmd/sops@latest | ||
|
||
.PHONY: ci-tools | ||
prereqs: $(PREREQS) ## Install prerequisites | ||
|
||
$(KUSTOMIZE): FORCE | ||
./scripts/install-kustomize.sh | ||
|
||
##@ Development: | ||
|
||
.PHONY: setup | ||
setup: .git/hooks/pre-push .git/hooks/pre-commit kustomize sops download-dependencies | ||
setup: install-git-hooks $(KUSTOMIZE) $(SOPS) deps ## Setup the development environment | ||
|
||
.PHONY: install-git-hooks | ||
install-git-hooks: $(addprefix .git/hooks/,$(GIT_HOOKS)) ## Install Git hooks | ||
|
||
.PHONY: tidy | ||
tidy: ## Run go mod tidy | ||
@echo "Running go mod tidy…" | ||
@go mod tidy | ||
|
||
$(PLUGIN_NAME): FORCE | ||
@echo "Building $(PLUGIN_NAME)…" | ||
@go build $(GO_BUILD_FLAGS) -o $@ | ||
|
||
.PHONY: build | ||
build: $(PLUGIN_NAME) ## Compile the plugin | ||
|
||
.PHONY: test | ||
test: import-test-keys ## Run go tests | ||
@echo "Running go test…" | ||
@go test -v -race -count=1 ./... | ||
|
||
.PHONY: import-test-keys | ||
import-test-keys: | ||
import-test-keys: ## Import GPG test keys | ||
@echo "Importing GPG test keys…" | ||
gpg --import test/key.asc | ||
|
||
.PHONY: test | ||
test: install setup-test-files go-test | ||
.PHONY: fmt | ||
fmt: ## Run go fmt | ||
@echo "Running go fmt…" | ||
@go fmt . | ||
|
||
.PHONY: setup-test-files | ||
setup-test-files: | ||
./scripts/setup-test-files.sh | ||
.PHONY: vet | ||
vet: ## Run go vet | ||
@echo "Running go vet…" | ||
@go vet -v ./... | ||
|
||
.PHONY: go-install | ||
go-install: | ||
go install | ||
.PHONY: lint | ||
lint: $(STATICCHECK) ## Run staticcheck linter | ||
@echo "Running staticcheck…" | ||
@$< | ||
|
||
.PHONY: go-test | ||
go-test: | ||
go test -v ./... | ||
.PHONY: outdated | ||
outdated: $(GO_MOD_OUTDATED) ## List outdated dependencies. | ||
@go list -u -m -json all | $< -update | ||
|
||
.PHONY: go-fmt | ||
go-fmt: | ||
go fmt . | ||
.PHONY: docker-build | ||
docker-build: ## Build the Docker image. | ||
@echo "Building Docker image $(IMAGE):$(GIT_VERSION)…" | ||
@docker buildx build \ | ||
--build-arg GO_VERSION=$(GO_VERSION) \ | ||
$(BUILDX_ARGS) \ | ||
-t $(IMAGE):$(GIT_VERSION) . | ||
|
||
.PHONY: go-vet | ||
go-vet: | ||
go vet -v ./... | ||
##@ Install: | ||
|
||
.PHONY: install | ||
install: go-install clean build install-plugin | ||
|
||
.PHONY: lint | ||
lint: | ||
staticcheck | ||
.PHONY: install-plugin | ||
install-plugin: ## Install the ksops plugin | ||
./scripts/install-ksops.sh | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f $(PLUGIN_NAME) | ||
rm -rf $(XDG_CONFIG_HOME)/kustomize/plugin/viaduct.ai/v1/ || true | ||
rm -rf $(HOME)/sigs.k8s.io/kustomize/plugin/viaduct.ai/v1/ || true | ||
rm -f $(shell command -v $(PLUGIN_NAME)) | ||
|
||
.PHONY: go-install | ||
go-install: | ||
go install | ||
|
||
################################################################################ | ||
# Git Hooks | ||
################################################################################ | ||
## Git hooks to validate worktree is clean before commit/push | ||
.git/hooks/pre-push: Makefile | ||
# Create Git pre-push hook | ||
echo 'make pre-push' > .git/hooks/pre-push | ||
chmod +x .git/hooks/pre-push | ||
|
||
.git/hooks/pre-commit: Makefile | ||
# Create Git pre-commit hook | ||
echo 'make pre-commit' > .git/hooks/pre-commit | ||
chmod +x .git/hooks/pre-commit | ||
.git/hooks/pre-push: | ||
@echo "Installing pre-push hook…" | ||
@echo 'make pre-push' > .git/hooks/pre-push | ||
@chmod +x .git/hooks/pre-push | ||
|
||
.git/hooks/pre-commit: | ||
@echo "Installing pre-commit hook…" | ||
@echo 'make pre-commit' > .git/hooks/pre-commit | ||
@chmod +x .git/hooks/pre-commit | ||
|
||
.PHONY: pre-commit | ||
pre-commit: download-dependencies lint go-fmt go-vet | ||
pre-commit: download-dependencies lint fmt vet | ||
|
||
.PHONY: pre-push | ||
pre-push: test |
This file was deleted.
Oops, something went wrong.