-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
179 lines (149 loc) · 5.44 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
ROOT_DIRECTORY := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
include $(ROOT_DIRECTORY)/hack/include/help.mk
include $(ROOT_DIRECTORY)/hack/include/tools.mk
include $(ROOT_DIRECTORY)/hack/include/build.mk
GCP_PROJECT ?= pluralsh
APP_NAME ?= plural-cli
APP_VSN ?= $(shell git describe --tags --always --dirty)
APP_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%S%z")
BUILD ?= $(shell git rev-parse --short HEAD)
DKR_HOST ?= dkr.plural.sh
GOOS ?= darwin
GOARCH ?= arm64
GOLANG_CROSS_VERSION ?= v1.20.2
PACKAGE ?= github.com/pluralsh/plural
BASE_LDFLAGS ?= -s -w
LDFLAGS ?= $(BASE_LDFLAGS) $\
-X "$(PACKAGE)/cmd/plural.Version=$(APP_VSN)" $\
-X "$(PACKAGE)/cmd/plural.Commit=$(BUILD)" $\
-X "$(PACKAGE)/cmd/plural.Date=$(APP_DATE)" $\
-X "$(PACKAGE)/pkg/scm.GitlabClientSecret=${GITLAB_CLIENT_SECRET}" $\
-X "$(PACKAGE)/pkg/scm.BitbucketClientSecret=${BITBUCKET_CLIENT_SECRET}"
WAILS_TAGS ?= desktop,production,ui,debug
WAILS_BINDINGS_TAGS ?= bindings,generate
WAILS_BINDINGS_BINARY_NAME ?= wailsbindings
TAGS ?= $(WAILS_TAGS)
OUTFILE ?= plural.o
# Targets to run before other targets
# install-tools - Install binaries required to run targets
PRE := install-tools
.PHONY: git-push
git-push:
git pull --rebase
git push
.PHONY: install
install: build-cli-ui
mv $(OUTFILE) ~/bin/plural
.PHONY: build-cli
build-cli: ## Build a CLI binary for the host architecture without embedded UI
go build -ldflags='$(LDFLAGS)' -o $(OUTFILE) .
.PHONY: build-cli-ui
build-cli-ui: $(PRE) generate-bindings ## Build a CLI binary for the host architecture with embedded UI
CGO_LDFLAGS=$(CGO_LDFLAGS) go build -tags $(WAILS_TAGS) -ldflags='$(LDFLAGS)' -o $(OUTFILE) .
.PHONY: build-web
build-web: ## Build just the embedded UI
cd pkg/ui/web && yarn --immutable && yarn build
.PHONY: run-web
run-web: $(PRE) ## Run the UI for development
@CGO_LDFLAGS=$(CGO_LDFLAGS) wails dev -tags ui -browser -skipbindings
# This is somewhat an equivalent of wails `GenerateBindings` method.
# Ref: https://github.com/wailsapp/wails/blob/master/v2/pkg/commands/bindings/bindings.go#L28
.PHONY: generate-bindings
generate-bindings: build-web ## Generate backend bindings for the embedded UI
@echo Building bindings binary
@CGO_LDFLAGS=$(CGO_LDFLAGS) go build -tags $(WAILS_BINDINGS_TAGS) -ldflags='$(LDFLAGS)' -o $(WAILS_BINDINGS_BINARY_NAME) .
@echo Generating bindings
@./$(WAILS_BINDINGS_BINARY_NAME) > /dev/null 2>&1
@echo Cleaning up
@rm $(WAILS_BINDINGS_BINARY_NAME)
.PHONY: release
release:
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags='$(LDFLAGS)' -o $(OUTFILE) .
.PHONY: setup
setup: ## sets up your local env (for mac only)
brew install golangci-lint
.PHONY: plural
plural: ## uploads to plural
plural apply -f plural/Pluralfile
.PHONY: build
build: ## Build the Docker image
docker build --build-arg APP_NAME=$(APP_NAME) \
--build-arg APP_VSN=$(APP_VSN) \
--build-arg APP_DATE=$(APP_DATE) \
--build-arg APP_COMMIT=$(BUILD) \
-t $(APP_NAME):$(APP_VSN) \
-t $(APP_NAME):latest \
-t gcr.io/$(GCP_PROJECT)/$(APP_NAME):$(APP_VSN) \
-t $(DKR_HOST)/plural/$(APP_NAME):$(APP_VSN) .
.PHONY: build-cloud
build-cloud: ## build the cloud docker image
docker build --build-arg APP_NAME=$(APP_NAME) \
--build-arg APP_VSN=$(APP_VSN) \
--build-arg APP_DATE=$(APP_DATE) \
--build-arg APP_COMMIT=$(BUILD) \
-t $(APP_NAME)-cloud:$(APP_VSN) \
-t $(APP_NAME)-cloud:latest \
-t gcr.io/$(GCP_PROJECT)/$(APP_NAME)-cloud:$(APP_VSN) \
-t $(DKR_HOST)/plural/$(APP_NAME)-cloud:$(APP_VSN) -f dockerfiles/Dockerfile.cloud .
.PHONY: build-dind
build-dind: ## build the dind docker image
docker build --build-arg APP_NAME=$(APP_NAME) \
--build-arg APP_VSN=$(APP_VSN) \
--build-arg APP_DATE=$(APP_DATE) \
--build-arg APP_COMMIT=$(BUILD) \
-t $(APP_NAME)-cloud:$(APP_VSN) \
-t $(APP_NAME)-cloud:latest \
-t gcr.io/$(GCP_PROJECT)/$(APP_NAME)-cloud:$(APP_VSN) \
-t $(DKR_HOST)/plural/$(APP_NAME)-dind:$(APP_VSN) -f dockerfiles/Dockerfile.dind .
.PHONY: push
push: ## push to gcr
docker push gcr.io/$(GCP_PROJECT)/$(APP_NAME):$(APP_VSN)
docker push $(DKR_HOST)/plural/${APP_NAME}:$(APP_VSN)
.PHONY: push-cloud
push-cloud: ## push to gcr
docker push gcr.io/$(GCP_PROJECT)/$(APP_NAME):$(APP_VSN)-cloud
docker push $(DKR_HOST)/plural/${APP_NAME}:$(APP_VSN)-cloud
.PHONY: generate
generate:
go generate ./...
.PHONY: bake-ami
bake-ami:
cd packer && packer build -var "cli_version=$(APP_VSN)" .
@echo "baked ami for all regions"
.PHONY: up
up: # spin up local server
docker-compose up
.PHONY: pull
pull: # pulls new server image
docker-compose pull
.PHONY: serve
serve: build-cloud # build cloud version of plural-cli and start plural serve in docker
docker kill plural-cli || true
docker run --rm --name plural-cli -p 8080:8080 -d plural-cli:latest-cloud
.PHONY: release-vsn
release-vsn: # tags and pushes a new release
@read -p "Version: " tag; \
git checkout main; \
git pull --rebase; \
git tag -a $$tag -m "new release"; \
git push origin $$tag
.PHONY: setup-tests
setup-tests:
go install gotest.tools/gotestsum@latest
.PHONY: test
test: setup-tests
gotestsum --format testname -- -v -race ./pkg/... ./cmd/...
.PHONY: format
format: # formats all go code to prep for linting
golangci-lint run --fix
.PHONY: genmock
genmock: # generates mocks before running tests
hack/gen-client-mocks.sh
.PHONY: lint
lint:
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.50.1 golangci-lint run
.PHONY: delete-tag
delete-tag:
@read -p "Version: " tag; \
git tag -d $$tag; \
git push origin :$$tag