forked from thechangelog/changelog.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
304 lines (256 loc) Β· 9.24 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
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
SHELL := bash# we want bash behaviour in all shell invocations
PLATFORM := $(shell uname)
platform = $(shell echo $(PLATFORM) | tr A-Z a-z)
MAKEFILE := $(firstword $(MAKEFILE_LIST))
# https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/
RED := $(shell tput setaf 1)
GREEN := $(shell tput setaf 2)
YELLOW := $(shell tput setaf 3)
BOLD := $(shell tput bold)
NORMAL := $(shell tput sgr0)
ifneq (4,$(firstword $(sort $(MAKE_VERSION) 4)))
$(warning $(BOLD)$(RED)GNU Make v4 or newer is required$(NORMAL))
$(info On macOS it can be installed with $(BOLD)brew install make$(NORMAL) and run as $(BOLD)gmake$(NORMAL))
$(error Please run with GNU Make v4 or newer)
endif
### VARS ###
#
# https://tools.ietf.org/html/rfc3339 format - s/:/./g so that Docker tag is valid
export BUILD_VERSION := $(shell date -u +'%Y-%m-%dT%H.%M.%SZ')
STACK_VERSION ?= 202008
HOSTNAME ?= 2020.changelog.com
GIT_REPOSITORY ?= https://github.com/thechangelog/changelog.com
GIT_BRANCH ?= master
LOCAL_BIN := $(CURDIR)/bin
PATH := $(LOCAL_BIN):$(PATH)
export PATH
ifeq ($(PLATFORM),Darwin)
OPEN := open
else
OPEN := xdg-open
endif
XDG_CONFIG_HOME := $(CURDIR)/.config
export XDG_CONFIG_HOME
### DEPS ###
#
ifeq ($(PLATFORM),Darwin)
DOCKER ?= /usr/local/bin/docker
COMPOSE ?= $(DOCKER)-compose
$(DOCKER) $(COMPOSE):
brew cask install docker \
&& open -a Docker
endif
ifeq ($(PLATFORM),Linux)
DOCKER ?= /usr/bin/docker
$(DOCKER): $(CURL)
@sudo apt-get update && \
sudo apt-get install apt-transport-https gnupg-agent && \
$(CURL) -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && \
APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=true apt-key finger | \
grep --quiet "9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88" && \
echo "deb https://download.docker.com/linux/ubuntu $$(lsb_release -c -s) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list && \
sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io && \
sudo adduser $$USER docker && newgrp docker && sudo service restart docker
COMPOSE ?= /usr/local/bin/docker-compose
$(COMPOSE):
@sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$$(uname -s)-$$(uname -m)" -o /usr/local/bin/docker-compose && \
sudo chmod a+x /usr/local/bin/docker-compose
endif
CURL ?= /usr/bin/curl
ifeq ($(PLATFORM),Linux)
$(CURL):
@sudo apt-get update && sudo apt-get install curl
endif
ifeq ($(PLATFORM),Darwin)
JQ := /usr/local/bin/jq
$(JQ):
@brew install jq
endif
ifeq ($(PLATFORM),Linux)
JQ ?= /snap/bin/jq
$(JQ):
@sudo snap install jq
endif
ifeq ($(PLATFORM),Darwin)
LPASS := /usr/local/bin/lpass
$(LPASS):
@brew install lastpass-cli
endif
ifeq ($(PLATFORM),Linux)
LPASS := /usr/bin/lpass
$(LPASS):
@sudo apt-get update && sudo apt-get install lastpass-cli
endif
TERRAFORM := /usr/local/bin/terraform
$(TERRAFORM):
ifeq ($(PLATFORM),Darwin)
@brew install terraform
endif
ifeq ($(PLATFORM),Linux)
$(error $(RED)Please install $(BOLD)Terraform v0.13$(NORMAL) in $(TERRAFORM): https://www.terraform.io/downloads.html)
endif
ifeq ($(PLATFORM),Darwin)
WATCH := /usr/local/bin/watch
$(WATCH):
@brew install watch
endif
ifeq ($(PLATFORM),Linux)
WATCH := /usr/bin/watch
endif
WATCH_MAKE_TARGET = $(WATCH) --color $(MAKE) --makefile $(MAKEFILE) --no-print-directory
SECRETS := mkdir -p $(XDG_CONFIG_HOME)/.config && $(LPASS) ls "Shared-changelog/secrets"
TF := cd terraform && $(TERRAFORM)
# Enable Terraform debugging if make runs in debug mode
ifneq (,$(findstring d,$(MFLAGS)))
TF_LOG ?= debug
export TF_LOG
endif
AWS := /usr/local/bin/aws
$(AWS):
ifeq ($(PLATFORM),Darwin)
@brew install awscli
endif
ifeq ($(PLATFORM),Linux)
AWS := /usr/bin/aws
$(error $(RED)Please install $(BOLD)AWS CLI v2$(NORMAL): https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)
endif
### TARGETS ###
#
.DEFAULT_GOAL := help
include $(CURDIR)/mk/docker.mk
include $(CURDIR)/mk/secrets.mk
include $(CURDIR)/mk/lke.mk
colours:
@echo "$(BOLD)BOLD $(RED)RED $(GREEN)GREEN $(YELLOW)YELLOW $(NORMAL)"
define MAKE_TARGETS
awk -F: '/^[^\.%\t][a-zA-Z\._\-]*:+.*$$/ { printf "%s\n", $$1 }' $(MAKEFILE_LIST)
endef
define BASH_AUTOCOMPLETE
complete -W \"$$($(MAKE_TARGETS) | sort | uniq)\" make gmake m
endef
.PHONY: autocomplete
autocomplete: ## ac | Configure shell autocomplete - eval "$(make autocomplete)"
@echo "$(BASH_AUTOCOMPLETE)"
.PHONY: ac
ac: autocomplete
# Continuous Feedback for the ac target - run in a split window while iterating on it
.PHONY: CFac
CFac: $(WATCH)
@$(WATCH_MAKE_TARGET) ac
.PHONY: create-dirs-mounted-as-volumes
create-dirs-mounted-as-volumes:
@mkdir -p $(CURDIR)/priv/{uploads,db}
.PHONY: help
help:
@awk -F"[:#]" '/^[^\.][a-zA-Z\._\-]+:+.+##.+$$/ { printf "\033[36m%-24s\033[0m %s\n", $$1, $$4 }' $(MAKEFILE_LIST) \
| sort
# Continuous Feedback for the help target - run in a split window while iterating on it
.PHONY: CFhelp
CFhelp: $(WATCH)
@$(WATCH_MAKE_TARGET) help
.PHONY: contrib
contrib: $(COMPOSE) create-dirs-mounted-as-volumes ## c | Contribute to changelog.com by running a local copy
@bash -c "trap '$(COMPOSE) down' INT ; \
$(COMPOSE) up ; \
[[ $$? =~ 0|2 ]] || \
( echo 'You might want to run $(BOLD)make clean contrib$(NORMAL) if app dependencies have changed' && exit 1 )"
.PHONY: c
c: contrib
.PHONY: clean
clean:
@rm -fr deps _build assets/node_modules
define VERSION_CHECK
VERSION="$$($(CURL) --silent --location \
--write-out '$(NORMAL)HTTP/%{http_version} %{http_code} in %{time_total}s' \
http://$(HOSTNAME)/version.txt)" && \
echo $(BOLD)$(GIT_COMMIT)$$VERSION @ $$(date)
endef
.PHONY: check-deployed-version
check-deployed-version: GIT_COMMIT = $(GIT_REPOSITORY)/commit/
check-deployed-version: $(CURL) ## cdv | Check the currently deployed git sha
@$(VERSION_CHECK)
.PHONY: cdv
cdv: check-deployed-version
priv/db:
@mkdir -p priv/db
.PHONY: iaas
iaas: dnsimple-creds init validate apply
.PHONY: i
i: iaas
.PHONY: init
init: $(TERRAFORM)
@$(TF) init
.PHONY: validate
validate: $(TERRAFORM)
@$(TF) validate
.PHONY: plan
plan: $(TERRAFORM)
@$(TF) plan
.PHONY: apply
apply: $(TERRAFORM)
@$(TF) apply
CHANGELOG_SERVICES_SEPARATOR := ----------------------------------------------------------------------------------------
define CHANGELOG_SERVICES
$(BOLD)$(RED)Private$(NORMAL) $(BOLD)$(GREEN)Public$(NORMAL)
$(CHANGELOG_SERVICES_SEPARATOR)
| $(BOLD)$(RED)Fastly$(NORMAL) | https://manage.fastly.com/services/all |
$(CHANGELOG_SERVICES_SEPARATOR)
| $(BOLD)$(RED)Linode$(NORMAL) | https://cloud.linode.com/dashboard |
$(CHANGELOG_SERVICES_SEPARATOR)
| $(BOLD)$(RED)Pivotal Tracker$(NORMAL) | https://www.pivotaltracker.com/n/projects/1650121 |
$(CHANGELOG_SERVICES_SEPARATOR)
| $(BOLD)$(RED)Rollbar Dashboard$(NORMAL) | https://rollbar.com/changelogmedia/changelog.com/ |
| $(BOLD)$(RED)Rollbar Deploys$(NORMAL) | https://rollbar.com/changelogmedia/changelog.com/deploys/ |
$(CHANGELOG_SERVICES_SEPARATOR)
| $(BOLD)$(RED)Pingdom Uptime$(NORMAL) | https://my.pingdom.com/reports/uptime |
| $(BOLD)$(RED)Pingdom Page Speed$(NORMAL) | https://my.pingdom.com/reports/rbc |
| $(BOLD)$(RED)Pingdom Visitor Insights$(NORMAL) | https://my.pingdom.com/3/visitor-insights |
| $(BOLD)$(GREEN)Pingdom Status$(NORMAL) | http://status.changelog.com/ |
$(CHANGELOG_SERVICES_SEPARATOR)
| $(BOLD)$(GREEN)DockerHub$(NORMAL) | https://hub.docker.com/u/thechangelog |
$(CHANGELOG_SERVICES_SEPARATOR)
| $(BOLD)$(GREEN)CircleCI$(NORMAL) | https://app.circleci.com/pipelines/github/thechangelog |
$(CHANGELOG_SERVICES_SEPARATOR)
| $(BOLD)$(GREEN)GitHub$(NORMAL) | https://github.com/thechangelog/changelog.com |
$(CHANGELOG_SERVICES_SEPARATOR)
| $(BOLD)$(GREEN)Slack$(NORMAL) | https://changelog.slack.com/ |
$(CHANGELOG_SERVICES_SEPARATOR)
endef
export CHANGELOG_SERVICES
.PHONY: list-services
list-services: ## ls | List of all services used by changelog.com
@echo "$$CHANGELOG_SERVICES"
.PHONY: ls
ls: list-services
.PHONY: preview-readme
preview-readme: $(DOCKER) ## pre | Preview README & live reload on edit
@$(DOCKER) run --interactive --tty --rm --name changelog_md \
--volume $(CURDIR):/data \
--volume $(HOME)/.grip:/.grip \
--expose 5000 --publish 5000:5000 \
mbentley/grip --context=. 0.0.0.0:5000
.PHONY: pre
pre: preview-readme
.PHONY: test
test: $(COMPOSE) ## t | Run tests as they run on CircleCI
@$(COMPOSE) run --rm -e MIX_ENV=test -e DB_NAME=changelog_test app mix test
.PHONY: t
t: test
test_flakes:
@mkdir -p test_flakes
TEST_RUNS ?= 10
.PHONY: find-flaky-tests
find-flaky-tests: test_flakes
@for TEST_RUN_NO in {1..$(TEST_RUNS)}; do \
echo "RUNNING TEST $$TEST_RUN_NO ... " ; \
($(MAKE) --no-print-directory test >> test_flakes/$$TEST_RUN_NO && \
rm test_flakes/$$TEST_RUN_NO && \
echo -e "$(GREEN)PASS$(NORMAL)\n") || \
echo -e "$(RED)FAIL$(NORMAL)\n"; \
done
.PHONY: ssl-report
ssl-report: ## ssl | Run an SSL report via SSL Labs
@open "https://www.ssllabs.com/ssltest/analyze.html?d=$(HOSTNAME)&latest"
.PHONY: ssl
ssl: ssl-report