-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
164 lines (126 loc) Β· 3.94 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Makefile - use `make` or `make help` to get a list of commands.
#
# Note - Comments inside this makefile should be made using a single
# hashtag `#`, lines with double hash-tags will be the messages that
# printed in the help command
# Name of the current directory
PROJECTNAME="maci-coordinator"
REPOSITORY="privacy-scaling-explorations/$(PROJECTNAME)"
# List of all Go-files to be processed
GOFILES=$(wildcard *.go)
# Redirecting error output to a file, acts as logs that can
# be referenced if needed
STDERR=/tmp/$(PROJECTNAME)-stderr.txt
# Docker image variables
IMAGE := $(PROJECTNAME)
VERSION := latest
# Ensures firing a blank `make` command default to help
.DEFAULT_GOAL := help
# Make is verbose in Linux. Make it silent
MAKEFLAGS += --silent
.PHONY: help
## `help`: Generates this help dialog for the Makefile
help: Makefile
echo
echo " Commands available in \`"$(PROJECTNAME)"\`:"
echo
sed -n 's/^[ \t]*##//p' $< | column -t -s ':' | sed -e 's/^//'
echo
.PHONY: local-setup
## `local-setup`: Setup development environment locally
local-setup:
echo " > Ensuring directory is a git repository"
git init &> /dev/null
echo " > Installing pre-commit"
pip install --upgrade pre-commit &> /dev/null
pre-commit install
# Will install missing dependencies
.PHONY: install
## `install`: Fetch dependencies needed to run `maci-coordinator`
install:
echo " > Getting dependencies..."
go get -v $(get)
go mod tidy
.PHONY: codestyle
## :
## `codestyle`: Run code formatter(s)
codestyle:
golangci-lint run --fix
.PHONY: lint
## `lint`: Run linters and check code-style
lint:
golangci-lint run
# No `help` message for this command - designed to be consumed internally
.PHONY: --test-runner
--test-runner:
go test ./src -race -covermode=atomic -coverprofile=./coverage/coverage.txt
go tool cover -html=./coverage/coverage.txt -o ./coverage/coverage.html
.PHONY: test
## :
## `test`: Run all tests
test: export TEST_MODE=complete
test: --test-runner
.PHONY: fast-tests
## `fast-tests`: Selectively run fast tests
fast-tests: export TEST_MODE=fast
fast-tests: --test-runner
.PHONY: slow-tests
## `slow-tests`: Selectively run slow tests
slow-tests: export TEST_MODE=slow
slow-tests: --test-runner
.PHONY: test-suite
## `test-suite`: Check code style, run linters and ALL tests
test-suite: export TEST_MODE=complete
test-suite: lint test
.PHONY: run
## :
## `run`: Run `maci-coordinator` in production mode
run: export production_mode=production
run: export __BUILD_MODE__=production
run:
go run main.go $(q)
.PHONY: run-debug
## `run-debug`: Run `maci-coordinator` in debug mode
run-debug: export debug_mode=debug
run-debug: export __BUILD_MODE__=debug
run-debug:
go run main.go $(q)
.PHONY: docker-gen
## :
## `docker-gen`: Create a production docker image for `maci-coordinator`
docker-gen:
echo "Building docker image \`ghcr.io/$(REPOSITORY):$(VERSION)\`..."
docker build --rm \
--platform linux/amd64 \
--build-arg final_image=scratch \
--build-arg build_mode=production \
-t ghcr.io/$(REPOSITORY):$(VERSION) . \
-f ./docker/Dockerfile
.PHONY: docker-debug
## `docker-debug`: Create debug-friendly docker images for `maci-coordinator`
docker-debug:
echo "Building docker image \`ghcr.io/$(REPOSITORY):$(VERSION)\`..."
docker build --rm=false \
--platform linux/amd64 \
--build-arg final_image=golang:1.18 \
--build-arg build_mode=debug \
-t ghcr.io/$(REPOSITORY):$(VERSION) . \
-f ./docker/Dockerfile
.PHONY: clean-docker
## `clean-docker`: Delete an existing docker image
clean-docker:
echo "Removing docker ghcr.io/$(REPOSITORY):$(VERSION)..."
docker rmi -f ghcr.io/$(REPOSITORY):$(VERSION)
## :
## NOTE: All docker-related commands can use `IMAGE`
## : and `VERSION` variables to modify the docker
## : image being targeted
## :
## : Example;
## : make docker-gen IMAGE=new_project VERSION=3.15
## :
## : Likewise, both the `run` commands can pass runtime
## : arguments under the `q` arg
## :
## : Example;
## : `make run q="time --version"`