-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
158 lines (130 loc) · 4.36 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
# ==============================================================================
# VARIABLES
DOCKER_UID = $(shell id -u)
DOCKER_GID = $(shell id -g)
DOCKER_USER = $(DOCKER_UID):$(DOCKER_GID)
COMPOSE = DOCKER_USER=$(DOCKER_USER) docker compose
COMPOSE_RUN = $(COMPOSE) run --rm
ES_INDEX = statements-fixtures
# -- Node
COMPOSE_RUN_NODE = $(COMPOSE_RUN) node
YARN = $(COMPOSE_RUN_NODE) yarn
# -- Utils
WAIT_DB = $(COMPOSE_RUN) dockerize -wait tcp://postgresql:5432 -timeout 60s
WAIT_GRAFANA = $(COMPOSE_RUN) dockerize -wait http://grafana:3000 -timeout 60s
WAIT_ES = $(COMPOSE_RUN) dockerize -wait http://elasticsearch:9200 -timeout 60s
WAIT_MYSQL = $(COMPOSE_RUN) dockerize -wait tcp://edx_mysql:3306 -timeout 60s
# -- Targets
sources := $(shell find src -type f -name '*.jsonnet')
libraries := $(shell find src -type f -name '*.libsonnet')
plugins := $(shell find src/plugins/packages -maxdepth 1 -mindepth 1 -type d)
targets := $(patsubst src/%.jsonnet,var/lib/grafana/%.json,$(sources))
plugins-dist := $(patsubst src/plugins/packages/%,var/lib/grafana/plugins/%,$(plugins))
default: help
# ==============================================================================
# FILES
var/lib/grafana:
mkdir -p var/lib/grafana
var/lib/grafana/%.json: src/%.jsonnet
mkdir -p $(shell dirname $@)
bin/jsonnet -o /$@ $<
var/lib/grafana/plugins/%: src/plugins/packages/%
mkdir -p $@
cp -R $</dist/* $@
tree: \
var/lib/grafana
.PHONY: tree
# RULES
bootstrap: \
tree \
dependencies \
plugins \
build \
compile \
fixtures \
hooks
bootstrap: ## bootstrap the application
.PHONY: bootstrap
build: ## build potsie development image
@$(COMPOSE) build app
.PHONY: build
clean: \
down
clean: ## remove project files and containers (warning: it removes the database container)
rm -rf ./var src/plugins/node_modules src/plugins/packages/*/node_modules src/plugins/packages/*/dist
.PHONY: clean
compile: \
tree \
$(targets)
compile: ## compile jsonnet sources to json
.PHONY: compile
dependencies: ## install project dependencies (plugins)
@$(YARN) install
.PHONY: dependencies
down: ## remove stack (warning: it removes the database container)
@$(COMPOSE) down || echo WARNING: unable to remove the stack. Try to stop linked containers or networks first.
.PHONY: down
fixtures: \
run
fixtures: ## Load test data (for development)
@echo "Wait for databases to be up..."
@$(WAIT_ES)
$(COMPOSE_RUN) elasticsearch /usr/local/bin/create_es_index.sh $(ES_INDEX)
@$(WAIT_MYSQL)
zcat ./fixtures/elasticsearch/lrs.json.gz | \
$(COMPOSE_RUN) patch_statements_date | \
$(COMPOSE_RUN) -T ralph push -b es --es-index $(ES_INDEX) && \
$(COMPOSE_RUN) users-permissions sh /scripts/users-permissions.sh
.PHONY: fixtures
format: ## format Jsonnet sources and libraries
bin/jsonnetfmt -i $(sources) $(libraries)
.PHONY: format
hooks: ## run post-deployment hooks
@$(COMPOSE_RUN) hooks ./post-deploy
.PHONY: hooks
lint: ## lint Jsonnet sources and libraries
bin/jsonnet-lint $(sources) $(libraries)
.PHONY: lint
logs: ## display grafana logs (follow mode)
@$(COMPOSE) logs -f grafana
.PHONY: logs
plugins: ## download, build and install plugins
@$(YARN) build
.PHONY: plugins
plugins-dist: \
tree \
$(plugins-dist)
plugins-dist: ## copy compiled plugins in the distribution tree
.PHONY: plugins-dist
restart: ## restart grafana
@$(COMPOSE) restart grafana
.PHONY: restart
run: \
tree
run: ## start the development server
@$(COMPOSE) up -d postgresql
@echo "Wait for database to be up..."
@$(WAIT_DB)
@$(COMPOSE) up -d grafana
@echo "Wait for grafana to be up..."
@$(WAIT_GRAFANA)
.PHONY: run
status: ## an alias for "docker compose ps"
@$(COMPOSE) ps
.PHONY: status
stop: ## stop the development server
@$(COMPOSE) stop
.PHONY: stop
update: ## update jsonnet bundles
@$(COMPOSE_RUN) jb update
$(MAKE) build
.PHONY: update
# This rule requires to install the inotify-tools dependency (Linux Only)
# https://github.com/inotify-tools/inotify-tools/wiki
watch: ## automatically compiles sources when changed
bin/watch src "$(MAKE) -B compile"
.PHONY: watch
# ==============================================================================
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help