generated from brevdev/seed
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathMakefile
More file actions
356 lines (290 loc) · 10.9 KB
/
Makefile
File metadata and controls
356 lines (290 loc) · 10.9 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
.DEFAULT_GOAL := fast-build
VERSION := dev-$(shell git rev-parse HEAD | cut -c 1-8)
# Cross-compilation via Docker (golang:1.24 native Linux container).
# When arch=<GOOS>/<GOARCH> is provided, spin up a container that matches
# the target platform so CGO uses the native Linux gcc/GNU ld toolchain
_GOMODCACHE := $(shell go env GOMODCACHE)
ifdef arch
_CROSS_GOOS := $(word 1,$(subst /, ,$(arch)))
_CROSS_GOARCH := $(word 2,$(subst /, ,$(arch)))
_BUILD_PREFIX := docker run --rm \
--platform $(_CROSS_GOOS)/$(_CROSS_GOARCH) \
-v $(CURDIR):/app \
-v $(_GOMODCACHE):/go/pkg/mod \
-e CGO_ENABLED=1 \
-e GOPRIVATE=github.com/brevdev/* \
-e GONOSUMDB=github.com/brevdev/* \
-w /app \
golang:1.24
else
_BUILD_PREFIX := CGO_ENABLED=1
endif
.PHONY: fast-build
fast-build: ## go build -o brev
$(call print-target)
echo ${VERSION}
CGO_ENABLED=1 go build -o brev -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}"
.PHONY: local
local: ## build with env wrapper (use: make local env=dev0|dev1|dev2|stg arch=linux/amd64, or make local for defaults)
$(call print-target)
ifdef env
@echo "Building with env=$(env) wrapper..."
@echo ${VERSION}
$(_BUILD_PREFIX) go build -o brev-local -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}"
@echo '#!/bin/sh' > brev
@echo '# Auto-generated wrapper with environment overrides' >> brev
@echo 'export BREV_CONSOLE_URL="https://localhost.nvidia.com:3000"' >> brev
@echo 'export BREV_AUTH_URL="https://api.stg.ngc.nvidia.com"' >> brev
@echo 'export BREV_AUTH_ISSUER_URL="https://stg.login.nvidia.com"' >> brev
@echo 'export BREV_API_URL="https://bd.$(env).brev.nvidia.com"' >> brev
@echo 'export BREV_PUBLIC_API_URL="https://api.$(env).brev.nvidia.com"' >> brev
@echo 'export BREV_GRPC_URL="api.$(env).brev.nvidia.com:443"' >> brev
@echo 'exec "$$(cd "$$(dirname "$$0")" && pwd)/brev-local" "$$@"' >> brev
@chmod +x brev
else
@echo "Building without environment overrides (using config.go defaults)..."
$(_BUILD_PREFIX) go build -o brev -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}"
endif
.PHONY: install-dev
install-dev: fast-build ## go install
cp brev $(shell go env GOPATH)/bin/
.PHONY: version
version:
echo ${VERSION}
.PHONY: dev
dev: ## dev build
dev: clean install-tools generate vet fmt lint test mod-tidy
.PHONY: ci
ci: ## CI build
ci: dev diff
.PHONY: clean
clean: ## remove files created during build pipeline
$(call print-target)
rm -rf dist
rm -f coverage.*
.PHONY: install-tools
install-tools: ## go install tools
$(call print-target)
cd tools && go install $(shell cd tools && go list -e -f '{{ join .Imports " " }}' -tags=tools)
.PHONY: generate
generate: ## go generate
$(call print-target)
go generate ./...
.PHONY: vet
vet: ## go vet
$(call print-target)
go vet ./...
.PHONY: fmt
fmt: ## go fmt
$(call print-target)
gofumpt -l -w .
fmtcheck: ## go fmt --check
$(call print-target)
# gofumpt check
gofumpt -l -d -e .
.PHONY: lint
lint: ## golangci-lint
$(call print-target)
golangci-lint run --timeout 5m
.PHONY: test
test: ## go test with race detector and code covarage
$(call print-target)
go test -race -covermode=atomic -coverprofile=coverage.out ./pkg/...
go tool cover -html=coverage.out -o coverage.html
.PHONY: test-e2e
test-e2e: ## go test with race detector and code covarage
$(call print-target)
go test -timeout 90m -race -covermode=atomic -coverprofile=coverage.out ./e2etest/...
.PHONY: mod-tidy
mod-tidy: ## go mod tidy
$(call print-target)
go mod tidy
cd tools && go mod tidy
.PHONY: diff
diff: ## git diff
$(call print-target)
git diff --exit-code
RES=$$(git status --porcelain) ; if [ -n "$$RES" ]; then echo $$RES && exit 1 ; fi
.PHONY: release
release: ## goreleaser --rm-dist
release: install-tools
$(call print-target)
goreleaser --rm-dist
# Docker-based build/release using goreleaser-cross.
# See: https://goreleaser.com/limitations/cgo (goreleaser needs explicit instructions for CGO builds)
# See: https://github.com/goreleaser/goreleaser-cross (docker image with cross-compilers for CGO builds)
# See: https://github.com/goreleaser/example-cross (example of using goreleaser-cross)
GOLANG_CROSS_VERSION ?= v1.24.5
BREV_MODULE ?= github.com/brevdev/brev-cli
# Dry-run build using goreleaser-cross
.PHONY: build-cross
build-cross:
$(call print-target)
docker run --rm \
-e CGO_ENABLED=1 \
-v "$$(pwd):/go/src/$(BREV_MODULE)" \
-w "/go/src/$(BREV_MODULE)" \
ghcr.io/goreleaser/goreleaser-cross:$(GOLANG_CROSS_VERSION) \
--clean --skip=validate --skip=publish
# Release using goreleaser-cross. Requires GITHUB_TOKEN to be set.
.PHONY: release-cross
release-cross:
$(call print-target)
docker run --rm \
-e CGO_ENABLED=1 \
-e "GITHUB_TOKEN=$$GITHUB_TOKEN" \
-v "$$(pwd):/go/src/$(BREV_MODULE)" \
-w "/go/src/$(BREV_MODULE)" \
ghcr.io/goreleaser/goreleaser-cross:$(GOLANG_CROSS_VERSION) \
release --clean
.PHONY: run
run: ## go run
@go run -race .
.PHONY: go-clean
go-clean: ## go clean build, test and modules caches
$(call print-target)
go clean -r -i -cache -testcache -modcache
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
define print-target
@printf "Executing target: \033[36m$@\033[0m\n"
endef
.PHONY: smoke-test
smoke-test: ## runs `brev version`
$(call print-target)
go run main.go --version
.PHONY: full-smoke-test
full-smoke-test: ci fast-build
# relocate directories used by cli if they exist
[ ! -d ~/.ssh ] || mv ~/.ssh ~/.ssh.bak
[ ! -d ~/.config/Jetbrains ] || mv ~/.config/Jetbrains ~/.config/Jetbrains.bak
[ ! -d ~/.brev ] || mv ~/.brev ~/.brev.bak
# cli user flows to smoke test
# login, set org, list workspaces, start, stop, start, reset, delete & brev jetbrains
./brev login
./brev set brev.dev
./brev ls
./brev start https://github.com/brevdev/todo-template
./brev stop brevdev/todo-template
echo "may have to run this again in a different term"
./brev start brevdev/todo-template
./brev reset brevdev/todo-template
./brev delete brevdev/todo-template
sleep 5
./brev jetbrains
# restore directories used by cli
[ ! -d ~/.ssh.bak ] || mv ~/.ssh.bak ~/.ssh
[ ! -d ~/.config/Jetbrains.bak ] || mv ~/.config/Jetbrains.bak ~/.config/Jetbrains
[ ! -d ~/.brev.bak ] || mv ~/.brev.bak ~/.brev
.PHONY: build-linux-amd
build-linux-amd:
$(call print-target)
echo ${VERSION}
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o brev -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}"
.PHONY: build-darwin-amd
build-darwin-amd:
$(call print-target)
echo ${VERSION}
GOOS=darwin GOARCH=amd64 go build -o brev -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}"
.PHONY: setup-workspace-repo
setup-workspace-repo: build-linux-amd
make setup-workspace setup_param_path=assets/test_setup_v0_repo.json
.PHONY: setup-workspace-norepo
setup-workspace-norepo: build-linux-amd
make setup-workspace setup_param_path=assets/test_setup_v0_norepo.json
.PHONY: setup-workspace-blank
setup-workspace-blank:
make setup-workspace setup_param_path=assets/blank_v0.json
container_name=setup-workspace
image_name=test-workspace
.PHONY: build-test-workspace
build-test-workspace:
cd workspacedocker && docker build -t $(image_name) . && cd -
.PHONY: setup-workspace
setup-workspace: build-linux-amd build-test-workspace
# run docker image copy in binary with volume config map + exec setup workspace
[ "${setup_param_path}" ] || ( echo "'setup_param_path' not provided"; exit 1 )
make time
docker kill $(container_name) || true
docker run -d --privileged=true --name $(container_name) --rm -it -p 22776:22778 -p 2222:22 brevdev/ubuntu-proxy:0.3.13 zsh
docker exec -it $(container_name) mkdir /etc/meta
docker cp ${setup_param_path} $(container_name):/etc/meta/setup_v0.json
docker cp brev $(container_name):/usr/local/bin/
make time
docker exec -it $(container_name) /usr/local/bin/brev setupworkspace
make time
.PHONY: workspace-dev-script
workspace-dev-script: fast-build clean-simulated-workspace
make simulate-workspace setup_param_path=assets/std_setup_v0.json
echo "exit the shell and re-run to reset workspace"
make shell-into-workspace
.PHONY: simulate-workspace
simulate-workspace:
[ "${setup_param_path}" ] || ( echo "'setup_param_path' not provided"; exit 1 )
make time
docker kill $(container_name) || true
echo "modify workspace files in devworkspace"
docker run -d --privileged=true --name $(container_name) --rm -it -p 2222:22 -v $(shell pwd)/devworkspace:/home/brev/workspace brevdev/ubuntu-proxy:0.3.13 zsh
docker exec -it $(container_name) mkdir /etc/meta
docker cp ${setup_param_path} $(container_name):/etc/meta/setup_v0.json
# remove when released binary has setupworkspace
docker cp brev $(container_name):/usr/local/bin/
make time
docker exec -it $(container_name) /usr/local/bin/brev setupworkspace
make time
.PHONY:clean-simulated-workspace
clean-simulated-workspace:
sudo rm -rf devworkspace
.PHONY: shell-into-workspace
shell-into-workspace:
docker exec --user brev -it $(container_name) zsh --login
time:
date +"%FT%T%z"
get-latest-tag:
git describe --tags --abbrev=0
version-bump-patch:
make version-bump type=patch
version-bump-minor:
make version-bump type=minor
version-bump-major:
make version-bump type=major
fetch-tags:
git fetch --all --tags
version-bump: fetch-tags
[ "${type}" ] || ( echo "'type' not provided [patch, minor, major]"; exit 1 )
bump2version --current-version $(shell git describe --tags --abbrev=0) ${type} --list --tag --serialize v{major}.{minor}.{patch} --tag-name {new_version} | grep new_version | sed -r s,"^.*=",, | xargs git push origin
lr := $(shell git rev-parse latest-review)
cr := $(shell git rev-parse main)
review:
git diff ${lr}...${cr}
review-github:
open https://github.com/brevdev/brev-cli/compare/${lr}...${cr}
review_tag := review-`date +"%F-%H-%M"`
review-mark-done:
git tag latest-review -f
git tag -a ${review_tag}
git push origin latest-review --force
git push origin ${review_tag}
gen-e2e:
cat e2etest/setup/setup_test.go| grep -Eo "Test_\w+" | xargs python bin/gen-e2e-actions.py
## removed queued jobs from github actions
remove-queued-jobs:
./bin/remove-queued-jobs.sh
new-cmd:
mkdir -p pkg/cmd/${name}
touch pkg/cmd/${name}/${name}.go
# populate the template
./bin/newcmd.sh ${name} > pkg/cmd/${name}/${name}.go
.PHONY: develop-with-nix
develop-with-nix:
nix develop .
.PHONY: update-devplane-deps
update-devplane-deps: ## update devplane dependencies (use: make update-devplane-deps commit=<hash-or-tag>, defaults to latest)
@COMMIT=$${commit:-latest}; \
echo "Updating devplane dependencies to: $$COMMIT"; \
GOPRIVATE=github.com/brevdev/* go get -u github.com/brevdev/dev-plane@$$COMMIT; \
go get buf.build/gen/go/brevdev/devplane/grpc/go@$$COMMIT; \
go get buf.build/gen/go/brevdev/devplane/protocolbuffers/go@$$COMMIT; \
GOPRIVATE=github.com/brevdev/* go mod tidy; \
echo "Successfully updated to $$COMMIT"