-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
97 lines (70 loc) · 3.17 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
NAME=bitwarden-sdk-server
# Set the build dir, where built cross-compiled binaries will be output
BUILDDIR := bin
# VERSION defines the project version for the bundle.
VERSION ?= 0.0.1
UNAME ?= $(shell uname|tr '[:upper:]' '[:lower:]')
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
MKCERT ?= $(LOCALBIN)/mkcert
UNAME ?= $(shell uname|tr '[:upper:]' '[:lower:]')
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# List the GOOS and GOARCH to build
GO_LDFLAGS_STATIC="-s -w $(CTIMEVAR) -extldflags -static"
GOLANGCI_LINT_VERSION ?= v1.57.2
MKCERT_VERSION ?= v1.4.4
.DEFAULT_GOAL := help
.PHONY: mkcert
mkcert: $(MKCERT)
$(MKCERT): $(LOCALBIN)
curl -L "https://github.com/FiloSottile/mkcert/releases/download/$(MKCERT_VERSION)/mkcert-$(MKCERT_VERSION)-$(UNAME)-amd64" -o $(LOCALBIN)/mkcert
chmod +x $(LOCALBIN)/mkcert
##@ Build
build: ## Builds binaries
CGO_LDFLAGS="-framework CoreFoundation" CGO_ENABLED=1 go build -ldflags='-s -w' -o $(LOCALBIN)/$(NAME) main.go
build-docker: ## Builds binaries
CC=musl-gcc CGO_LDFLAGS="-lm" CGO_ENABLED=1 go build -a -ldflags '-linkmode external -extldflags "-static -Wl,-unresolved-symbols=ignore-all"' -o $(LOCALBIN)/$(NAME) main.go
##@ Testing
.PHONY: lint
lint: golangci-lint ## Run golangci-lint.
$(GOLANGCI_LINT) run
clean: ## Runs go clean
go clean -i
test-ci: ## Test the project
CC=musl-gcc CGO_LDFLAGS="-lm" CGO_ENABLED=1 go test ./... -coverprofile cover.out
.PHONY: prime-test-cluster
prime-test-cluster: mkcert
./hack/prime_test_cluster.sh
helm-test:
@helm unittest --file tests/*.yaml --file 'tests/**/*.yaml' deploy/charts/bitwarden-sdk-server/
helm-test-update:
@helm unittest -u --file tests/*.yaml --file 'tests/**/*.yaml' deploy/charts/bitwarden-sdk-server/
##@ Docker
IMG ?= ghcr.io/external-secrets/bitwarden-sdk-server
TAG ?= v0.1.0
docker_image: ## Creates a docker image. Requires `image` and `version` variables on command line
docker build -t $(IMG):$(VERSION) .
##@ Utilities
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT): $(LOCALBIN)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
help: ## Display this help. Thanks to https://www.thapaliya.com/en/writings/well-documented-makefiles/
ifeq ($(OS),Windows_NT)
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make <target>\n"} /^[a-zA-Z_-]+:.*?##/ { printf " %-40s %s\n", $$1, $$2 } /^##@/ { printf "\n%s\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
else
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-40s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
endif