-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
86 lines (64 loc) · 2.04 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Projec name
PROJECT_NAME=learn-go-backend
PORT=8080
# Binary name
BINARY_NAME=main
# Go related variables
GOBASE=$(shell pwd)
GOBIN=$(GOBASE)/bin
GOBINPATH=$(GOBIN)/$(BINARY_NAME)
GOFILES=$(GOBASE)/app/cmd/*.go
# Make is verbose in Linux. Make it silent.
MAKEFLAGS += --silent
.PHONY: build clean run daemon deps doctor containerize run-container
deps:
@echo "Ensuring dependencies are up to date..."
@go mod tidy
build: deps
@echo "Building..."
@go build -o $(GOBINPATH) $(GOFILES)
clean:
@echo "Cleaning..."
@go clean
@rm -rf $(GOBIN)
run: build
@echo "Running..."
@$(GOBINPATH)
daemon: build
@air --build.cmd "go build -o $(GOBINPATH) $(GOFILES)" --build.bin "$(GOBINPATH)"
doctor:
@echo "Ensuring dependencies are up to date..."
@go mod tidy
@echo "Formatting code..."
@go fmt ./...
@echo "Running go vet..."
@go vet ./...
@echo "Running tests..."
@go test ./...
@echo "Running integration tests..."
@go test -tags integration ./...
@echo "All checks passed!"
containerize:
@echo "Building container..."
@docker build -t $(PROJECT_NAME):latest .
@echo "Container built!"
run-container: containerize
@echo "Running container..."
@docker run --name $(PROJECT_NAME) -d -p $(PORT):$(PORT) $(PROJECT_NAME):latest
dockerhub-push: containerize
@echo "Pushing container to DockerHub..."
@docker tag $(PROJECT_NAME):latest $(DOCKERHUB_USERNAME)/$(PROJECT_NAME):latest
@docker push $(DOCKERHUB_USERNAME)/$(PROJECT_NAME):latest
# Help target
help:
@echo "Available targets:"
@echo " build - Build the application"
@echo " clean - Remove binary and clear cache"
@echo " run - Build and run the application"
@echo " daemon - Deamon running application"
@echo " deps - Ensure dependencies are up to date"
@echo " doctor - Run vet, test, and build"
@echo " containerize - Build container"
@echo " run-container - Run container"
@echo " dockerhub-push - Push container to DockerHub"
@echo " help - Print this help message"