-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
119 additions
and
94 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
repos: | ||
- repo: local | ||
hooks: | ||
- id: format | ||
name: format code | ||
entry: make format | ||
language: system | ||
always_run: true | ||
|
||
- id: lint | ||
name: check code style | ||
entry: make lint | ||
language: system | ||
always_run: true | ||
|
||
- id: test | ||
name: run tests | ||
entry: make test | ||
language: system | ||
always_run: true | ||
|
||
- id: build | ||
name: build the project | ||
entry: make build | ||
language: system | ||
always_run: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,92 @@ | ||
BINARY_DIR=bin | ||
BINARY_NAME=server | ||
BINARY_PATH=$(BINARY_DIR)/$(BINARY_NAME) | ||
RELEASE_NAME=minisearch | ||
COVERAGE_PROFILE=cover.out | ||
DOCKER_IMAGE=minisearch | ||
DOCKER_IMAGE_DEV=$(DOCKER_IMAGE)-dev | ||
DOCKER_IMAGE_WATCH=$(DOCKER_IMAGE)-watch | ||
DOCKER_PORT=3000 | ||
WATCH_PORT=3001 | ||
|
||
.PHONY: vendor | ||
|
||
all: lint coverage build | ||
|
||
# Build: | ||
setup: | ||
@go mod download | ||
|
||
build: | ||
@go build -buildvcs=false -o $(BINARY_PATH) ./cmd/server | ||
|
||
clean: | ||
@go clean --cache | ||
@rm -rf $(BINARY_DIR) | ||
@rm $(COVERAGE_PROFILE) | ||
|
||
vendor: | ||
@GO111MODULE=on go mod vendor | ||
|
||
watch: | ||
$(eval PACKAGE_NAME=$(shell head -n 1 go.mod | cut -d ' ' -f2)) | ||
@docker run -it --rm \ | ||
-w /go/src/$(PACKAGE_NAME) \ | ||
-v $(shell pwd):/go/src/$(PACKAGE_NAME) \ | ||
-p $(WATCH_PORT):$(WATCH_PORT) \ | ||
--name $(DOCKER_IMAGE_WATCH) \ | ||
cosmtrek/air \ | ||
--build.cmd "go build -buildvcs=false -race -o $(BINARY_PATH) ./cmd/server" \ | ||
--build.bin "./$(BINARY_PATH) -p $(WATCH_PORT)" | ||
|
||
# Test: | ||
test: | ||
@go test -v -race ./... | ||
|
||
coverage: | ||
@go test -v -race -cover -covermode=atomic -coverprofile=$(COVERAGE_PROFILE) ./... | ||
@go tool cover -func $(COVERAGE_PROFILE) | ||
|
||
# Benchmark: | ||
bench: | ||
@go test -bench=. -run=^a -benchtime=5x ./... | ||
|
||
# Lint | ||
lint: | ||
@golangci-lint run --timeout=3m | ||
|
||
# Release: | ||
release: | ||
@go build -buildvcs=false -o $(BINARY_NAME) ./cmd/server | ||
@tar -czvf $(RELEASE_NAME).tar.gz $(BINARY_NAME) README.md LICENSE.md | ||
@rm $(BINARY_NAME) | ||
|
||
# Docker dev: | ||
docker-dev-setup: | ||
@docker build -t $(DOCKER_IMAGE_DEV) --target dev . | ||
@docker run --rm --name $(DOCKER_IMAGE_DEV) -d -v $(shell pwd):/app $(DOCKER_IMAGE_DEV) | ||
|
||
docker-dev-stop: | ||
@docker stop $(DOCKER_IMAGE_DEV) | ||
|
||
docker-check: | ||
@docker exec $(DOCKER_IMAGE_DEV) make | ||
|
||
docker-test: | ||
@docker exec $(DOCKER_IMAGE_DEV) make test | ||
|
||
docker-bench: | ||
@docker exec $(DOCKER_IMAGE_DEV) make bench | ||
|
||
# Docker prod: | ||
docker-build: | ||
@docker build -t $(DOCKER_IMAGE) --target release . | ||
|
||
docker-run: | ||
@docker run --rm --name $(DOCKER_IMAGE) -d -p $(DOCKER_PORT):$(DOCKER_PORT) $(DOCKER_IMAGE) -p $(DOCKER_PORT) | ||
|
||
docker-stop: | ||
@docker stop $(DOCKER_IMAGE) | ||
BINARY_DIR=bin | ||
BINARY_NAME=server | ||
BINARY_PATH=$(BINARY_DIR)/$(BINARY_NAME) | ||
RELEASE_NAME=minisearch | ||
COVERAGE_PROFILE=cover.out | ||
DOCKER_IMAGE=minisearch | ||
DOCKER_IMAGE_DEV=$(DOCKER_IMAGE)-dev | ||
DOCKER_IMAGE_WATCH=$(DOCKER_IMAGE)-watch | ||
DOCKER_PORT=3000 | ||
WATCH_PORT=3001 | ||
|
||
.PHONY: vendor | ||
|
||
all: lint coverage build | ||
|
||
# Build: | ||
setup: | ||
@go mod download | ||
|
||
build: | ||
@go build -buildvcs=false -o $(BINARY_PATH) ./cmd/server | ||
|
||
clean: | ||
@go clean --cache | ||
@rm -rf $(BINARY_DIR) | ||
@rm $(COVERAGE_PROFILE) | ||
|
||
vendor: | ||
@GO111MODULE=on go mod vendor | ||
|
||
watch: | ||
$(eval PACKAGE_NAME=$(shell head -n 1 go.mod | cut -d ' ' -f2)) | ||
@docker run -it --rm \ | ||
-w /go/src/$(PACKAGE_NAME) \ | ||
-v $(shell pwd):/go/src/$(PACKAGE_NAME) \ | ||
-p $(WATCH_PORT):$(WATCH_PORT) \ | ||
--name $(DOCKER_IMAGE_WATCH) \ | ||
cosmtrek/air \ | ||
--build.cmd "go build -buildvcs=false -race -o $(BINARY_PATH) ./cmd/server" \ | ||
--build.bin "./$(BINARY_PATH) -p $(WATCH_PORT)" | ||
|
||
# Test: | ||
test: | ||
@go test -v -race ./... | ||
|
||
coverage: | ||
@go test -v -race -cover -covermode=atomic -coverprofile=$(COVERAGE_PROFILE) ./... | ||
@go tool cover -func $(COVERAGE_PROFILE) | ||
|
||
# Benchmark: | ||
bench: | ||
@go test -bench=. -run=^a -benchtime=5x ./... | ||
|
||
# Lint | ||
lint: | ||
@golangci-lint run --timeout=3m | ||
|
||
format: | ||
@go fmt ./... | ||
|
||
# Release: | ||
release: | ||
@go build -buildvcs=false -o $(BINARY_NAME) ./cmd/server | ||
@tar -czvf $(RELEASE_NAME).tar.gz $(BINARY_NAME) README.md LICENSE.md | ||
@rm $(BINARY_NAME) | ||
|
||
# Docker dev: | ||
docker-dev-setup: | ||
@docker build -t $(DOCKER_IMAGE_DEV) --target dev . | ||
@docker run --rm --name $(DOCKER_IMAGE_DEV) -d -v $(shell pwd):/app $(DOCKER_IMAGE_DEV) | ||
|
||
docker-dev-stop: | ||
@docker stop $(DOCKER_IMAGE_DEV) | ||
|
||
docker-check: | ||
@docker exec $(DOCKER_IMAGE_DEV) make | ||
|
||
docker-test: | ||
@docker exec $(DOCKER_IMAGE_DEV) make test | ||
|
||
docker-bench: | ||
@docker exec $(DOCKER_IMAGE_DEV) make bench | ||
|
||
# Docker prod: | ||
docker-build: | ||
@docker build -t $(DOCKER_IMAGE) --target release . | ||
|
||
docker-run: | ||
@docker run --rm --name $(DOCKER_IMAGE) -d -p $(DOCKER_PORT):$(DOCKER_PORT) $(DOCKER_IMAGE) -p $(DOCKER_PORT) | ||
|
||
docker-stop: | ||
@docker stop $(DOCKER_IMAGE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters