-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
237 lines (188 loc) · 7.08 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
### Defensive settings for make:
# https://tech.davis-hansson.com/p/make/
SHELL:=bash
.ONESHELL:
.SHELLFLAGS:=-xeu -o pipefail -O inherit_errexit -c
.SILENT:
.DELETE_ON_ERROR:
MAKEFLAGS+=--warn-undefined-variables
MAKEFLAGS+=--no-builtin-rules
MAKEFLAGS+=--output-sync=target
# We like colors
# From: https://coderwall.com/p/izxssa/colored-makefile-for-golang-projects
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`
# Project Name
PROJECT_NAME=2023-ploneconf
# Folder containing this Makefile
PROJECT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
# Versions
PLONE_VERSION=$$(cat ${PROJECT_DIR}/backend/version.txt)
VOLTO_VERSION=$$(cat ${PROJECT_DIR}/frontend/version.txt)
PROJECT_VERSION=$$(cat version.txt)
# Get current user information
CURRENT_USER=$$(whoami)
USER_INFO=$$(python -c 'import os,grp,pwd;uid=os.getuid();user=pwd.getpwuid(uid);guid=user.pw_gid;print(f"{uid}:{guid}")')
# Compose files used in local development
DEV_COMPOSE=docker-compose.yml
DEV_COMPOSE_OVERRIDE=override.yml
ACCEPTANCE_COMPOSE=devops/dev/acceptance.yml
COMPOSE_CMD=PROJECT_DIR=${PROJECT_DIR} VOLTO_VERSION=${VOLTO_VERSION} PLONE_VERSION=${PLONE_VERSION} USER=${USER_INFO} docker compose
ifneq ("$(wildcard $(DEV_COMPOSE_OVERRIDE))","")
DEV_CMD=${COMPOSE_CMD} -p ${PROJECT_NAME} -f ${DEV_COMPOSE} -f ${DEV_COMPOSE_OVERRIDE}
else
DEV_CMD=${COMPOSE_CMD} -p ${PROJECT_NAME} -f ${DEV_COMPOSE}
endif
#DEV_CMD=${COMPOSE_CMD} -p ${PROJECT_NAME} -f ${DEV_COMPOSE} -f ${DEV_COMPOSE_OVERRIDE}
ACCEPTANCE_CMD=${COMPOSE_CMD} -p ${PROJECT_NAME}-acceptance -f ${ACCEPTANCE_COMPOSE}
# Service Names
SERVICE_BACKEND=backend-dev
SERVICE_FRONTEND=frontend-dev
# Container Names
CONTAINER_BACKEND=${PROJECT_NAME}-${SERVICE_BACKEND}-1
CONTAINER_FRONTEND=${PROJECT_NAME}-${SERVICE_FRONTEND}-1
.PHONY: all
all: install
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
.PHONY: help
help: ## This help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: info
info: ## Debug information about this project
@echo ""
@echo "========================="
@echo "Project Information"
@echo "========================="
@echo "- Project Name: ${PROJECT_NAME}"
@echo "- Project Directory: ${PROJECT_DIR}"
@echo "- Plone Version: ${PLONE_VERSION}"
@echo "- Volto Version: ${VOLTO_VERSION}"
@echo ""
.PHONY: install-frontend
install-frontend: ## Install React Frontend
$(MAKE) -C "./frontend/" config
${DEV_CMD} build ${SERVICE_FRONTEND}
.PHONY: install-frontend-clean
install-frontend-clean: ## Install React Frontend
$(MAKE) -C "./frontend/" config
${DEV_CMD} build ${SERVICE_FRONTEND} --no-cache
.PHONY: debug-frontend
debug-frontend: ## Run bash in the Frontend container
${DEV_CMD} run --rm --entrypoint bash ${SERVICE_FRONTEND} || true
.PHONY: stop-frontend
stop-frontend: ## Stop Frontend
${DEV_CMD} stop ${SERVICE_FRONTEND}
.PHONY: start-frontend-daemon
start-frontend-daemon: ## Start Frontend as daemon
${DEV_CMD} up -d ${SERVICE_FRONTEND}
.PHONY: start-frontend
start-frontend: start-frontend-daemon ## Start React Frontend
@echo -e "\nStarting frontend only. Don't forget to run the backend separately"
@docker attach ${CONTAINER_FRONTEND}
.PHONY: install-backend
install-backend: ## Build development image for Backend
${DEV_CMD} build ${SERVICE_BACKEND}
.PHONY: install-backend-clean
install-backend-clean: ## Build development image for Backend
${DEV_CMD} build ${SERVICE_BACKEND} --no-cache
.PHONY: debug-backend
debug-backend: ## Run bash in the Frontend container
${DEV_CMD} run --rm --entrypoint bash ${SERVICE_BACKEND} || true
.PHONY: stop-backend
stop-backend: ## Stop Frontend
${DEV_CMD} stop ${SERVICE_BACKEND}
.PHONY: start-backend-daemon
start-backend-daemon: ## Start Plone Backend as daemon
${DEV_CMD} up -d ${SERVICE_BACKEND}
.PHONY: start-backend
start-backend: start-backend-daemon ## Start Plone Backend
@echo -e "\nStarting backend only. Don't forget to run the frontend separately"
@docker attach ${CONTAINER_BACKEND}
.PHONY: compose-down
compose-down-clean: ## Build development image for Backend
${DEV_CMD} down --remove-orphans
.PHONY: status
status: ## Status of the stack
@echo -e "\nCommand line for docker-compose to append custom commands:\n${DEV_CMD}\n"
${DEV_CMD} ps
.PHONY: install
install: ## Setup containers for backend and frontend
@echo "Install Backend & Frontend"
$(MAKE) install-backend
$(MAKE) install-frontend
.PHONY: start
start: ## Start Backend and Frontend
@echo "Start Backend & Frontend for development:"
${DEV_CMD} --profile dev up || true
# Code Linting & Formatting
.PHONY: format-backend
format-backend: ## Format Backend Codebase
@echo "Format backend codebase"
$(MAKE) -C "./backend/" format
.PHONY: format-frontend
format-frontend: ## Format Frontend Codebase
@echo "Format frontend codebase"
${DEV_CMD} run --rm ${SERVICE_FRONTEND} lint:fix
${DEV_CMD} run --rm ${SERVICE_FRONTEND} prettier:fix
${DEV_CMD} run --rm ${SERVICE_FRONTEND} stylelint:fix
.PHONY: format
format: ## Format codebase
@echo "Format codebase"
$(MAKE) format-backend
$(MAKE) format-frontend
.PHONY: lint-backend
lint-backend: ## Lint Backend Codebase
@echo "Lint backend codebase"
$(MAKE) -C "./backend/" lint
.PHONY: lint-frontend
lint-frontend: ## Lint Frontend Codebase
@echo "Lint frontend codebase"
${DEV_CMD} run --rm ${SERVICE_FRONTEND} lint
${DEV_CMD} run --rm ${SERVICE_FRONTEND} prettier
# ${DEV_CMD} run --rm ${SERVICE_FRONTEND} stylelint
.PHONY: lint
lint: ## Lint codebase
@echo "Format codebase"
$(MAKE) format-backend
$(MAKE) format-frontend
# .PHONY: i18n
# i18n: ## Update locales
# @echo "Update locales"
# $(MAKE) -C "./backend/" i18n
# $(MAKE) -C "./frontend/" i18n
# Tests
.PHONY: test-backend
test-backend: ## Test backend codebase
@echo "Test backend"
${DEV_CMD} run --rm ${SERVICE_BACKEND} /app/bin/pytest src/ploneconf.core/tests
.PHONY: test-frontend
test-frontend: ## Test frontend codebase
@echo "Test frontend"
${DEV_CMD} run --rm ${SERVICE_FRONTEND} test --watchAll
.PHONY: test-frontend-ci
test-frontend-ci: ## Test frontend codebase once
@echo "Test frontend"
${DEV_CMD} run --rm -e CI=1 ${SERVICE_FRONTEND} test
.PHONY: test
test: test-backend test-frontend-ci ## Test codebase
# Build container images
.PHONY: build-image-frontend
build-image-frontend:
@echo "Build Frontend image"
$(MAKE) -C "./frontend/" build-image
.PHONY: build-image-backend
build-image-backend:
@echo "Build Backend image"
$(MAKE) -C "./backend/" build-image
.PHONY: build-images
build-images: build-image-frontend build-image-backend
create-tag: # Create a new tag using git
@echo "Creating new tag $(PROJECT_VERSION)"
if git show-ref --tags v$(PROJECT_VERSION) --quiet; then echo "$(PROJECT_VERSION) already exists";else git tag -a v$(PROJECT_VERSION) -m "Release $(PROJECT_VERSION)" && git push && git push --tags;fi
commit-and-release: # Commit new version change and create tag
@echo "Commiting changes"
@git commit -am "Tag release as $(PROJECT_VERSION) to deploy"
make create-tag