forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
170 lines (144 loc) · 5.51 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
#
# Makefile
#
# this is horrible magic, we use it to open a nice welcome message for
# the user in tmux in the shell that they normally use (e.g. bash, zsh)
# https://unix.stackexchange.com/questions/352316/finding-out-the-default-shell-of-a-user-within-a-shell-script
LOGIN_SHELL = $(shell finger $(USER) | grep 'Shell:*' | cut -f3 -d ":")
# setting .env variables as Make variables for validate.env targets
# https://lithic.tech/blog/2020-05/makefile-dot-env/
ifneq (,$(wildcard ./.env))
include .env
export
endif
help:
@echo 'Available commands:'
@echo
@echo ' GRAPHER ONLY'
@echo ' make up start dev environment via docker-compose and tmux'
@echo ' make down stop any services still running'
@echo
@echo ' GRAPHER + WORDPRESS (staff-only)'
@echo ' make up.full start dev environment via docker-compose and tmux'
@echo ' make down.full stop any services still running'
@echo
up: export DEBUG = 'knex:query'
up: require create-if-missing.env tmp-downloads/owid_chartdata.sql.gz
@make validate.env
@make check-port-3306
@echo '==> Building grapher'
yarn install
yarn run tsc -b
@echo '==> Starting dev environment'
tmux new-session -s grapher \
-n docker 'docker-compose -f docker-compose.grapher.yml up' \; \
set remain-on-exit on \; \
new-window -n admin \
'devTools/docker/wait-for-mysql.sh && yarn run tsc-watch -b --onSuccess "yarn startAdminServer"' \; \
set remain-on-exit on \; \
new-window -n webpack 'yarn run startSiteFront' \; \
set remain-on-exit on \; \
new-window -n welcome 'devTools/docker/banner.sh; exec $(LOGIN_SHELL)' \; \
bind R respawn-pane -k \; \
bind X kill-pane \; \
bind Q kill-server \
|| make down
up.devcontainer: create-if-missing.env.devcontainer tmp-downloads/owid_chartdata.sql.gz
@make validate.env
@make check-port-3306
@echo '==> Building grapher'
yarn install
yarn run tsc -b
@echo '==> Starting dev environment'
tmux new-session -s grapher \
-n admin \
'devTools/docker/wait-for-mysql.sh && yarn run tsc-watch -b --onSuccess "yarn startAdminServer"' \; \
set remain-on-exit on \; \
new-window -n webpack 'yarn run startSiteFront' \; \
set remain-on-exit on \; \
new-window -n welcome 'devTools/docker/banner.sh; exec $(LOGIN_SHELL)' \; \
bind R respawn-pane -k \; \
bind X kill-pane \; \
bind Q kill-server
up.full: export DEBUG = 'knex:query'
up.full: require create-if-missing.env.full wordpress/.env tmp-downloads/owid_chartdata.sql.gz tmp-downloads/live_wordpress.sql.gz wordpress/web/app/uploads/2022
@make validate.env.full
@make check-port-3306
@echo '==> Building grapher'
yarn install
yarn run tsc -b
yarn buildWordpressPlugin
@echo '==> Starting dev environment'
tmux new-session -s grapher \
-n docker 'docker-compose -f docker-compose.full.yml up' \; \
set remain-on-exit on \; \
new-window -n admin \
'devTools/docker/wait-for-mysql.sh && yarn run tsc-watch -b --onSuccess "yarn startAdminServer"' \; \
set remain-on-exit on \; \
new-window -n webpack 'yarn run startSiteFront' \; \
set remain-on-exit on \; \
new-window -n welcome 'devTools/docker/banner.sh; exec $(LOGIN_SHELL)' \; \
bind R respawn-pane -k \; \
bind X kill-pane \; \
bind Q kill-server \
|| make down.full
down:
@echo '==> Stopping services'
docker-compose -f docker-compose.grapher.yml down
down.full:
@echo '==> Stopping services'
docker-compose -f docker-compose.full.yml down
require:
@echo '==> Checking your local environment has the necessary commands...'
@which docker-compose >/dev/null 2>&1 || (echo "ERROR: docker-compose is required."; exit 1)
@which yarn >/dev/null 2>&1 || (echo "ERROR: yarn is required."; exit 1)
@which tmux >/dev/null 2>&1 || (echo "ERROR: tmux is required."; exit 1)
@which finger >/dev/null 2>&1 || (echo "ERROR: finger is required."; exit 1)
guard-%:
@if [ -z "${${*}}" ]; then echo 'ERROR: .env variable $* not set' && exit 1; fi
create-if-missing.env:
@if test ! -f .env; then \
echo 'Copying .env.example-grapher --> .env'; \
cp .env.example-grapher .env; \
fi
create-if-missing.env.devcontainer:
@if test ! -f .env; then \
echo 'Copying .env.devcontainer --> .env'; \
cp .env.devcontainer .env; \
fi
validate.env:
@echo '==> Validating your .env file for make up'
@grep '=' .env.example-grapher | sed 's/=.*//' | while read variable; \
do make guard-$$variable 2>/dev/null || exit 1; \
done
@echo '.env file valid for make up'
create-if-missing.env.full:
@if test ! -f .env; then \
echo 'Copying .env.example-full --> .env'; \
cp .env.example-full .env; \
fi
validate.env.full:
@echo '==> Validating your .env file for make up.full'
@grep '=' .env.example-full | sed 's/=.*//' | while read variable; \
do make guard-$$variable 2>/dev/null || exit 1; \
done
@echo '.env file valid for make up.full'
check-port-3306:
@echo "==> Checking port"
@if [ "${GRAPHER_DB_PORT}" = "3306" ]; then \
echo "Your database port is set to 3306.\
\nThis will likely conflict with any pre-existing MySQL instances you have running.\
\nWe recommend using a different port (like 3307)";\
fi
tmp-downloads/owid_chartdata.sql.gz:
@echo '==> Downloading chart data'
./devTools/docker/download-grapher-mysql.sh
tmp-downloads/live_wordpress.sql.gz:
@echo '==> Downloading wordpress data'
./devTools/docker/download-wordpress-mysql.sh
wordpress/.env:
@echo 'Copying wordpress/.env.example --> wordpress/.env'
@cp -f wordpress/.env.example wordpress/.env
wordpress/web/app/uploads/2022:
@echo '==> Downloading wordpress uploads'
./devTools/docker/download-wordpress-uploads.sh