/
Makefile
65 lines (46 loc) · 2.11 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
.DEFAULT_GOAL := help
GO := go
LDFLAGS := '-w -s'
BUILD_DIR := ./build
APP_BIN := $(BUILD_DIR)/floridaman
APP_BIN_LINUX := $(APP_BIN)_linux
APP_VERSION := 1.0
SOURCE_FILES := $(shell find . -type f -name "*.go")
COVERAGE_FILE := $(BUILD_DIR)/coverage.out
LINUX_FLAGS := GOOS=linux GOARCH=amd64
.PHONY: help
help: ## prints help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
$(APP_BIN): $(SOURCE_FILES)
@mkdir -p $(BUILD_DIR)
@CGO_ENABLED=0 $(GO) build -ldflags $(LDFLAGS) -o $(APP_BIN) ./cmd/floridaman
$(APP_BIN_LINUX): $(SOURCE_FILES)
mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 $(LINUX_FLAGS) $(GO) build -ldflags $(LDFLAGS) -o $(APP_BIN_LINUX) ./cmd/floridaman
build: $(APP_BIN) ## builds floridaman's binary for production use in the current machine's architecture
build-linux: $(APP_BIN_LINUX) ## builds floridaman's binary for production use in linux and amd64
build-linux:
.PHONY: test
test: ## runs all floridaman tests
@$(GO) test ./...
$(COVERAGE_FILE): $(SOURCE_FILES)
@$(GO) test -coverprofile=$(COVERAGE_FILE) ./...
coverage: $(COVERAGE_FILE) ## tests floridaman codebase and generates a coverage file
.PHONY: see-coverage
see-coverage: coverage ## showcases the coverage in a browser using html output
@$(GO) tool cover -html=$(COVERAGE_FILE)
.PHONY: clean
clean: ## removes build assets generated by the build target from the system
@rm -rf $(BUILD_DIR)/*
.PHONY: lint
lint: ## detects flaws in the code and checks for style
@docker run --rm -v $$PWD:/app -w /app golangci/golangci-lint:v1.47.2 golangci-lint run
.PHONY: docker
docker: ## builds the application's docker image
@docker build -t davidonium/floridaman:$(APP_VERSION) .
@docker tag davidonium/floridaman:$(APP_VERSION) davidonium/floridaman:latest
deploy: build-linux ## deploys the application to production, assumes that the config in ~/.ssh/config has a Host floridaman entry
# copy the binary generated by build target
rsync -avz $(APP_BIN_LINUX) floridaman:/tmp/floridaman
# reload the systemd service
ssh floridaman "sudo systemctl restart floridaman"