forked from thechangelog/changelog.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
638 lines (552 loc) Β· 23.3 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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
SHELL := bash# we want bash behaviour in all shell invocations
PLATFORM := $(shell uname)
MAKEFILE := $(firstword $(MAKEFILE_LIST))
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')
DOMAIN ?= changelog.com
DOCKER_STACK ?= 201910
DOCKER_STACK_FILE ?= docker/$(DOCKER_STACK).stack.yml
HOST ?= $(DOCKER_STACK)i.$(DOMAIN)
HOST_SSH_USER ?= core
HOSTNAME := $(DOCKER_STACK).$(DOMAIN)
HOSTNAME_LOCAL := changelog.localhost
GIT_REPOSITORY ?= https://github.com/thechangelog/changelog.com
GIT_BRANCH ?= master
export FQDN IPv4
### DEPS ###
#
DOCKER_DARWIN := /usr/local/bin/docker
ifeq ($(PLATFORM),Darwin)
DOCKER ?= $(DOCKER_DARWIN)
COMPOSE ?= $(DOCKER)-compose
$(DOCKER) $(COMPOSE):
@brew cask install docker
endif
DOCKER_LINUX := /usr/bin/docker
ifeq ($(PLATFORM),Linux)
DOCKER ?= $(DOCKER_LINUX)
$(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/opt/terraform@0.11/bin/terraform
$(TERRAFORM):
ifeq ($(PLATFORM),Darwin)
@brew install terraform@0.11
endif
ifeq ($(PLATFORM),Linux)
$(error $(RED)Please install $(BOLD)terraform v0.11$(NORMAL) in $(TERRAFORM): https://www.terraform.io/downloads.html)
endif
ifeq ($(PLATFORM),Darwin)
OPENSSL := /usr/local/opt/openssl/bin/openssl
$(OPENSSL):
@brew install openssl
endif
ifeq ($(PLATFORM),Linux)
OPENSSL := /usr/bin/openssl
$(OPENSSL):
@sudo apt-get update && sudo apt-get install openssl
endif
ifeq ($(PLATFORM),Darwin)
WATCH := /usr/local/bin/watch
$(WATCH):
@brew install watch
endif
ifeq ($(PLATFORM),Linux)
WATCH := /usr/bin/watch
endif
BATS := /usr/local/bin/bats
$(BATS):
ifeq ($(PLATFORM),Darwin)
@brew install bats-core
endif
ifeq ($(PLATFORM),Linux)
$(error $(RED)Please install $(BOLD)bats-core$(NORMAL) in $(BATS): https://github.com/bats-core/bats-core#installation)
endif
SECRETS := $(LPASS) ls "Shared-changelog/secrets"
TF := cd terraform && $(TERRAFORM)
TF_VAR := export TF_VAR_ssl_key="$$(lpass show --notes 8038492725192048930)" && export TF_VAR_ssl_cert="$$(lpass show --notes 7748004306557989540 && cat terraform/dhparams.pem)"
# Enable Terraform debugging if make runs in debug mode
ifneq (,$(findstring d,$(MFLAGS)))
TF_LOG ?= debug
export TF_LOG
endif
### TARGETS ###
#
.DEFAULT_GOAL := help
include mk/inspect.mk
include mk/images.mk
MIGRATE_FROM := core@2019i.changelog.com
include mk/migrate.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) --color $(MAKE) --makefile $(MAKEFILE) ac
.PHONY: $(HOST)
$(HOST): iaas create-docker-secrets bootstrap-docker
define BOOTSTRAP_CONTAINER
docker pull thechangelog/bootstrap:$(DOCKER_STACK) && \
docker run --rm --interactive --tty --name bootstrap \
--env HOSTNAME=\$$HOSTNAME \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
--volume changelog.com:/app:rw \
$(BOOTSTRAP_RUN)
endef
BOOTSTRAP_RUN ?= thechangelog/bootstrap:$(DOCKER_STACK)
define DISABLE_APP_UPDATER
docker service scale $(DOCKER_STACK)_app_updater=0
endef
.PHONY: bootstrap-docker
bootstrap-docker:
@ssh -t $(HOST_SSH_USER)@$(HOST) "$(DISABLE_APP_UPDATER) ; $(BOOTSTRAP_CONTAINER)"
.PHONY: bd
bd: bootstrap-docker
.PHONY: interactive-bootstrap
interactive-bootstrap: BOOTSTRAP_RUN = --entrypoint /bin/bash thechangelog/bootstrap:$(DOCKER_STACK) --login
interactive-bootstrap:
@ssh -t $(HOST_SSH_USER)@$(HOST) "$(BOOTSTRAP_CONTAINER)"
.PHONY: ib
ib: interactive-bootstrap
.PHONY: add-secret
add-secret: $(LPASS) ## as | Add secret to LastPass
ifndef SECRET
@echo "$(RED)SECRET$(NORMAL) environment variable must be set to the name of the secret that will be added" && \
echo "This value must be in upper-case, e.g. $(BOLD)SOME_SECRET$(NORMAL)" && \
echo "This value must not match any of the existing secrets:" && \
$(SECRETS) && \
exit 1
endif
@$(LPASS) add --notes "Shared-changelog/secrets/$(SECRET)"
.PHONY: as
as: add-secret
.PHONY: prevent-incompatible-deps-reaching-the-docker-image
prevent-incompatible-deps-reaching-the-docker-image:
@rm -fr deps
.PHONY: create-dirs-mounted-as-volumes
create-dirs-mounted-as-volumes:
@mkdir -p $(CURDIR)/priv/{uploads,db}
.PHONY: build
build: $(COMPOSE) prevent-incompatible-deps-reaching-the-docker-image ## b | Build changelog.com app container
@$(COMPOSE) build
.PHONY: b
b: build
.PHONY: build-test
build-test: $(COMPOSE) prevent-incompatible-deps-reaching-the-docker-image ## bt | Build Docker image required to run tests locally
@$(COMPOSE) run --rm -e MIX_ENV=test -e DB_URL=ecto://postgres@db:5432/changelog_test app mix do deps.get, compile, ecto.create
.PHONY: bt
bt: build-test
.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) --color $(MAKE) --makefile $(MAKEFILE) help
.PHONY: clean-docker
clean-docker: $(DOCKER) $(COMPOSE) ## cd | Remove all changelog containers, images & volumes
@$(COMPOSE) stop && \
$(DOCKER) stack rm $(DOCKER_STACK) && \
$(DOCKER) system prune && \
$(DOCKER) volume prune && \
$(DOCKER) volume ls | awk '/changelog|$(DOCKER_STACK)/ { system("$(DOCKER) volume rm " $$2) }' ; \
$(DOCKER) image ls | awk '/changelog|$(DOCKER_STACK)/ { system("$(DOCKER) image rm " $$1 ":" $$2) }' ; \
$(DOCKER) config ls | awk '/changelog|$(DOCKER_STACK)/ { system("$(DOCKER) config rm " $$2) }'
.PHONY: cd
cd: clean-docker
CIRCLE_CI_ADD_ENV_VAR_URL = https://circleci.com/api/v1.1/project/github/thechangelog/changelog.com/envvar?circle-token=$(CIRCLE_TOKEN)
.PHONY: configure-ci-secrets
configure-ci-secrets: configure-ci-docker-secret configure-ci-coveralls-secret ## ccs | Configure CircleCI secrets
.PHONY: ccs
ccs: configure-ci-secrets
.PHONY: configure-ci-docker-secret
configure-ci-docker-secret: $(LPASS) $(JQ) $(CURL) circle-token
@DOCKER_CREDENTIALS=$$($(LPASS) show --json 2219952586317097429) && \
DOCKER_USER="$$($(JQ) --compact-output '.[] | {name: "DOCKER_USER", value: .username}' <<< $$DOCKER_CREDENTIALS)" && \
DOCKER_PASS="$$($(JQ) --compact-output '.[] | {name: "DOCKER_PASS", value: .password}' <<< $$DOCKER_CREDENTIALS)" && \
$(CURL) --silent --fail --request POST --header "Content-Type: application/json" -d "$$DOCKER_USER" "$(CIRCLE_CI_ADD_ENV_VAR_URL)" && \
$(CURL) --silent --fail --request POST --header "Content-Type: application/json" -d "$$DOCKER_PASS" "$(CIRCLE_CI_ADD_ENV_VAR_URL)"
.PHONY: ccds
ccds: configure-ci-docker-secret
.PHONY: configure-ci-coveralls-secret
configure-ci-coveralls-secret: $(LPASS) $(JQ) $(CURL) circle-token
@COVERALLS_TOKEN='{"name":"COVERALLS_REPO_TOKEN", "value":"'$$($(LPASS) show --notes 8654919576068551356)'"}' && \
$(CURL) --silent --fail --request POST --header "Content-Type: application/json" -d "$$COVERALLS_TOKEN" "$(CIRCLE_CI_ADD_ENV_VAR_URL)"
.PHONY: cccs
.PHONY: cccs
cccs: configure-ci-coveralls-secret
.PHONY: contrib
contrib: $(COMPOSE) prevent-incompatible-deps-reaching-the-docker-image 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 build contrib$(NORMAL) if app dependencies have changed' && exit 1 )"
.PHONY: c
c: contrib
.PHONY: create-docker-secrets
create-docker-secrets: $(LPASS) ## cds | Create Docker secrets
@$(SECRETS) | \
awk '! /secrets\/? / { print($$1) }' | \
while read -r secret ; do \
export secret_key="$$($(LPASS) show --name $$secret)" ; \
export secret_value="$$($(LPASS) show --notes $$secret)" ; \
echo "Creating $(BOLD)$(YELLOW)$$secret_key$(NORMAL) secret on $(HOST)..." ; \
echo "Prevent ssh from hijacking stdin: https://github.com/koalaman/shellcheck/wiki/SC2095" > /dev/null ; \
if [ $(HOST) = localhost ] ; then \
echo $$secret_value | docker secret create $$secret_key - || true ; \
else \
ssh $(HOST_SSH_USER)@$(HOST) "echo $$secret_value | docker secret create $$secret_key - || true" < /dev/null || exit 1 ; \
fi \
done && \
echo "$(BOLD)$(GREEN)All secrets are now setup as Docker secrets$(NORMAL)" && \
echo "A Docker secret cannot be modified - it can only be removed and created again, with a different value" && \
echo "A Docker secret can only be removed if it is not bound to a Docker service" && \
echo "It might be easier to define a new secret, e.g. $(BOLD)ALGOLIA_API_KEY2$(NORMAL)"
.PHONY: cds
cds: create-docker-secrets
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
.PHONY: check-deployed-version-local
check-deployed-version-local: HOSTNAME = $(HOSTNAME_LOCAL)
check-deployed-version-local: $(CURL)
@$(VERSION_CHECK)
.PHONY: cdvl
cdvl: check-deployed-version-local
.PHONY: remove-docker-secrets
remove-docker-secrets: $(LPASS)
@if [ $(HOST) = localhost ] ; then \
docker secret ls | awk '/ago/ { system("docker secret rm " $$1) }' ; \
else \
ssh $(HOST_SSH_USER)@$(HOST) "docker secret ls | awk '/ago/ { system(\"docker secret rm \" \$$1) }'" ; \
fi
.PHONY: rds
rds: remove-docker-secrets
.PHONY: deploy-docker-stack
deploy-docker-stack: $(DOCKER) ## dds | Deploy the changelog.com Docker Stack
@export HOSTNAME ; \
$(DOCKER) service scale $(DOCKER_STACK)_app_updater=0 ; \
$(DOCKER) stack deploy --compose-file $(DOCKER_STACK_FILE) --prune $(DOCKER_STACK)
.PHONY: dds
dds: deploy-docker-stack
priv/db:
@mkdir -p priv/db
.PHONY: deploy-docker-stack-local
deploy-docker-stack-local: DOCKER_STACK_FILE = docker/local.stack.yml
deploy-docker-stack-local: deploy-docker-stack priv/db
.PHONY: ddsl
ddsl: deploy-docker-stack-local
.PHONY: update-app-service-local
update-app-service-local: $(DOCKER)
@$(DOCKER) service update --force --image thechangelog/changelog.com:local --update-monitor 10s $(DOCKER_STACK)_app
.PHONY: uasl
uasl: update-app-service-local
.PHONY: env-secrets
env-secrets: postgres campaignmonitor github aws backups_aws twitter app slack rollbar buffer coveralls algolia ## es | Print secrets stored in LastPass as env vars
.PHONY: es
es: env-secrets
.PHONY: iaas
iaas: linode-token dnsimple-creds terraform/dhparams.pem init validate apply ## i | Provision IaaS infrastructure
.PHONY: i
i: iaas
# https://www.linode.com/docs/platform/nodebalancer/nodebalancer-reference-guide/#diffie-hellman-parameters
terraform/dhparams.pem: $(OPENSSL)
@$(OPENSSL) dhparam -out terraform/dhparams.pem 2048
.PHONY: init
init: $(TERRAFORM)
@$(TF) init
.PHONY: validate
validate: $(TERRAFORM)
@$(TF_VAR) && $(TF) validate
.PHONY: plan
plan: $(TERRAFORM)
@$(TF_VAR) && $(TF) plan
.PHONY: apply
apply: $(TERRAFORM)
@$(TF_VAR) && $(TF) apply
.PHONY: legacy-assets
legacy-assets: $(DOCKER)
@echo "$(YELLOW)This is a secret target that is only meant to be executed if legacy assets are present locally$(NORMAL)" && \
echo "$(YELLOW)If this runs with an incorrect $(BOLD)./nginx/www/wp-content$(NORMAL)$(YELLOW), the resulting Docker image will miss relevant files$(NORMAL)" && \
read -rp "Are you sure that you want to continue? (y|n) " -n 1 && ([[ $$REPLY =~ ^[Yy]$$ ]] || exit) && \
cd nginx && $(DOCKER) build --tag thechangelog/legacy_assets --file Dockerfile.legacy_assets . && \
$(DOCKER) push thechangelog/legacy_assets
CHANGELOG_SERVICES_SEPARATOR := ----------------------------------------------------------------------------------------
define CHANGELOG_SERVICES
$(BOLD)$(RED)Private$(NORMAL) $(BOLD)$(GREEN)Public$(NORMAL)
$(CHANGELOG_SERVICES_SEPARATOR)
| $(BOLD)$(RED)Papertrail$(NORMAL) | https://papertrailapp.com/dashboard |
$(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)Netdata$(NORMAL) | http://netdata.changelog.com |
$(CHANGELOG_SERVICES_SEPARATOR)
| $(BOLD)$(GREEN)DockerHub$(NORMAL) | https://hub.docker.com/u/thechangelog |
$(CHANGELOG_SERVICES_SEPARATOR)
| $(BOLD)$(GREEN)CircleCI$(NORMAL) | https://circleci.com/gh/thechangelog/changelog.com |
$(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: e2e
e2e: $(BATS) $(CURL)
.PHONY: proxy-test
proxy-test: FQDN = $(DOMAIN)
proxy-test: IPv4 = 69.164.223.133
proxy-test: e2e
@cd test/e2e && \
$(BATS) proxy.bats proxy.prod.bats
.PHONY: pt
pt: proxy-test
.PHONY: proxy-test-local
proxy-test-local: FQDN = $(HOSTNAME_LOCAL)
proxy-test-local: IPv4 = 127.0.0.1
proxy-test-local: e2e
@cd test/e2e && \
$(BATS) proxy.bats proxy.local.bats
.PHONY: ptl
ptl: proxy-test-local
.PHONY: report-deploy
report-deploy: report-deploy-slack report-deploy-rollbar
.PHONY: report-deploy-rollbar
report-deploy-rollbar: $(CURL)
@ROLLBAR_ACCESS_TOKEN="$$(cat /run/secrets/ROLLBAR_ACCESS_TOKEN)" && export ROLLBAR_ACCESS_TOKEN && \
COMMIT_USER="$$(cat ./COMMIT_USER)" && export COMMIT_USER && \
COMMIT_SHA="$$(cat ./COMMIT_SHA)" && export COMMIT_SHA && \
$(CURL) --silent --fail --output /dev/null --request POST --url https://api.rollbar.com/api/1/deploy/ \
--data '{"access_token":"'$$ROLLBAR_ACCESS_TOKEN'","environment":"'$$ROLLBAR_ENVIRONMENT'","rollbar_username":"'$$COMMIT_USER'","revision":"'$$COMMIT_SHA'","comment":"Running in container '$$HOSTNAME' on host '$$NODE'"}'
.PHONY: report-deploy-slack
report-deploy-slack: $(CURL)
@SLACK_DEPLOY_WEBHOOK="$$(cat /run/secrets/SLACK_DEPLOY_WEBHOOK)" && export SLACK_DEPLOY_WEBHOOK && \
COMMIT_USER="$$(cat ./COMMIT_USER)" && export COMMIT_USER && \
COMMIT_SHA="$$(cat ./COMMIT_SHA)" && export COMMIT_SHA && \
$(CURL) --silent --fail --output /dev/null --request POST --url $$SLACK_DEPLOY_WEBHOOK \
--header 'Content-type: application/json' \
--data '{"text":"<$(GIT_REPOSITORY)/commit/'$$COMMIT_SHA'|'$${COMMIT_SHA:0:7}'> by <$(GIT_REPOSITORY)/commits?author='$$COMMIT_USER'|'$$COMMIT_USER'> just started, it will be promoted to live when healthy. <$(GIT_REPOSITORY)/blob/master/docker/$(DOCKER_STACK).stack.yml|$(DOCKER_STACK).stack>"}'
.PHONY: rsync-small-uploads-local
rsync-small-uploads-local: create-dirs-mounted-as-volumes
@rsync --archive --delete --update --inplace --verbose --progress --human-readable \
"$(HOST_SSH_USER)@$(HOST):/uploads/{avatars,covers,icons,logos}" $(CURDIR)/priv/uploads/
.PHONY: rsul
rsul: rsync-small-uploads-local
.PHONY: secrets
secrets: $(LPASS) ## s | List all LastPass secrets
@$(SECRETS)
.PHONY: s
s: secrets
.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
.PHONY: test
test: $(COMPOSE) ## t | Run tests as they run on CircleCI
@$(COMPOSE) run --rm -e MIX_ENV=test -e DB_URL=ecto://postgres@db:5432/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
define UPDATE_NETDATA
docker pull netdata/netdata && \
docker service update --force --image netdata/netdata $(DOCKER_STACK)_netdata
endef
.PHONY: update_netdata
update_netdata:
@ssh -t $(HOST_SSH_USER)@$(HOST) "$(UPDATE_NETDATA)"
define DIRENV
We like $(BOLD)https://direnv.net/$(NORMAL) to manage environment variables.
This is an $(BOLD).envrc$(NORMAL) template that you can use as a starting point:
PATH_add script
export CIRCLE_TOKEN=
export TF_VAR_linode_token=
export DNSIMPLE_ACCOUNT=
export DNSIMPLE_TOKEN=
endef
export DIRENV
.PHONY: circle-token
circle-token:
ifndef CIRCLE_TOKEN
@echo "$(RED)CIRCLE_TOKEN$(NORMAL) environment variable must be set\n" && \
echo "Learn more about CircleCI API tokens $(BOLD)https://circleci.com/docs/2.0/managing-api-tokens/$(NORMAL) " && \
echo "$$DIRENV" && \
exit 1
endif
.PHONY: linode-token
linode-token:
ifndef TF_VAR_linode_token
@echo "$(RED)TF_VAR_linode_token$(NORMAL) environment variable must be set" && \
echo "Learn more about Linode API tokens $(BOLD)https://cloud.linode.com/profile/tokens$(NORMAL) " && \
echo "$$DIRENV" && \
exit 1
endif
.PHONY: dnsimple-creds
dnsimple-creds:
ifndef DNSIMPLE_ACCOUNT
@echo "$(RED)DNSIMPLE_ACCOUNT$(NORMAL) environment variable must be set" && \
echo "This will be the account's numerical ID, e.g. $(BOLD)00000$(NORMAL)" && \
echo "$$DIRENV" && \
exit 1
endif
ifndef DNSIMPLE_TOKEN
@echo "$(RED)DNSIMPLE_TOKEN$(NORMAL) environment variable must be set" && \
echo "Get a DNSimple user access token $(BOLD)https://dnsimple.com/user?account_id=$(DNSIMPLE_ACCOUNT)$(NORMAL) " && \
echo "$$DIRENV" && \
exit 1
endif
.PHONY: sync-secrets
sync-secrets: $(LPASS)
@$(LPASS) sync
.PHONY: postgres
postgres: $(LPASS)
@echo "export PG_DOTCOM_PASS=$$($(LPASS) show --notes 7298637973371173308)"
.PHONY: campaignmonitor
campaignmonitor: $(LPASS)
@echo "export CM_SMTP_TOKEN=$$($(LPASS) show --notes 4518157498237793892)" && \
echo "export CM_API_TOKEN=$$($(LPASS) show --notes 2172742429466797248)"
.PHONY: github
github: $(LPASS)
@echo "export GITHUB_CLIENT_ID=$$($(LPASS) show --notes 6311620502443842879)" && \
echo "export GITHUB_CLIENT_SECRET=$$($(LPASS) show --notes 6962532309857955032)" && \
echo "export GITHUB_API_TOKEN=$$($(LPASS) show --notes Shared-changelog/secrets/GITHUB_API_TOKEN2)"
.PHONY: aws
aws: $(LPASS)
@echo "export AWS_ACCESS_KEY_ID=$$($(LPASS) show --notes 5523519094417729320)" && \
echo "export AWS_SECRET_ACCESS_KEY=$$($(LPASS) show --notes 1520570655547620905)"
.PHONY: backups_aws
backups_aws: $(LPASS)
@echo "export BACKUPS_AWS_ACCESS_KEY=$$($(LPASS) show --notes 2383382642830769087)" && \
echo "export BACKUPS_AWS_SECRET_KEY=$$($(LPASS) show --notes 4892015361959119196)"
.PHONY: twitter
twitter: $(LPASS)
@echo "export TWITTER_CONSUMER_KEY=$$($(LPASS) show --notes 1932439368993537002)" && \
echo "export TWITTER_CONSUMER_SECRET=$$($(LPASS) show --notes 5671723614506961548)"
.PHONY: app
app: $(LPASS)
@echo "export SECRET_KEY_BASE=$$($(LPASS) show --notes 7272253808960291967)" && \
echo "export SIGNING_SALT=$$($(LPASS) show --notes 8954230056631744101)"
.PHONY: slack
slack: $(LPASS)
@echo "export SLACK_INVITE_API_TOKEN=$$($(LPASS) show --notes 3107315517561229870)" && \
echo "export SLACK_APP_API_TOKEN=$$($(LPASS) show --notes 1152178239154303913)"
.PHONY: rollbar
rollbar: $(LPASS)
@echo "export ROLLBAR_ACCESS_TOKEN=$$($(LPASS) show --notes 5433360937426957091)"
.PHONY: buffer
buffer: $(LPASS)
@echo "export BUFFER_TOKEN=$$($(LPASS) show --notes Shared-changelog/secrets/BUFFER_TOKEN_2)"
.PHONY: coveralls
coveralls: $(LPASS)
@echo "export COVERALLS_REPO_TOKEN=$$($(LPASS) show --notes 8654919576068551356)"
.PHONY: algolia
algolia: $(LPASS)
@echo "export ALGOLIA_APPLICATION_ID=$$($(LPASS) show --notes 5418916921816895235)" && \
echo "export ALGOLIA_API_KEY=$$($(LPASS) show --notes 1668162557359149736)"