-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
223 lines (185 loc) · 6.03 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
#
# Parameters
#
export ROOT = $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
export PATH := $(ROOT)/bin:$(PATH)
TMP := tmp
ACCEPTANCE := live-from-production
# To disable husky scripts
export HUSKY=0
# Defaults value for Dev:
## For patching, we need a ref to the local server
export CRYPTOMEDIC_DEV_HTTP_PORT = 8085
export CRYPTOMEDIC_DEV_HTTP_HOST ?= localhost
## Where to deploy
export CRYPTOMEDIC_DEPLOY_WEB_HOST ?= $(CRYPTOMEDIC_HTTP_DEPLOY_HOST)
export CRYPTOMEDIC_DEPLOY_WEB_PORT ?= $(CRYPTOMEDIC_DEV_HTTP_PORT)
export CRYPTOMEDIC_DEPLOY_WEB_TOKEN ?= secret
export DBUPDATEPWD := secret # From config.php
export CRYPTOMEDIC_DOCKER_SOCKET := $(shell docker context inspect | jq -r .[0].Endpoints.docker.Host | sed "s^unix://^^")
define rehydrate
@if [ -r "$(1)" ] && [ "$(1)" -ot "$(2)" ] ; then \
echo "Hydrate $(1)"; \
touch -m --reference "$(2)" "$(1)"; \
fi
endef
# Default target
.PHONY: check
check: cls dependencies lint build test ok
# Test with clean environment
.PHONY: full
full: cls clean stop dc-build start dependencies lint build test ok
.PHONY: ok
ok:
@echo -n "✓ ok at "
@date +"%H:%M:%S"
.PHONY: clean
.PHONY: dump
.PHONY: dependencies
.PHONY: lint
.PHONY: build
.PHONY: test
.PHONY: update
.PHONY: github
include Makefile-backend
include Makefile-frontend
include Makefile-integration
#
# Debug options:
# --warn-undefined-variables
# --debug=basic
#
dump: global-dump
.PHONY: global-dump
global-dump:
@echo ""
@echo "***************"
@echo "*** generic ***"
@echo ""
@echo "Who am i: $(shell whoami) ($(shell id -u))"
@echo "HOME: $(HOME)"
@echo "SHELL: $(SHELL)"
@echo "PATH: $(PATH)"
@echo "arch: $(shell arch)"
@echo "CRYPTOMEDIC_DOCKER_SOCKET: $(CRYPTOMEDIC_DOCKER_SOCKET)"
@echo "ACCEPTANCE: $(ACCEPTANCE)"
@echo "CRYPTOMEDIC_DEPLOY_FILES_HOST: $(CRYPTOMEDIC_DEPLOY_FILES_HOST)"
@echo "CRYPTOMEDIC_DEPLOY_WEB_HOST: $(CRYPTOMEDIC_DEPLOY_WEB_HOST)"
@echo "CRYPTOMEDIC_DEPLOY_WEB_PORT: $(CRYPTOMEDIC_DEPLOY_WEB_PORT)"
@echo "CRYPTOMEDIC_DEV_HTTP_PORT: $(CRYPTOMEDIC_DEV_HTTP_PORT)"
@echo "CRYPTOMEDIC_DEV_HTTP_HOST: $(CRYPTOMEDIC_DEV_HTTP_HOST)"
@echo "------------------------------------------"
@echo "Docker: $(shell docker --version)"
@echo "Docker compose: $(shell docker compose version)"
@echo "Docker security: $(shell docker info -f "{{println .SecurityOptions}}" )"
@echo ""
@echo "+++ lsb release +++"
lsb_release -a
@echo ""
@echo "+++ docker version +++"
# This can fail if the docker server is not running (see CI)
docker version || true
@echo ""
# @echo "MySQL: $(shell QUIET=y bin/cr-mysql --version 2>&1 )"
# @echo "MySQL Server: $(shell QUIET=y bin/cr-mysql --silent --database mysql --raw --skip-column-names -e "SELECT VERSION();" 2>&1)"
# @echo "MySQL user: $(shell QUIET=y bin/cr-mysql --silent --database mysql --raw --skip-column-names -e "SELECT CURRENT_USER; " 2>&1)"
.PHONY: clear
clear: cls
.PHONY: cls
cls:
@if [ -z "$$NO_CLEAR" ]; then clear; fi || true
@echo "**"
@echo "**"
@echo "** Tests starting at $$(date) **"
@echo "**"
@echo "**"
clean: stop clean-files
# find . -name "tmp" -prune -exec "rm" "-fr" "{}" ";" || true
rm -fr "$(ROOT)/tmp"
clean-files:
find . -name "*.log" -delete
rm -f "$(ROOT)/.ovhconfig"
rm -f "$(ROOT)/www/built/backup"
rm -f "$(ROOT)/www/built/browsers.json"
dc-build:
docker compose build
docker compose --profile=tools build
.PHONY: start
start: dc-up dependencies build reset
@echo "Open browser: http://$(CRYPTOMEDIC_DEV_HTTP_HOST):$(CRYPTOMEDIC_DEV_HTTP_PORT)/"
@echo "Test page: http://$(CRYPTOMEDIC_DEV_HTTP_HOST):$(CRYPTOMEDIC_DEV_HTTP_PORT)/dev/"
@echo -n "Official port: "
@docker compose port proxy 80
dev: clear start
# No reset!
# build: other stuff than frontend need to be build
dc-up:
docker compose up -d --wait --remove-orphans --build
# bin/cr-refresh-structure "http://$(CRYPTOMEDIC_HTTP_DEPLOY_HOST):$(CRYPTOMEDIC_HTTP_DEPLOY_PORT)/" "secret"
stop:
docker compose down --volumes --remove-orphans
docker compose kill -s SIGINT mysql || true
@echo ""
.PHONY: logs
logs:
docker compose logs -f
reset:
bin/cr-data-reset
database-update-base-sql:
bin/cr-database-backup
lint: global-lint-prettier
.PHONY: global-lint-prettier
global-lint-prettier: $(FRONTEND_DEPENDENCIES_MARK)
node_modules/.bin/prettier --check .
.PHONY: global-lint-prettier-fix
global-lint-prettier-fix: $(FRONTEND_DEPENDENCIES_MARK)
node_modules/.bin/prettier --write .
#
#
# Acceptance
#
#
acceptance: $(ACCEPTANCE)/.done dc-up
cr-mysql -e "DROP DATABASE cryptomedic; CREATE DATABASE cryptomedic"
cr-mysql --database=cryptomedic < "$(ACCEPTANCE)"/backups/backup.sql
cr-refresh-structure "http://$(CRYPTOMEDIC_HTTP_DEPLOY_HOST):$(CRYPTOMEDIC_HTTP_DEPLOY_PORT)/" "secret"
rsync -itr --delete "$(ACCEPTANCE)"/storage/ live/storage
$(ACCEPTANCE)/.done:
bin/cr-live-backup.sh "$(dir $@)"
touch "$@"
acceptance-refresh:
rm -f "$(ROOT)/$(ACCEPTANCE)/.done"
# Do not depend but force running
make "$(ROOT)/$(ACCEPTANCE)/.done"
acceptance-clean:
rm -f "$(ROOT)/$(ACCEPTANCE)/"
#
# Deploy command
#
.PHONY: deploy
deploy: .ovhconfig $(HOME)/.ssh/id_rsa
bin/cr-deploy-sshfs commit
.PHONY: deploy-test
deploy-test: .ovhconfig $(HOME)/.ssh/id_rsa
bin/cr-deploy-sshfs
$(HOME)/.ssh/id_rsa:
mkdir -p "$(HOME)"/.ssh
ssh-keygen -b 2048 -t rsa -f "$(HOME)"/.ssh/id_rsa -q -N ""
.PHONY: build
build: \
www/built/backup \
www/built/release_version.txt \
.ovhconfig
.ovhconfig: conf/ovhconfig .env
bash -c "set -o allexport; source .env; envsubst < conf/ovhconfig > $@"
www/built/backup: bin/cr-live-backup.sh
# Make the backup script available to web
@mkdir -p "$(dir $@)"
cp -f "$<" "$@"
www/built/release_version.txt:
@mkdir -p "$(dir $@)"
date > "$@"
.PHONY: update-references-browsers
update: update-references-browsers
update-references-browsers:
node_modules/.bin/browserslist --update-db