-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
132 lines (102 loc) · 5.19 KB
/
Makefile
File metadata and controls
132 lines (102 loc) · 5.19 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
#vars
IMAGE_NAME=scanoss-go-api
REPO=scanoss
DOCKER=$(shell which docker)
DOCKER_FULLNAME=${REPO}/${IMAGE_NAME}
GHCR_FULLNAME=ghcr.io/${REPO}/${IMAGE_NAME}
VERSION=$(shell ./version.sh)
# Linter version
LINT_VERSION := v2.11.3
# HELP
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## This help
@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
clean: ## Clean all dev data
@echo "Removing dev data..."
@rm -f pkg/cmd/version.txt version.txt target/* scripts/scanoss-go-api
clean_testcache: ## Expire all Go test caches
@echo "Cleaning test caches..."
go clean -testcache
version: ## Produce dependency version text file
@echo "Writing version file..."
echo $(VERSION) > pkg/cmd/version.txt
unit_test: ## Run all unit tests in the pkg folder
@echo "Running unit test framework..."
go test -v ./pkg/...
unit_test_cover: ## Run all unit tests in the pkg folder
@echo "Running unit test framework with coverage..."
go test -cover ./pkg/...
int_test: clean_testcache ## Run all integration tests in the tests folder
@echo "Running integration test framework..."
go test -v ./tests
int_test_cover: clean_testcache ## Run all integration tests in the tests folder
@echo "Running integration test framework..."
go test -cover -v ./tests
lint_local_clean: ## Cleanup the local cache from the linter
@echo "Cleaning linter cache..."
golangci-lint cache clean
lint_local: lint_local_clean ## Run local instance of linting across the code base
@echo "Running linter on codebase..."
golangci-lint run ./pkg/... ./cmd/...
lint_local_fix: ## Run local instance of linting across the code base including auto-fixing
@echo "Running linter with fix option..."
golangci-lint run --fix ./pkg/... ./cmd/...
lint_docker: ## Run docker instance of linting across the code base
${DOCKER} run --rm -v $(PWD):/app -v ~/.cache/golangci-lint/$(LINT_VERSION):/root/.cache -w /app golangci/golangci-lint:$(LINT_VERSION) golangci-lint run ./pkg/... ./cmd/...
lint_docker_fix: ## Run docker instance of linting across the code base including auto-fixing
${DOCKER} run --rm -v $(PWD):/app -v ~/.cache/golangci-lint/$(LINT_VERSION):/root/.cache -w /app golangci/golangci-lint:$(LINT_VERSION) golangci-lint run --fix ./pkg/... ./cmd/...
run_local: ## Launch the API locally for test
@echo "Launching API locally..."
go run cmd/server/main.go -json-config config/app-config-dev.json -debug
docker_build_test:
@echo "Building test image..."
${DOCKER} build . -t scanoss_api_go_service_test --target=test
e2e_test: docker_build_test clean_testcache ## Run end to end integration tests using Docker
@echo "Running End-to-End tests..."
${DOCKER} compose down
${DOCKER} compose up -d
${DOCKER} compose exec -T http go test -v -tags="integration e2e" ./tests
${DOCKER} compose down
e2e_test_cover: docker_build_test clean_testcache ## Run end to end integration tests using Docker
@echo "Running End-to-End tests..."
${DOCKER} compose down
${DOCKER} compose up -d
${DOCKER} compose exec -T http go test -cover -v -tags="integration e2e" ./tests
${DOCKER} compose down
ghcr_build: version ## Build GitHub container image
@echo "Building GHCR container image..."
${DOCKER} build --no-cache -t $(GHCR_FULLNAME) --platform linux/amd64 .
ghcr_tag: ## Tag the latest GH container image with the version from Git tag
@echo "Tagging GHCR latest image with $(VERSION)..."
${DOCKER} tag $(GHCR_FULLNAME):latest $(GHCR_FULLNAME):$(VERSION)
ghcr_push: ## Push the GH container image to GH Packages
@echo "Publishing GHCR container $(VERSION)..."
${DOCKER} push $(GHCR_FULLNAME):$(VERSION)
${DOCKER} push $(GHCR_FULLNAME):latest
ghcr_all: ghcr_build ghcr_tag ghcr_push ## Execute all GitHub Package container actions
build_local: version ## Build a Local binary
@echo "Building AMD binary $(VERSION)..."
go generate ./pkg/cmd/server.go
CGO_ENABLED=0 go build -ldflags="-w -s" -o ./target/scanoss-go-api-local ./cmd/server
build_amd: version ## Build a Linux AMD 64 binary
@echo "Building AMD binary $(VERSION)..."
go generate ./pkg/cmd/server.go
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o ./target/scanoss-go-api-linux-amd64 ./cmd/server
build_arm: version ## Build a Linux ARM 64 binary
@echo "Building ARM binary $(VERSION)..."
go generate ./pkg/cmd/server.go
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="-w -s" -o ./target/scanoss-go-api-linux-arm64 ./cmd/server
package: package_amd ## Build & Package an AMD 64 binary
package_amd: version ## Build & Package an AMD 64 binary
@echo "Building AMD binary $(VERSION) and placing into scripts..."
go generate ./pkg/cmd/server.go
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o ./scripts/scanoss-go-api ./cmd/server
bash ./package-scripts.sh linux-amd64 $(VERSION)
package_arm: version ## Build & Package an ARM 64 binary
@echo "Building ARM binary $(VERSION) and placing into scripts..."
go generate ./pkg/cmd/server.go
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="-w -s" -o ./scripts/scanoss-go-api ./cmd/server
bash ./package-scripts.sh linux-arm64 $(VERSION)