-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
123 lines (105 loc) · 2.78 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
DISPLAY_NAME := DeployIT
SHORT_NAME := dit
VERSION := 1.0.0
COMMIT := $(shell git rev-parse --short HEAD)
BUILD_ARGS := "-X main.Version=$(VERSION) -X main.Commit=$(COMMIT) -X main.DisplayName=$(DISPLAY_NAME) -X main.ShortName=$(SHORT_NAME)"
PORT ?= 8080
-include .env
export
## info: prints a project info message
.PHONY: info
info:
@echo "$(DISPLAY_NAME) version $(VERSION), build $(COMMIT)"
## run: uses go to start the main.go
.PHONY: run
run:
@go run main.go
## build: uses go to build the app with build args
.PHONY: build
build:
@touch .env
go build \
-ldflags=$(BUILD_ARGS) \
-o bin
chmod +x bin
## install: installs the build binary globally
.PHONY: install
install:
@cp ./bin /usr/local/bin/$(SHORT_NAME)
## uninstall: uninstalls the build binary globally
.PHONY: uninstall
uninstall:
@rm -f /usr/local/bin/$(SHORT_NAME)
## clean: cleans up the tmp, build and docker cache
.PHONY: clean
clean:
@rm -f bin
@rm -fr ./tmp
@if command -v go 2>&1 >/dev/null; then \
echo "cleanup go..."; \
go clean; \
go clean -cache -fuzzcache; \
fi
@if command -v docker 2>&1 >/dev/null; then \
echo "cleanup docker..."; \
CACHE_DIR="" PORT="" docker compose down --remove-orphans --rmi all; \
docker image prune -f; \
fi
@echo "cleanup done!"
@echo "WARNING: the .env file still exists!"
@echo "If installed also execute 'make uninstall' to uninstall the binary."
## update: updates dependencies
.PHONY: update
update:
go get -t -u ./...
## test: runs all tests without coverage
.PHONY: test
test:
go test ./...
## init: prepares ands builds
.PHONY: init
init:
@touch .env
@echo "update deps..."
@go mod tidy
@echo "testing..."
@make -s test
@echo "building..."
@make -s build
## air: starts the go bin in air watch mode
.PHONY: air
air:
@go install github.com/air-verse/air@v1
@air
## dev: starts a dev docker container
.PHONY: dev
dev:
@touch .env
$(eval CACHE_DIR = .tmp/.cache/go-build)
@if [ -d ~/.cache/go-build ]; then \
$(eval CACHE_DIR = ~/.cache/go-build) \
echo "Use users go-build cache dir."; \
else \
mkdir -p $(CACHE_DIR); \
echo "Use local go-build cache dir."; \
fi
@docker rm -f $(SHORT_NAME)-local-dev > /dev/null 2>&1
PORT=${PORT} \
CACHE_DIR=${CACHE_DIR} \
docker compose run --build --rm -it --name $(SHORT_NAME)-local-dev -P local
## exec: starts a bash in a dev container
.PHONY: exec
exec:
@touch .env
$(eval CACHE_DIR = .tmp/.cache/go-build)
@if [ -d ~/.cache/go-build ]; then \
$(eval CACHE_DIR = ~/.cache/go-build) \
echo "Use users go-build cache dir."; \
else \
mkdir -p $(CACHE_DIR); \
echo "Use local go-build cache dir."; \
fi
@docker rm -f $(SHORT_NAME)-local-bash > /dev/null 2>&1
PORT=${PORT} \
CACHE_DIR=${CACHE_DIR} \
docker compose run --build --rm -it --name $(SHORT_NAME)-local-bash --entrypoint bash -P local