-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
147 lines (117 loc) · 4.67 KB
/
Makefile
File metadata and controls
147 lines (117 loc) · 4.67 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
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
# Check to see if we can use ash, in Alpine images, or default to BASH.
SHELL_PATH = /bin/ash
SHELL = $(if $(wildcard $(SHELL_PATH)),/bin/ash,/bin/bash)
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: run-dev
run-dev: ## Run the application in dev mode (default)
go run ./...
run-db-dev: ## Run a local instance of postgres for development
docker build -f Dockerfile.postgres -t my-postgres .
docker run -d -p 5432:5432 --name postgres-dev my-postgres
.PHONY: run-docker
run-docker: ## Run the application in docker for development
@docker build -t maple .
@docker run -p 8080:8080 maple
# =========== DEPENDENCIES ===========
GOLANG := golang:1.25
ALPINE := alpine:3.22
POSTGRES := postgres:18.0
GRAFANA := grafana/grafana:12.2.0
PROMETHEUS := prom/prometheus:v3.7.0
TEMPO := grafana/tempo:2.9.0
LOKI := grafana/loki:3.5.0
PROMTAIL := grafana/promtail:3.5.0
NAMESPACE := maple-system
MAPLE_APP := maple
AUTH_APP := auth
BASE_IMAGE_NAME := localhost/maple
VERSION := 0.0.1
MAPLE_IMAGE := $(BASE_IMAGE_NAME)/$(MAPLE_APP):$(VERSION)
METRICS_IMAGE := $(BASE_IMAGE_NAME)/metrics:$(VERSION)
AUTH_IMAGE := $(BASE_IMAGE_NAME)/$(AUTH_APP):$(VERSION)
# VERSION := "0.0.1-$(shell git rev-parse --short HEAD)"
# ==============================================================================
# Detect operating system and set the appropriate open command
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
OPEN_CMD := open
else
OPEN_CMD := xdg-open
endif
# ==============================================================================
# Install dependencies
dev-gotooling:
go install github.com/divan/expvarmon@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
go install golang.org/x/vuln/cmd/govulncheck@latest
go install golang.org/x/tools/cmd/goimports@latest
dev-brew:
brew update
brew list pgcli || brew install pgcli
brew list watch || brew install watch
dev-docker:
docker pull docker.io/$(GOLANG) & \
docker pull docker.io/$(ALPINE) & \
docker pull docker.io/$(POSTGRES) & \
docker pull docker.io/$(GRAFANA) & \
docker pull docker.io/$(PROMETHEUS) & \
docker pull docker.io/$(TEMPO) & \
docker pull docker.io/$(LOKI) & \
docker pull docker.io/$(PROMTAIL) & \
wait;
# =========== BUILD CONTAINERS ===========
build: maple metrics auth ## Build all containers
maple: ## Build the maple container
docker build \
-f zoltan/docker/dockerfile.maple \
-t $(MAPLE_IMAGE) \
-t $(BASE_IMAGE_NAME)/backend:dev \
--build-arg BUILD_REF=$(VERSION) \
--build-arg BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") \
.
metrics: ## Build the metrics container
docker build \
-f zoltan/docker/dockerfile.metrics \
-t $(METRICS_IMAGE) \
-t $(BASE_IMAGE_NAME)/metrics:dev \
--build-arg BUILD_REF=$(VERSION) \
--build-arg BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") \
.
auth: ## Build the auth container
docker build \
--no-cache \
-f zoltan/docker/dockerfile.auth \
-t $(AUTH_IMAGE) \
-t $(BASE_IMAGE_NAME)/auth:dev \
--build-arg BUILD_REF=$(VERSION) \
--build-arg BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") \
.
# ==============================================================================
# Metrics and Tracing
metrics-view-sc: ## View the metrics in a browser
expvarmon -ports="localhost:3010" -vars="build,requests,goroutines,errors,panics,mem:memstats.HeapAlloc,mem:memstats.HeapSys,mem:memstats.Sys"
metrics-view: ## View the metrics in a browser
expvarmon -ports="localhost:4020" -endpoint="/metrics" -vars="build,requests,goroutines,errors,panics,mem:memstats.HeapAlloc,mem:memstats.HeapSys,mem:memstats.Sys"
grafana: ## view the grafana dashboard
$(OPEN_CMD) http://localhost:3100/
statsviz: ## view the statsviz dashboard
$(OPEN_CMD) http://localhost:3010/debug/statsviz/
# ==============================================================================
# Audit
audit: ## Run the audit service
CGO_ENABLED=0 go vet ./...
staticcheck -checks=all ./...
govulncheck ./...
# ==============================================================================
# RUN
#
.PHONY: dev
dev: build ## Run the application in dev mode locally
docker compose -f zoltan/compose/docker-compose.yml -f zoltan/compose/docker-compose.dev.yml --env-file zoltan/compose/.env.dev up --force-recreate
.PHONY: dev-clean
dev-clean: down-dev ## Clean and restart dev environment
make dev
.PHONY: down-dev
down-dev: ## stop the application in dev mode locally
docker compose -f zoltan/compose/docker-compose.yml -f zoltan/compose/docker-compose.dev.yml down -v