This repository has been archived by the owner on Jan 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
204 lines (159 loc) · 7.69 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
#MAKEFLAGS += --warn-undefined-variables
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := all
.DELETE_ON_ERROR:
.SUFFIXES:
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
project_dir := $(dir $(mkfile_path))
PYTHON := $(project_dir)bin/python
PIP := $(project_dir)bin/pip
# Local pip is used by creating a python virtual environment and running `source ./bin/activate`
# Set to tmp/ when debugging the install
# make PREFIXDIR=${PWD}/tmp inspect.SRVDIR
# make PREFIXDIR=${PWD}/tmp ENVIRONMENT=development install
PREFIXDIR :=
# Set to development or production
ENVIRONMENT := development
ENV_FILE := ${PWD}/.env
PORTREGISTRY := ${PWD}/port-registry.cfg
SRVDIR := $(PREFIXDIR)/srv/puzzle-massive/
NGINXDIR := $(PREFIXDIR)/etc/nginx/
SYSTEMDDIR := $(PREFIXDIR)/etc/systemd/system/
DATABASEDIR := $(PREFIXDIR)/var/lib/puzzle-massive/sqlite3/
NGINXLOGDIR := $(PREFIXDIR)/var/log/nginx/puzzle-massive/
AWSTATSLOGDIR := $(PREFIXDIR)/var/log/awstats/puzzle-massive/
ARCHIVEDIR := $(PREFIXDIR)/var/lib/puzzle-massive/archive/
CACHEDIR := $(PREFIXDIR)/var/lib/puzzle-massive/cache/
PURGEURLLIST := $(PREFIXDIR)/var/lib/puzzle-massive/nginx/urls-to-purge.txt
IMAGEMAGICK_POLICY := $(PREFIXDIR)/etc/ImageMagick-6/policy.xml
# Set the internal ip which is used to secure access to admin/ pages.
INTERNALIP := $(shell hostname -I | cut -d' ' -f1)
# Get the version from the package.json
TAG := $(shell cat package.json | $(PYTHON) -c 'import sys, json; print(json.load(sys.stdin)["version"])')
# For debugging what is set in variables
inspect.%:
@echo $($*)
ifeq ($(shell ls bin/activate),)
$(error No bin/activate found. Run "'virtualenv . -p python3' or 'python3 -m venv .' to create a python virtual environment")
endif
#ifneq ($(shell which python),$(project_dir)bin/python)
#$(warning run "source bin/activate" to activate the python virtual environment. Using $(shell which python). Ignore this warning if using sudo make install.)
#endif
# Always run. Useful when target is like targetname.% .
# Use $* to get the stem
FORCE:
nginx_web_snippets := $(patsubst web/snippets/%.nginx.conf.sh, web/snippets/%.nginx.conf, $(wildcard web/snippets/*.nginx.conf.sh))
objects := site.cfg $(nginx_web_snippets) stats/awstats.puzzle.massive.xyz.conf stats/awstats-puzzle-massive-crontab
#####
bin/chill: chill/requirements.txt requirements.txt
$(PIP) install wheel
$(PIP) install --upgrade --upgrade-strategy eager -r $<
touch $@;
objects += chill/puzzle-massive-chill.service
chill/puzzle-massive-chill.service: chill/puzzle-massive-chill.service.sh
./$< $(ENVIRONMENT) $(project_dir) > $@
# Create a tar of the frozen directory to prevent manually updating files within it.
# Not using a frozen.tar.gz for now.
#objects += frozen.tar.gz
frozen.tar.gz: db.dump.sql site.cfg package.json $(shell find templates/ -type f -print) $(shell find documents/ -type f -print) $(shell find queries/ -type f -print)
bin/freeze.sh $@
objects += db.dump.sql
# Create db.dump.sql from site-data.sql and any chill-*.yaml files
db.dump.sql: site.cfg site-data.sql $(wildcard chill-*.yaml)
bin/create-db-dump-sql.sh
# Also installs janitor, scheduler and artist
bin/puzzle-massive-api: api/requirements.txt requirements.txt api/setup.py
$(PIP) install wheel
$(PIP) install --upgrade --upgrade-strategy eager -r $<
touch $@;
bin/puzzle-massive-divulger: divulger/requirements.txt requirements.txt divulger/setup.py
$(PIP) install wheel
$(PIP) install --upgrade --upgrade-strategy eager -r $<
touch $@;
bin/puzzle-massive-stream: stream/requirements.txt requirements.txt stream/setup.py
$(PIP) install wheel
$(PIP) install --upgrade --upgrade-strategy eager -r $<
touch $@;
bin/puzzle-massive-enforcer: enforcer/requirements.txt requirements.txt enforcer/setup.py
$(PIP) install wheel
$(PIP) install --upgrade --upgrade-strategy eager -r $<
touch $@;
objects += api/puzzle-massive-api.service
api/puzzle-massive-api.service: api/puzzle-massive-api.service.sh
./$< $(ENVIRONMENT) $(project_dir) > $@
objects += api/puzzle-massive-publish.service
api/puzzle-massive-publish.service: api/puzzle-massive-publish.service.sh
./$< $(ENVIRONMENT) $(project_dir) > $@
objects += api/puzzle-massive-artist.service
api/puzzle-massive-artist.service: api/puzzle-massive-artist.service.sh
./$< $(project_dir) > $@
objects += api/puzzle-massive-janitor.service
api/puzzle-massive-janitor.service: api/puzzle-massive-janitor.service.sh
./$< $(project_dir) > $@
objects += api/puzzle-massive-scheduler.service
api/puzzle-massive-scheduler.service: api/puzzle-massive-scheduler.service.sh
./$< $(project_dir) > $@
objects += divulger/puzzle-massive-divulger.service
divulger/puzzle-massive-divulger.service: divulger/puzzle-massive-divulger.service.sh
./$< $(project_dir) > $@
objects += stream/puzzle-massive-stream.service
stream/puzzle-massive-stream.service: stream/puzzle-massive-stream.service.sh
./$< $(project_dir) > $@
objects += enforcer/puzzle-massive-enforcer.service
enforcer/puzzle-massive-enforcer.service: enforcer/puzzle-massive-enforcer.service.sh
./$< $(project_dir) > $@
objects += api/puzzle-massive-cache-purge.path
api/puzzle-massive-cache-purge.path: api/puzzle-massive-cache-purge.path.sh
./$< $(PURGEURLLIST) > $@
objects += api/puzzle-massive-cache-purge.service
api/puzzle-massive-cache-purge.service: api/puzzle-massive-cache-purge.service.sh
./$< $(PORTREGISTRY) $(CACHEDIR) $(project_dir) $(PURGEURLLIST) > $@
objects += api/puzzle-massive-backup-db.service
api/puzzle-massive-backup-db.service: api/puzzle-massive-backup-db.service.sh
./$< $(ENVIRONMENT) $(project_dir) $(ENV_FILE) > $@
objects += api/puzzle-massive-backup-db.timer
api/puzzle-massive-backup-db.timer: api/puzzle-massive-backup-db.timer.sh
./$< $(ENVIRONMENT) > $@
site.cfg: site.cfg.sh $(PORTREGISTRY) $(ENV_FILE)
./$< $(ENVIRONMENT) $(DATABASEDIR) $(PORTREGISTRY) $(SRVDIR) $(ARCHIVEDIR) $(CACHEDIR) $(PURGEURLLIST) > $@
web/snippets/%.nginx.conf: web/snippets/%.nginx.conf.sh $(PORTREGISTRY) $(ENV_FILE) site.cfg
./$< $(ENVIRONMENT) > $@
stats/awstats.puzzle.massive.xyz.conf: stats/awstats.puzzle.massive.xyz.conf.sh
./$< $(NGINXLOGDIR) > $@
stats/awstats-puzzle-massive-crontab: stats/awstats-puzzle-massive-crontab.sh
./$< $(SRVDIR) $(AWSTATSLOGDIR) > $@
.PHONY: puzzle-massive-$(TAG).tar.gz
puzzle-massive-$(TAG).tar.gz: bin/dist.sh
./$< $(abspath $@)
######
.PHONY: all
all: bin/chill bin/puzzle-massive-api bin/puzzle-massive-divulger bin/puzzle-massive-stream bin/puzzle-massive-enforcer media $(objects)
.PHONY: install
install:
./bin/install.sh $(ENVIRONMENT) $(SRVDIR) $(NGINXDIR) $(NGINXLOGDIR) $(AWSTATSLOGDIR) $(SYSTEMDDIR) $(DATABASEDIR) $(ARCHIVEDIR) $(CACHEDIR) $(PURGEURLLIST) $(IMAGEMAGICK_POLICY)
# Remove any created files in the src directory which were created by the
# `make all` recipe.
.PHONY: clean
clean:
rm $(objects)
printf '%s\0' $(objects) | xargs -0 rm -f
$(PIP) uninstall --yes -r chill/requirements.txt
$(PIP) uninstall --yes -r api/requirements.txt
$(PIP) uninstall --yes -r divulger/requirements.txt
$(PIP) uninstall --yes -r stream/requirements.txt
$(PIP) uninstall --yes -r enforcer/requirements.txt
for mk in $(source_media_mk); do make -f $${mk} clean; done;
# Remove files placed outside of src directory and uninstall app.
# Will also remove the sqlite database file.
.PHONY: uninstall
uninstall:
./bin/uninstall.sh $(SRVDIR) $(NGINXDIR) $(SYSTEMDDIR) $(DATABASEDIR) $(ARCHIVEDIR) $(CACHEDIR) $(PURGEURLLIST) $(IMAGEMAGICK_POLICY)
.PHONY: dist
dist: puzzle-massive-$(TAG).tar.gz
# Find any make files in the source-media folder. Sort so the 00_ratio-hint.mk
# is last.
source_media_mk := $(shell find source-media/ -type f -name '*.mk' -print | sort --dictionary-order --ignore-case --reverse)
.PHONY: media
media:
for mk in $(source_media_mk); do make -f $${mk}; done;