-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
99 lines (86 loc) · 2.01 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
87
88
89
90
91
92
93
94
95
96
97
98
99
# Variables
APP_NAME = go-microservice
VERSION = 0.0.1
MAIN_DIR = cmd
BIN_DIR = bin
# Detect OS
ifeq ($(OS),Windows_NT)
RM = rmdir /s /q
EXE = .exe
else
RM = rm -rdf
EXE =
endif
.PHONY: all
all: build
.PHONY: build
build:
@echo "Building the application..."
@mkdir -p $(BIN_DIR)
@gofmt -w .
@go build -o $(BIN_DIR)/$(APP_NAME)$(EXE) main.go
@echo "$(APP_NAME)$(EXE)-$(VERSION) created!"
.PHONY: clean
clean:
@echo "Cleaning up $(BIN_DIR)/$(APP_NAME)"
@$(RM) $(BIN_DIR)
@echo "Done!"
.PHONY: docker
docker: test build
@echo "Building Docker image..."
@docker build -t $(APP_NAME):$(VERSION) .
@make clean
@echo "$(APP_NAME):$(VERSION) image created!"
.PHONY: info
info:
@echo "PROJECT INFO:"
@echo "+++++++++++++"
@echo "Name: $(APP_NAME)"
@echo "Version: $(VERSION)"
@echo "Binary folder: $(BIN_DIR)"
.PHONY: install
install:
@echo "Downloading libraries..."
@go mod download
@echo "Installing swag..."
@go install github.com/swaggo/swag/cmd/swag@latest
@echo "Done!"
.PHONY: migrate
migrate:
@echo "Running database schema migration..."
@go run internal/migrator/main.go
@echo "Done!"
.PHONY: run
run:
@echo "Running the application $(APP_NAME)..."
@go run main.go
.PHONY: swagger
swagger:
@echo "Creating swagger api..."
@swag init --parseDependency
@swag fmt
@go run docs/cmd/replace.go
@echo "Done!"
.PHONY: test
test:
@echo "Running tests..."
@go test -v ./tests/*
.PHONY: tidy
tidy:
@echo "Running go mod tidy..."
@go mod tidy
@echo "Done!"
.PHONY: help
help:
@echo "Makefile commands:"
@echo " make build - Build the application"
@echo " make clean - Clean build artifacts"
@echo " make docker - Create Docker image"
@echo " make help - Show this help message"
@echo " make info - Print Info"
@echo " make install - Install libraries"
@echo " make migrate - Migrate database schema"
@echo " make run - Run the application"
@echo " make swagger - Create swagger api"
@echo " make test - Run tests"
@echo " make tidy - Run go mod tidy"