-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
126 lines (91 loc) · 2.99 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
124
125
126
.DEFAULT_GOAL := all
## parameters
NAME ?= revip
NAMESPACE ?= github.com/corpix
VERSION ?= development
ENV ?= dev
PARALLEL_JOBS ?= 8
NIX_OPTS ?=
export GOFLAGS ?=
-include .env
## bindings
root := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
nix_dir := nix
pkg_prefix := $(NAMESPACE)/$(NAME)
tmux := tmux -2 -f $(PWD)/.tmux.conf -S $(PWD)/.tmux
tmux_session := $(NAME)
nix := nix $(NIX_OPTS)
shell_volume_nix := nix
### reusable and long opts for commands inside rules
add_shell_opts ?=
shell_opts = -v $(shell_volume_nix):/nix:rw \
-v $(root):/chroot \
-e COLUMNS=$(COLUMNS) \
-e LINES=$(LINES) \
-e TERM=$(TERM) \
-e NIX_BUILD_CORES=$(NIX_BUILD_CORES) \
-e HOME=/chroot \
-w /chroot \
--hostname $(NAMESPACE).localhost \
$(foreach v,$(ports), -p $(v):$(v) ) $(add_shell_opts)
## helpers
, = ,
## macro
define fail
{ echo "error: "$(1) 1>&2; exit 1; }
endef
## targets
.PHONY: all
all: lint test # test, check and build all cmds
.PHONY: help
help: # print defined targets and their comments
@grep -Po '^[a-zA-Z%_/\-\s]+:+(\s.*$$|$$)' Makefile \
| sort \
| sed 's|:.*#|#|;s|#\s*|#|' \
| column -t -s '#' -o ' | '
#### runners
## env
.PHONY: run/shell
run/shell: # enter development environment with nix-shell
nix-shell
.PHONY: run/cage/shell
run/cage/shell: # enter sandboxed development environment with nix-cage
nix-cage
## dev session
.PHONY: run/tmux/session
run/tmux/session: # start development environment
@$(tmux) has-session -t $(tmux_session) && $(call fail,tmux session $(tmux_session) already exists$(,) use: '$(tmux) attach-session -t $(tmux_session)' to attach) || true
@$(tmux) new-session -s $(tmux_session) -n console -d
@$(tmux) select-window -t $(tmux_session):0
@if [ -f $(root)/.personal.tmux.conf ]; then \
$(tmux) source-file $(root)/.personal.tmux.conf; \
fi
@$(tmux) attach-session -t $(tmux_session)
.PHONY: run/tmux/attach
run/tmux/attach: # attach to development session if running
@$(tmux) attach-session -t $(tmux_session)
.PHONY: run/tmux/kill
run/tmux/kill: # kill development environment
@$(tmux) kill-session -t $(tmux_session)
### development
.PHONY: test
test: # run unit tests
go test -v ./...
.PHONY: lint
lint: # run linter
golangci-lint --color=always --timeout=120s run ./...
#### testing
#### docker
.PHONY: run/docker/shell
run/docker/shell: # run development environment shell
@docker run --rm -it \
--log-driver=none \
$(shell_opts) nixos/nix:latest \
nix-shell --run 'exec make run/shell'
.PHONY: run/docker/clean
run/docker/clean: # clean development environment artifacts
docker volume rm nix
##
.PHONY: clean
clean:: # clean stored state
rm -rf result*