-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
310 lines (255 loc) · 10.4 KB
/
Copy pathMakefile
File metadata and controls
310 lines (255 loc) · 10.4 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
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
### 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
CURRENT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
GIT_FOLDER=$(CURRENT_DIR)/.git
PROJECT_NAME=kitconcept-intranet
STACK_FILE=docker-compose-dev.yml
STACK_FILE_DEV=docker-compose-dev.yml
STACK_FILE_CI=docker-compose-ci.yml
STACK_HOSTNAME=kitconcept-intranet.localhost
# Docker Compose Helpers
STACK_PROFILE := $(if $(filter undefined,$(origin COMPOSE_PROFILES)),dev,$(COMPOSE_PROFILES))
COMPOSE_DEV := docker compose -f $(STACK_FILE) --profile dev
COMPOSE_ACCEPTANCE := docker compose -f $(STACK_FILE) --profile acceptance
COMPOSE_A11y := docker compose -f $(STACK_FILE) --profile a11y
COMPOSE_CI := docker compose -f $(STACK_FILE) -f $(STACK_FILE_CI) --profile $(STACK_PROFILE)
# CI Test Command
CI_TEST_COMMAND := $(if $(filter a11y,$(STACK_PROFILE)),ci-acceptance-a11y-test,ci-acceptance-test)
# Versioning variables
VOLTO_VERSION = $(shell cat frontend/mrs.developer.json | python -c "import sys, json; print(json.load(sys.stdin)['core']['tag'])")
KC_VERSION=$(shell cat backend/version.txt)
IMAGE_TAG=latest
# Environment variables to be exported
export VOLTO_VERSION := $(VOLTO_VERSION)
export KC_VERSION := $(KC_VERSION)
export DOCKER_BUILDKIT := 1
export COMPOSE_BAKE := 1
# 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`
.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}'
###########################################
# Frontend
###########################################
.PHONY: frontend-install
frontend-install: ## Install React Frontend
$(MAKE) -C "./frontend/" install
.PHONY: frontend-build
frontend-build: ## Build React Frontend
$(MAKE) -C "./frontend/" build
.PHONY: frontend-start
frontend-start: ## Start React Frontend
$(MAKE) -C "./frontend/" start
.PHONY: frontend-test
frontend-test: ## Test frontend codebase
@echo "Test frontend"
$(MAKE) -C "./frontend/" test
###########################################
# Backend
###########################################
.PHONY: backend-install
backend-install: ## Create virtualenv and install Plone
$(MAKE) -C "./backend/" install
$(MAKE) backend-create-site
.PHONY: backend-build
backend-build: ## Build Backend
$(MAKE) -C "./backend/" install
.PHONY: backend-create-site
backend-create-site: ## Create a Plone site with default content
$(MAKE) -C "./backend/" create-site
.PHONY: backend-update-example-content
backend-update-example-content: ## Export example content inside package
$(MAKE) -C "./backend/" update-example-content
.PHONY: backend-update-example-content-bug-workaround
backend-update-example-content-bug-workaround: ## Export example content inside package
# portlets.json always changes without any actual content amendments
git checkout origin/main backend/src/kitconcept/intranet/distributions/intranet/content/portlets.json
# RSS block example content is deleted without any actual deletion
git checkout origin/main backend/src/kitconcept/intranet/distributions/intranet/content/content/7c7cf1aae1a9431db3a706615a410cdc/data.json
# "remoteUrl" starts with "http://nohost/"
git checkout origin/main backend/src/kitconcept/intranet/distributions/intranet/content/content/195d96ca9952493cbffa69cda040b8b3/data.json
.PHONY: backend-delete-and-create-site
backend-delete-and-create-site: ## Remove all content and create site
$(MAKE) -C "./backend/" remove-data
$(MAKE) -C "./backend/" create-site
.PHONY: backend-start
backend-start: ## Start Plone Backend
$(MAKE) -C "./backend/" start
.PHONY: backend-test
backend-test: ## Test backend codebase
@echo "Test backend"
$(MAKE) -C "./backend/" test
.PHONY: install
install: ## Install
@echo "Install Backend & Frontend"
$(MAKE) backend-install
$(MAKE) frontend-install
.PHONY: start
start: ## Start
@echo "Starting application"
$(MAKE) backend-start
$(MAKE) frontend-start
.PHONY: clean
clean: ## Clean installation
@echo "Clean installation"
$(MAKE) -C "./backend/" clean
$(MAKE) -C "./frontend/" clean
.PHONY: status
status: ## Show status
@echo "Show status"
python3 ./dirty.py
.PHONY: list-frontend-packages
list-frontend-packages: ## List frontend packages and their tags from mrs.developer.json
@python3 -c 'import json; f = open("frontend/mrs.developer.json"); data = json.load(f); f.close(); result = {v["package"]: v.get("tag", None) for v in data.values() if isinstance(v, dict) and "package" in v and "tag" in v}; print(json.dumps(result, indent=2))'
.PHONY: format
format: ## Format codebase
@echo "Format codebase"
$(MAKE) -C "./backend/" format
$(MAKE) -C "./frontend/" format
.PHONY: lint
lint: ## Lint codebase
@echo "Lint codebase"
$(MAKE) -C "./backend/" lint
$(MAKE) -C "./frontend/" lint
.PHONY: i18n
i18n: ## Update locales
@echo "Update locales"
$(MAKE) -C "./backend/" i18n
$(MAKE) -C "./frontend/" i18n
.PHONY: test
test: backend-test frontend-test ## Test codebase
.PHONY: build-images
build-images: ## Build docker images
@echo "Build Images"
$(MAKE) -C "./backend/" build-image
$(MAKE) -C "./frontend/" build-image
## Docker stack
.PHONY: stack-start
stack-start: ## Local Stack: Start Services
@echo "Start local Docker stack"
VOLTO_VERSION=$(VOLTO_VERSION) KC_VERSION=$(KC_VERSION) docker compose -f $(STACK_FILE) up -d --build
@echo "Now visit: http://$(STACK_HOSTNAME)/ to access the site"
@echo "- http://$(STACK_HOSTNAME)/ to access the default site"
@echo "- http://admin-$(STACK_HOSTNAME)/ to create a new site"
@echo "- http://traefik.$(STACK_HOSTNAME)/ to access the Traefik dashboard"
.PHONY: start-stack
stack-create-site: ## Local Stack: Create a new site
@echo "Create a new site in the local Docker stack"
$(COMPOSE_DEV) exec backend ./docker-entrypoint.sh create-site
.PHONY: start-status
stack-status: ## Local Stack: Check Status
@echo "Check the status of the local Docker stack"
$(COMPOSE_DEV) ps
.PHONY: stack-stop
stack-stop: ## Local Stack: Stop Services
@echo "Stop local Docker stack"
$(COMPOSE_DEV) stop
.PHONY: stack-rm
stack-rm: ## Local Stack: Remove Services and Volumes
@echo "Remove local Docker stack"
$(COMPOSE_DEV) down
@echo "Remove local volume data"
@docker volume rm $(PROJECT_NAME)_vol-site-data
####################################################
## Acceptance
####################################################
.PHONY: acceptance-backend-dev-start
acceptance-backend-dev-start: ## Build Acceptance Servers
@echo "Build acceptance backend"
$(MAKE) -C "./backend/" acceptance-backend-start
.PHONY: acceptance-frontend-dev-start
acceptance-frontend-dev-start: ## Build Acceptance Servers
@echo "Build acceptance backend"
$(MAKE) -C "./frontend/" acceptance-frontend-dev-start
.PHONY: acceptance-test
acceptance-test: ## Start Acceptance tests in interactive mode
@echo "Build acceptance backend"
$(MAKE) -C "./frontend/" acceptance-test
## A11y tests
.PHONY: acceptance-a11y-backend-dev-start
acceptance-a11y-backend-dev-start: ## Start a11y acceptance backend in dev mode
@echo "Start acceptance backend"
$(MAKE) -C "./backend/" acceptance-a11y-backend-start
.PHONY: acceptance-a11y-frontend-dev-start
acceptance-a11y-frontend-dev-start: ## Start a11y acceptance frontend in dev mode
$(MAKE) -C "./frontend/" acceptance-a11y-frontend-dev-start
.PHONY: acceptance-a11y-frontend-prod-start
acceptance-a11y-frontend-prod-start: ## Start a11y acceptance frontend in prod mode
$(MAKE) -C "./frontend/" acceptance-a11y-frontend-prod-start
.PHONY: acceptance-a11y-test
acceptance-a11y-test: ## Start a11y Cypress in interactive mode
$(MAKE) -C "./frontend/" acceptance-a11y-test
.PHONY: ci-acceptance-a11y-test
ci-acceptance-a11y-test: ## Run a11y cypress tests in headless mode for CI
$(MAKE) -C "./frontend/" ci-acceptance-a11y-test
## A11y tests with Containers
.PHONY: acceptance-a11y-images-build
acceptance-a11y-images-build: ## Build A11y frontend/backend images
@echo "Build acceptance a11y images build"
$(COMPOSE_A11y) build
.PHONY: acceptance-a11y-containers-start
acceptance-a11y-containers-start: ## Start A11y containers
@echo "Start acceptance a11y containers"
$(COMPOSE_A11y) up -d
.PHONY: acceptance-a11y-containers-stop
acceptance-a11y-containers-stop: ## Stop A11y containers
@echo "Stop acceptance a11y containers"
$(COMPOSE_A11y) down
## Acceptance tests with Containers
.PHONY: acceptance-images-build
acceptance-images-build: ## Build Acceptance frontend/backend images
@echo "Build acceptance images build"
$(COMPOSE_ACCEPTANCE) build
.PHONY: acceptance-containers-start
acceptance-containers-start: ## Start Acceptance containers
@echo "Start acceptance containers"
$(COMPOSE_ACCEPTANCE) up -d
.PHONY: acceptance-containers-stop
acceptance-containers-stop: ## Stop Acceptance containers
@echo "Stop acceptance containers"
$(COMPOSE_ACCEPTANCE) down
## Acceptance / A11y tests in CI
.PHONY: ci-images-load
ci-images-load: ## Load container images in CI
@echo "Load container images"
$(COMPOSE_CI) pull
.PHONY: ci-containers-start
ci-containers-start: ## Start Acceptance containers
@echo "Start containers"
$(COMPOSE_CI) up
.PHONY: ci-test
ci-test: ## Run Acceptance tests in ci mode
@echo "Run tests"
$(MAKE) -C "./frontend/" $(CI_TEST_COMMAND)
.PHONY: ci-a11y-test-complete
ci-a11y-test-complete: ## Simulate CI a11y test run
@echo "Simulate CI a11y test run"
$(MAKE) acceptance-a11y-containers-start
@echo "- Waiting for backend and frontend to be ready"
pnpx wait-on --httpTimeout 20000 http-get://localhost:8080/plone http://localhost:3000
-$(MAKE) -C "./frontend/" ci-acceptance-a11y-test || true
$(MAKE) acceptance-a11y-containers-stop
.PHONY: ci-acceptance-test-complete
ci-acceptance-test-complete: ## Simulate CI acceptance test run
@echo "Simulate CI acceptance test run"
$(MAKE) acceptance-containers-start
@echo "- Waiting for backend and frontend to be ready"
pnpx wait-on --httpTimeout 20000 http-get://localhost:55001/plone http://localhost:3000
-$(MAKE) -C "./frontend/" ci-acceptance-test || true
$(MAKE) acceptance-containers-stop