forked from cubedro/eth-netstats
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile
More file actions
187 lines (147 loc) · 7.24 KB
/
Copy pathMakefile
File metadata and controls
187 lines (147 loc) · 7.24 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
FRONTEND_DIR := frontend
BACKEND_DIR := backend
FRONTEND_CONTAINER := xdcstats-frontend-dev
BACKEND_PORT := 2000
FRONTEND_PORT := 32001
BACKEND_IMAGE := xinfinorg/xdcstats-backend
FRONTEND_IMAGE := xinfinorg/xdcstats-frontend
TAG ?= $(shell git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD)
PLATFORM ?=
_PLATFORM_FLAG = $(if $(PLATFORM),--platform $(PLATFORM),)
.PHONY: install install-backend install-frontend \
build build-frontend \
dev-backend dev-frontend \
frontend-run frontend-stop frontend-logs \
start stop \
docker-up docker-down \
docker-build docker-build-backend docker-build-frontend \
docker-build-amd64 \
docker-push docker-push-backend docker-push-frontend \
docker-release docker-release-amd64 \
test lint clean help
## ── Dependencies ──────────────────────────────────────────────────────────────
install: install-backend install-frontend
install-backend:
cd $(BACKEND_DIR) && go mod download
install-frontend:
cd $(FRONTEND_DIR) && npm install
## ── Build ─────────────────────────────────────────────────────────────────────
build: build-backend build-frontend
build-backend:
cd $(BACKEND_DIR) && CGO_ENABLED=0 go build -o xdcstats-backend .
build-frontend: install-frontend
cd $(FRONTEND_DIR) && npm run build
## ── Development ───────────────────────────────────────────────────────────────
dev-backend:
cd $(BACKEND_DIR) && go run .
dev-frontend:
cd $(FRONTEND_DIR) && npm run dev
## ── Frontend dev container (npm run dev, reads .env) ─────────────────────────
frontend-run: docker-build-frontend frontend-stop
ifndef ENV
$(error ENV must be set to devnet, testnet, or mainnet, e.g. make frontend-run ENV=testnet)
endif
docker run -d \
--name $(FRONTEND_CONTAINER) \
--restart unless-stopped \
-e ENV=$(ENV) \
-p $(FRONTEND_PORT):32001 \
$(FRONTEND_IMAGE):$(TAG)
@echo "Frontend → http://localhost:$(FRONTEND_PORT)"
@echo "Backend → http://localhost:$(BACKEND_PORT) (start separately with: make dev-backend)"
frontend-stop:
@docker stop $(FRONTEND_CONTAINER) 2>/dev/null || true
@docker rm $(FRONTEND_CONTAINER) 2>/dev/null || true
frontend-logs:
docker logs -f $(FRONTEND_CONTAINER)
## ── Full stack (frontend dev container + backend docker-compose with MongoDB) ──
start:
$(MAKE) docker-up
$(MAKE) frontend-run
stop: frontend-stop docker-down
## ── Backend via Docker Compose (includes MongoDB) ─────────────────────────────
docker-up:
cd $(BACKEND_DIR) && docker-compose up -d
docker-down:
cd $(BACKEND_DIR) && docker-compose down
## ── Docker build & publish ────────────────────────────────────────────────────
docker-build: docker-build-backend docker-build-frontend
docker-build-backend:
docker build $(_PLATFORM_FLAG) -t $(BACKEND_IMAGE):$(TAG) $(BACKEND_DIR)/
@echo "Built $(BACKEND_IMAGE):$(TAG)"
docker-build-frontend:
docker build $(_PLATFORM_FLAG) \
-t $(FRONTEND_IMAGE):$(TAG) \
$(FRONTEND_DIR)/
@echo "Built $(FRONTEND_IMAGE):$(TAG)"
# Convenience target — build both images for linux/amd64 on any host (including Apple Silicon)
docker-build-amd64:
$(MAKE) docker-build PLATFORM=linux/amd64
docker-push: docker-push-backend docker-push-frontend
docker-push-backend:
docker push $(BACKEND_IMAGE):$(TAG)
docker-push-frontend:
docker push $(FRONTEND_IMAGE):$(TAG)
# Build and push in one step: make docker-release TAG=v1.2.0
docker-release: docker-build docker-push
# Build amd64 images and push: make docker-release-amd64 TAG=v1.2.0
docker-release-amd64:
$(MAKE) docker-build-amd64 TAG=$(TAG)
$(MAKE) docker-push TAG=$(TAG)
## ── Quality ───────────────────────────────────────────────────────────────────
test:
cd $(FRONTEND_DIR) && npm test
lint:
cd $(FRONTEND_DIR) && npm run lint
## ── Clean ─────────────────────────────────────────────────────────────────────
clean: frontend-stop
rm -rf $(FRONTEND_DIR)/dist
rm -rf $(FRONTEND_DIR)/node_modules
rm -f $(BACKEND_DIR)/xdcstats-backend
## ── Help ──────────────────────────────────────────────────────────────────────
help:
@echo ""
@echo "XDCStats — monorepo build targets"
@echo ""
@echo " Setup"
@echo " install Download deps for both backend and frontend"
@echo " install-backend go mod download for backend"
@echo " install-frontend npm install for frontend"
@echo ""
@echo " Development"
@echo " dev-backend Run Go backend (port $(BACKEND_PORT))"
@echo " dev-frontend Start Vite dev server (port $(FRONTEND_PORT))"
@echo ""
@echo " Frontend dev container (reads .env, npm run dev)"
@echo " frontend-run Build image + run dev container on port $(FRONTEND_PORT)"
@echo " frontend-stop Stop frontend dev container"
@echo " frontend-logs Follow frontend container logs"
@echo ""
@echo " Full stack"
@echo " start docker-up (MongoDB) + frontend-run"
@echo " stop frontend-stop + docker-down"
@echo ""
@echo " Backend docker-compose (includes MongoDB)"
@echo " docker-up Start backend + MongoDB"
@echo " docker-down Stop backend docker-compose"
@echo ""
@echo " Docker images (TAG defaults to git tag or short commit)"
@echo " docker-build Build both images (native arch)"
@echo " docker-build-amd64 Build both images for linux/amd64 (works on Apple Silicon)"
@echo " docker-build-backend Build $(BACKEND_IMAGE):\$$TAG"
@echo " docker-build-frontend Build $(FRONTEND_IMAGE):\$$TAG"
@echo " docker-push Push both images"
@echo " docker-push-backend Push backend image"
@echo " docker-push-frontend Push frontend image"
@echo " docker-release Build + push (make docker-release TAG=v1.2.0)"
@echo " docker-release-amd64 Build amd64 + push (make docker-release-amd64 TAG=v1.2.0)"
@echo ""
@echo " Tip: pass PLATFORM= to any docker-build target, e.g."
@echo " make docker-build-backend PLATFORM=linux/amd64"
@echo ""
@echo " Quality"
@echo " test Run frontend Vitest suite"
@echo " lint Run ESLint on frontend"
@echo ""
@echo " clean Remove dist, node_modules, stop frontend container"
@echo ""