-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathMakefile
More file actions
137 lines (113 loc) · 5.94 KB
/
Makefile
File metadata and controls
137 lines (113 loc) · 5.94 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
# ────────────────────────────────────────────────────────────────────────────────
# Project-wide Makefile
# Root = frontend, backend lives in ./backend
# Requires:
# CR_PAT GitHub Container Registry token (write:packages)
# NPM_TOKEN GitHub Packages npm token (read/write:packages)
# GH_USER your GitHub username (default: hoangsonww)
# ────────────────────────────────────────────────────────────────────────────────
# User/config
GH_USER ?= hoangsonww
BACKEND_DIR := backend
# derive versions from package.json
FRONTEND_VERSION := $(shell node -p "require('./package.json').version")
BACKEND_VERSION := $(shell cd $(BACKEND_DIR) && node -p "require('./package.json').version")
# image names
FRONTEND_IMAGE := ghcr.io/$(GH_USER)/ecommerce-fullstack-website-frontend
BACKEND_IMAGE := ghcr.io/$(GH_USER)/fusion-electronics-backend
# npm package names
FRONTEND_PKG := @$(GH_USER)/ecommerce-fullstack-website-frontend
BACKEND_PKG := @$(GH_USER)/fusion-electronics-backend
# ────────────────────────────────────────────────────────────────────────────────
.PHONY: all help install build test \
docker-build docker-push \
publish-npm \
clean
all: help
help:
@echo "Usage:"
@echo " make install # install both frontend & backend deps"
@echo " make build # build both frontend & backend"
@echo " make test # run tests (if any) for both"
@echo
@echo " make docker-build # docker build both images"
@echo " make docker-push # push both to ghcr.io (uses CR_PAT)"
@echo
@echo " make publish-npm # npm publish both to GitHub Packages (uses NPM_TOKEN)"
@echo
@echo " make clean # cleanup node_modules and builds"
@echo
# ────────────────────────────────────────────────────────────────────────────────
install: install-frontend install-backend
install-frontend:
@echo "↪ Installing frontend deps..."
npm ci
install-backend:
@echo "↪ Installing backend deps..."
cd $(BACKEND_DIR) && npm ci
# ────────────────────────────────────────────────────────────────────────────────
build: build-frontend build-backend
build-frontend:
@echo "↪ Building frontend..."
npm run build
build-backend:
@echo "↪ Building backend..."
cd $(BACKEND_DIR) && npm run build
# ────────────────────────────────────────────────────────────────────────────────
test: test-frontend test-backend
test-frontend:
@echo "↪ Testing frontend..."
# insert your frontend test command here, e.g. npm test
@echo "(no tests configured)"
test-backend:
@echo "↪ Testing backend..."
# insert your backend test command here, e.g. cd backend && npm test
@echo "(no tests configured)"
# ────────────────────────────────────────────────────────────────────────────────
docker-build: docker-build-frontend docker-build-backend
docker-build-frontend:
@echo "↪ Docker build frontend → $(FRONTEND_IMAGE):$(FRONTEND_VERSION)"
docker build \
-t $(FRONTEND_IMAGE):$(FRONTEND_VERSION) \
-t $(FRONTEND_IMAGE):latest \
-f Dockerfile \
.
docker-build-backend:
@echo "↪ Docker build backend → $(BACKEND_IMAGE):$(BACKEND_VERSION)"
docker build \
-t $(BACKEND_IMAGE):$(BACKEND_VERSION) \
-t $(BACKEND_IMAGE):latest \
-f $(BACKEND_DIR)/Dockerfile \
$(BACKEND_DIR)
docker-push: ## push both images (requires CR_PAT)
@echo "↪ Pushing to GitHub Container Registry..."
@if [ -z "$(CR_PAT)" ]; then \
echo "❌ CR_PAT is not set"; exit 1; \
fi
echo "$(CR_PAT)" | docker login ghcr.io -u "$(GH_USER)" --password-stdin
docker push $(FRONTEND_IMAGE):$(FRONTEND_VERSION)
docker push $(FRONTEND_IMAGE):latest
docker push $(BACKEND_IMAGE):$(BACKEND_VERSION)
docker push $(BACKEND_IMAGE):latest
# ────────────────────────────────────────────────────────────────────────────────
publish-npm: publish-frontend-npm publish-backend-npm
publish-frontend-npm:
@echo "↪ npm publish frontend → $(FRONTEND_PKG)@$(FRONTEND_VERSION)"
@if [ -z "$(NPM_TOKEN)" ]; then \
echo "❌ NPM_TOKEN is not set"; exit 1; \
fi
npm config set //npm.pkg.github.com/:_authToken "$(NPM_TOKEN)"
npm publish --access public
publish-backend-npm:
@echo "↪ npm publish backend → $(BACKEND_PKG)@$(BACKEND_VERSION)"
@if [ -z "$(NPM_TOKEN)" ]; then \
echo "❌ NPM_TOKEN is not set"; exit 1; \
fi
cd $(BACKEND_DIR) && \
npm config set //npm.pkg.github.com/:_authToken "$(NPM_TOKEN)" && \
npm publish --access public
# ────────────────────────────────────────────────────────────────────────────────
clean:
@echo "↪ Cleaning..."
rm -rf node_modules build
cd $(BACKEND_DIR) && rm -rf node_modules build