-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMakefile
More file actions
323 lines (280 loc) · 10.5 KB
/
Copy pathMakefile
File metadata and controls
323 lines (280 loc) · 10.5 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
NAME ?= prldevops
export PACKAGE_NAME ?= $(NAME)
export DOCKER_PACKAGE_NAME ?= prl-devops-service
export DOCKER_IMAGE_REPOSITORY ?= ghcr.io/parallels/$(DOCKER_PACKAGE_NAME)
ifeq ($(OS),Windows_NT)
export VERSION:=$(shell type VERSION)
else
export VERSION:=$(shell cat VERSION)
export BUILD_ID:=$(shell date +%s)
export SHORT_VERSION:=$(shell echo $(VERSION) | cut -d'.' -f1,2)
export BUILD_VERSION:=$(shell echo $(SHORT_VERSION).$(BUILD_ID))
export GIT_COMMIT:=$(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
export BUILD_DATE:=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)
endif
VERSION_PKG = github.com/Parallels/prl-devops-service/version
BASE_LDFLAGS = -X '$(VERSION_PKG).buildVersion=$(VERSION)' \
-X '$(VERSION_PKG).buildDate=$(BUILD_DATE)' \
-X '$(VERSION_PKG).buildCommit=$(GIT_COMMIT)'
COBERTURA = cobertura
GOX = gox
GOLANGCI_LINT = golangci-lint
GOSEC = gosec
SWAG = swag
START_SUPER_LINTER_CONTAINER = start_super_linter_container
DEVELOPMENT_TOOLS = $(GOX) $(COBERTURA) $(GOLANGCI_LINT) $(SWAG) $(bundler)
SECURITY_TOOLS = $(GOSEC)
.PHONY: help
help:
# make version
# make test
# make lint
# make build
# make generate-swagger
# make generate-postman
.PHONY: version
version:
@echo Version: $(VERSION)
.PHONY: test
test:
@echo "Running tests..."
@scripts/test -d ./src
.PHONY: coverage
coverage:
@echo "Running coverage report..."
ifeq ("$(wildcard coverage)","")
@echo "Creating coverage directory..."
@mkdir coverage
endif
@cd src && go test -coverprofile coverage.txt -covermode count -v ./...
@cd src && gocov convert coverage.txt | gocov-xml >../coverage/cobertura-coverage.xml
@cd src && rm coverage.txt
.PHONY: lint
lint: $(START_SUPER_LINTER_CONTAINER)
@echo "Running linter..."
@docker cp $(PACKAGE_NAME)-linter:/tmp/lint/super-linter.log .
@echo "Linter report saved to super-linter.log"
@docker stop $(PACKAGE_NAME)-linter
@echo "Linter finished."
.PHONY: security
security-check:
@echo "Running Security Check..."
@scripts/security-check -d ./src
.PHONY: build
build:
@echo "Building..."
ifeq ($(wildcard ./out/.*),)
@echo "Creating out directory..."
@mkdir out
@mkdir out/binaries
endif
@cd src && go build -ldflags="$(BASE_LDFLAGS) -X '$(VERSION_PKG).buildChannel=stable'" -o ../out/binaries/$(PACKAGE_NAME)
@echo "Build finished."
.PHONY: build-canary
build-canary:
@echo "Building Canary..."
ifeq ($(wildcard ./out/.*),)
@echo "Creating out directory..."
@mkdir out
@mkdir out/binaries
endif
@cd src && go build -ldflags="$(BASE_LDFLAGS) -X '$(VERSION_PKG).buildChannel=canary'" -o ../out/binaries/$(PACKAGE_NAME)
@echo "Build finished."
.PHONY: build-beta
build-beta:
@echo "Building Beta..."
ifeq ($(wildcard ./out/.*),)
@echo "Creating out directory..."
@mkdir out
@mkdir out/binaries
endif
@cd src && go build -ldflags="$(BASE_LDFLAGS) -X '$(VERSION_PKG).buildChannel=beta'" -o ../out/binaries/$(PACKAGE_NAME)
@echo "Build finished."
.PHONY: build-linux-amd64
build-linux-amd64:
@echo "Building..."
ifeq ($(wildcard ./out/.*),)
@echo "Creating out directory..."
@mkdir out
@mkdir out/binaries
endif
@cd src && CGO_ENABLED=0 GOOS="linux" GOARCH="amd64" go build -ldflags="$(BASE_LDFLAGS) -X '$(VERSION_PKG).buildChannel=stable'" -o ../out/binaries/$(PACKAGE_NAME)-linux-amd64
@echo "Build finished."
.PHONY: build-windows-amd64
build-windows-amd64:
@echo "Building..."
ifeq ($(wildcard ./out/.*),)
@echo "Creating out directory..."
@mkdir out
@mkdir out/binaries
endif
@cd src && CGO_ENABLED=0 GOOS="windows" GOARCH="amd64" go build -ldflags="$(BASE_LDFLAGS) -X '$(VERSION_PKG).buildChannel=stable'" -o ../out/binaries/$(PACKAGE_NAME)-windows-amd64
@echo "Build finished."
.PHONY: build-alpine
build-alpine:
@echo "Building..."
ifeq ($(wildcard ./out/.*),)
@echo "Creating out directory..."
@mkdir out
@mkdir out/binaries
endif
@cd src && CGO_ENABLED=0 GOOS=linux go build -ldflags="$(BASE_LDFLAGS) -w -s -X '$(VERSION_PKG).buildChannel=stable'" -o ../out/binaries/$(PACKAGE_NAME)-alpine
@echo "Build finished."
.PHONY: push-alpha-container
push-alpha-container:
@echo "Building $(BUILD_VERSION) Alpha Container..."
@docker build --platform linux/amd64,linux/arm64 \
-t $(DOCKER_IMAGE_REPOSITORY):$(BUILD_VERSION)-alpha \
-t $(DOCKER_IMAGE_REPOSITORY):latest-alpha \
--build-arg VERSION=$(BUILD_VERSION) \
--build-arg BUILD_ENV=canary \
--build-arg OS=linux \
--build-arg ARCHITECTURE=amd64 \
-f Dockerfile .
@echo "Pushing $(BUILD_VERSION) Container..."
@echo "Pushing $(DOCKER_IMAGE_REPOSITORY):$(BUILD_VERSION)-alpha tag..."
@docker push $(DOCKER_IMAGE_REPOSITORY):$(BUILD_VERSION)-alpha
@echo "Pushing $(DOCKER_IMAGE_REPOSITORY):latest-alpha tag..."
@docker push $(DOCKER_IMAGE_REPOSITORY):latest-alpha
@echo "Build finished. Pushed to $(DOCKER_IMAGE_REPOSITORY):$(BUILD_VERSION)-alpha and $(DOCKER_IMAGE_REPOSITORY):latest-alpha."
.PHONY: clean-alpha
clean-alpha-container:
@echo "Removing all alpha versions from $(DOCKER_IMAGE_REPOSITORY)..."
@IMAGE_REPOSITORY=$(DOCKER_IMAGE_REPOSITORY) ./.github/workflow_scripts/remove-docker-images.sh rm --filter '.*alpha.*$$'
@echo "All alpha versions removed."
.PHONY: push-beta-container
push-beta-container:
@echo "Building $(BUILD_VERSION) Beta Container..."
@docker build --platform linux/amd64,linux/arm64 \
-t $(DOCKER_IMAGE_REPOSITORY):$(BUILD_VERSION)-beta \
-t $(DOCKER_IMAGE_REPOSITORY):unstable \
--build-arg VERSION=$(BUILD_VERSION) \
--build-arg BUILD_ENV=canary \
--build-arg OS=linux \
--build-arg ARCHITECTURE=amd64 \
-f Dockerfile .
@echo "Pushing $(BUILD_VERSION) Container..."
@echo "Pushing $(DOCKER_IMAGE_REPOSITORY):$(BUILD_VERSION)-beta tag..."
@docker push $(DOCKER_IMAGE_REPOSITORY):$(BUILD_VERSION)-beta
@echo "Pushing $(DOCKER_IMAGE_REPOSITORY):unstable tag..."
@docker push $(DOCKER_IMAGE_REPOSITORY):unstable
@echo "Build finished. Pushed to $(DOCKER_IMAGE_REPOSITORY):$(BUILD_VERSION)-beta and $(DOCKER_IMAGE_REPOSITORY):unstable."
.PHONY: clean-beta
clean-beta-container:
@echo "Removing all beta versions from $(DOCKER_IMAGE_REPOSITORY)..."
@IMAGE_REPOSITORY=$(DOCKER_IMAGE_REPOSITORY) ./.github/workflow_scripts/remove-docker-images.sh rm --filter ".*beta.*$$"
@echo "All beta versions removed."
.PHONY: clean
clean:
@echo "Cleaning..."
ifneq ("$(wildcard bin)","")
@echo "Removing bin directory..."
@rm -rf bin
endif
ifneq ("$(wildcard out)","")
@echo "Removing out directory..."
@rm -rf out
endif
ifneq ("$(wildcard coverage)","")
@echo "Removing coverage directory..."
@rm -rf out
endif
ifneq ("$(wildcard tmp)","")
@echo "Removing tmp directory..."
@rm -rf out
endif
@echo "Clean finished."
.PHONY: generate-swagger
generate-swagger:
@echo "Generating Swagger..."
@cd src && swag fmt
@cd src && swag init -g main.go
.PHONY: generate-postman
generate-postman: generate-swagger
@echo "Generating Postman collection..."
@scripts/generate-postman.sh
.PHONY: generate-api-docs
generate-api-docs: generate-swagger
@echo "Generating API documentation..."
@go run src/api_documentation/api_generate.go
.PHONY: generate-all-docs
generate-all-docs: generate-swagger generate-postman generate-api-docs
@echo "All documentation generated successfully"
.PHONY: deps
deps: $(DEVELOPMENT_TOOLS) $(SECURITY_TOOLS)
.PHONY: release-check
release-check: test lint generate-swagger generate-postman coverage security-check
.PHONY: build-docs
build-docs:
@echo "Building Documentation..."
@cd docs && bundle exec jekyll build ./docs
.PHONY: serve-docs
serve-docs:
@echo "Serving Documentation..."
@cd docs && bundle exec jekyll serve ./docs
.PHONY: build-helm-chart
build-helm-chart:
@echo "Building Helm Chart..."
@helm package ./helm -d ./docs/charts
@helm repo index ./docs/charts --url https://parallels.github.io/prl-devops-service/charts --merge ./docs/charts/index.yaml
sign-macos-app:
@echo "Building App App..."
@if [ -f ./out/binaries/$(PACKAGE_NAME) ]; then \
echo "Removing previous MacOS App..."; \
rm ./out/binaries/$(PACKAGE_NAME); \
fi
@if [ -f ./out/binaries/$(PACKAGE_NAME).zip ]; then \
echo "Removing previous MacOS App Bundle..."; \
rm ./out/binaries/$(PACKAGE_NAME).zip; \
fi
@make build
@echo "Signing MacOS App..."
@codesign --force --deep --strict --verbose --options=runtime,library --sign "Developer ID Application: Carlos Lapao (KXLX56937Q)" --entitlements prldevops.entitlements ./out/binaries/$(PACKAGE_NAME)
@echo "MacOS App signed."
@echo "Notarizing MacOS App..."
@cd ./out/binaries && ditto -c -k --sequesterRsrc $(PACKAGE_NAME) $(PACKAGE_NAME).zip
@xcrun notarytool submit ./out/binaries/$(PACKAGE_NAME).zip --keychain-profile "notary-credentials" --wait
@echo "Verifying MacOS App..."
@codesign --verify --verbose ./out/binaries/$(PACKAGE_NAME)
@spctl -t open --context context:primary-signature -a -vvv ./out/binaries/$(PACKAGE_NAME)
$(COBERTURA):
@echo "Installing cobertura..."
@go install github.com/axw/gocov/gocov@latest
@go install github.com/AlekSi/gocov-xml@latest
@go install github.com/matm/gocov-html/cmd/gocov-html@latest
$(GOX):
@echo "Installing gox..."
@go install github.com/mitchellh/gox@latest
$(GOLANGCI_LINT):
@echo "Installing golangci-lint..."
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
$(GOSEC):
@echo "Installing gosec..."
@go install github.com/securego/gosec/v2/cmd/gosec@latest
$(SWAG):
@echo "Installing swag..."
@go install github.com/swaggo/swag/cmd/swag@latest
$(bundler):
@echo "Installing bundler..."
@bundler install
$(START_SUPER_LINTER_CONTAINER):
ifeq ($(OS), Windows_NT)
$(eval CONTAINER_ID := $(shell docker ps -a -q -f "name=$(PACKAGE_NAME)-linter"))
$(eval REPO := $(shell git rev-parse --abbrev-ref HEAD))
@IF "$(CONTAINER_ID)" EQU "" (\
docker run --name $(PACKAGE_NAME)-linter -e DEFAULT_BRANCH=main -e RUN_LOCAL=true -e VALIDATE_ALL_CODEBASE=true -e VALIDATE_JSCPD=false -e CREATE_LOG_FILE=true -e VALIDATE_GO=false -v .:/tmp/lint ghcr.io/super-linter/super-linter:latest \
) \
ELSE (\
docker start $(PACKAGE_NAME)-linter --attach \
);
else
$(eval CONTAINER_ID := $(shell docker ps -a | grep $(PACKAGE_NAME)-linter | awk '{print $$1}'))
$(eval REPO := $(shell git rev-parse --abbrev-ref HEAD))
@if [ -z $(CONTAINER_ID) ]; then \
echo "Linter container does not exist, creating it..."; \
docker run --platform linux/amd64 --name $(PACKAGE_NAME)-linter -e DEFAULT_BRANCH=$(REPO) -e RUN_LOCAL=true -e VALIDATE_ALL_CODEBASE=true -e VALIDATE_JSCPD=false -e CREATE_LOG_FILE=true -e VALIDATE_GO=false -v .:/tmp/lint ghcr.io/super-linter/super-linter:slim-latest; \
else \
echo "Linter container already exists $(CONTAINER_ID), starting it..."; \
docker start $(PACKAGE_NAME)-linter --attach; \
fi
endif