-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
111 lines (78 loc) · 3.44 KB
/
Copy pathMakefile
File metadata and controls
111 lines (78 loc) · 3.44 KB
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
PORT=8080
CLIENT_SECRET=aaaa
CONTAINER_NAME=do-token-scoper-companion
CONTAINER_PORT=5678
SOURCES=main.go rules.go utils.go config.go metrics.go
TESTS=rules_test.go
# TODO: use magic functions to find all sources and tests
DOCKER_PROJECT := allgreed/digitalocean-token-scoper
LINTFLAGS := -e -s
# Porcelain
# ###############
.PHONY: container run build lint test env-up env-down test-watch secrets
run: secrets setup ## run the app
# TODO: ensure that env is running?
APP_PERMISSIONS_PATH=./example.yaml APP_LOG_LEVEL=debug APP_LOG_FORMAT=text APP_PORT=$(PORT) APP_TARGET_URL=http://localhost:$(CONTAINER_PORT) APP_USERTOKEN__joe=./secrets/users/joe/secret APP_TOKEN_PATH=./secrets/token/secret APP_USERTOKEN__jane=./secrets/users/jane/secret go run -mod=readonly $(SOURCES)
run-watch: setup ## run the app in dev mode, hot reloading
ls $(SOURCES) Makefile | entr -cr make run
build: setup ## create artifact
nix-build
lint: setup ## run static analysis
gofmt $(LINTFLAGS) -w .
lint-check: setup ## run static analysis - for CI
test -z "$$(gofmt $(LINTFLAGS) -l .)"
test: setup ## run all tests
go test -mod=readonly
test-watch: setup ## run tests in watch mode
ls $(SOURCES) $(TESTS) | entr -c make test
env-up: ## set up dev environment
docker run -d --name $(CONTAINER_NAME) --restart=unless-stopped -p $(CONTAINER_PORT):80 ealen/echo-server:0.5.0 --enable:environment false --enable:host
sleep 2
env-down: ## tear down dev environment
docker rm -f $(CONTAINER_NAME)
container: setup ## create container
nix-build -A docker.image
interact: ## helper process to run predefined inputs
# TODO: simple command runner with a few options that can be chosen at a keypress
curl http://localhost:$(PORT)/v2/domains/example.com/records --silent -H "Authorization: Bearer $(CLIENT_SECRET)" | jq
# Plumbing
# ###############
.PHONY: setup gitclean gitclean-with-libs secrets
secrets: secrets/token/secret secrets/users/joe/secret secrets/users/jane/secret
main.out: $(SOURCES)
go build -o $< $@
setup:
gitclean:
gitclean-with-libs:
secrets/token/secret:
mkdir -p secrets/token
echo "verymuchanexampletoken" > $@
secrets/users/joe/secret:
mkdir -p secrets/users/joe
echo "$(CLIENT_SECRET)" > $@
secrets/users/jane/secret:
mkdir -p secrets/users/jane
echo "very much whatever" > $@
# Helpers
# ###############
.PHONY: container-full prepare-release-image-tag
container-full: setup container ## create and load the image to the local repository
docker load < result
ACQUIRE_VERSION_FORM_DEFAULT_NIX := grep 'version =' default.nix | cut -d' ' -f 5 | tr -d '\"\;'
check-version-uploaded:
curl --silent -f -lSL https://index.docker.io/v1/repositories/$(DOCKER_PROJECT)/tags/$$($(ACQUIRE_VERSION_FORM_DEFAULT_NIX)) > /dev/null && false || true
prepare-release-image-tag:
echo "$$($(ACQUIRE_VERSION_FORM_DEFAULT_NIX)),latest,$$($(ACQUIRE_VERSION_FORM_DEFAULT_NIX) | cut -d'.' -f 1),$$($(ACQUIRE_VERSION_FORM_DEFAULT_NIX) | cut -d'.' -f 1,2)" > .tags
# Utilities
# ###############
.PHONY: help todo clean really_clean init
init: ## one time setup
direnv allow .
todo: ## list all TODOs in the project
git grep -I --line-number TODO | grep -v 'list all TODOs in the project' | grep TODO
clean: gitclean ## remove artifacts
rm main.out
really_clean: clean gitclean-with-libs ## remove EVERYTHING
help: ## print this message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help