-
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathMakefile
More file actions
154 lines (121 loc) · 6.14 KB
/
Copy pathMakefile
File metadata and controls
154 lines (121 loc) · 6.14 KB
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
.PHONY: all clean deploy help lint \
production-deploy production-provision provision \
roles services-down services-up \
staging-anible staging-deploy staging-provision \
share-web test up vagrant-plugins venv \
all-tests quick-tests
VENV := .venv/bin
SHELL := /bin/bash
PYTHON_VERSION := $(shell cat .python-version 2>/dev/null || echo "python3")
# So inventory uses .venv
export PATH := $(CURDIR)/$(VENV):$(PATH)
all: help
venv: .venv/bin/activate
.venv/bin/activate: provisioning/requirements.txt
test -d .venv || virtualenv -p $(PYTHON_VERSION) .venv
${VENV}/pip install --upgrade pip
${VENV}/pip install -Ur provisioning/requirements.txt
touch .venv/bin/activate
roles: provisioning/.roles-installed
provisioning/.roles-installed: venv provisioning/requirements.yml
${VENV}/ansible-galaxy install -r provisioning/requirements.yml -p provisioning/roles
touch provisioning/.roles-installed
ANSIBLE_TAGS := $(shell echo "$(TAGS)" | sed 's/[^A-Z0-9_]\+/,/gi' | sed 's/,\+/,/g' | sed 's/^,//' | sed 's/,$$//')
ANSIBLE_SKIP_TAGS := $(shell echo "$(SKIP_TAGS)" | sed 's/[^A-Z0-9_]\+/,/gi' | sed 's/,\+/,/g' | sed 's/^,//' | sed 's/,$$//')
ANSIBLE_START_TASK := $(if $(START_AT_TASK),*$(shell echo "$(START_AT_TASK)" | sed 's/[^A-Z0-9_]\+/*/gi')*,)
# Build ansible-playbook options just like Vagrantfile
ANSIBLE_OPTS :=
ifdef ANSIBLE_TAGS
ANSIBLE_OPTS += --tags "$(ANSIBLE_TAGS)"
$(info INFO: Only running TAGS: $(ANSIBLE_TAGS))
endif
ifdef ANSIBLE_SKIP_TAGS
ANSIBLE_OPTS += --skip-tags "$(ANSIBLE_SKIP_TAGS)"
$(info INFO: Skipping TAGS: $(ANSIBLE_SKIP_TAGS))
endif
ifdef ANSIBLE_VERBOSE
ANSIBLE_OPTS += -$(ANSIBLE_VERBOSE)
$(info INFO: Setting verbose: -$(ANSIBLE_VERBOSE))
endif
ifdef ANSIBLE_START_TASK
ANSIBLE_OPTS += --start-at-task "$(ANSIBLE_START_TASK)"
$(info INFO: Starting at task matching: $(ANSIBLE_START_TASK))
endif
help: ## This help dialog.
@IFS=$$'\n' ; \
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##/:/'`); \
printf "%-30s %s\n" "Target" "Description" ; \
printf "%-30s %s\n" "------" "-----------" ; \
for help_line in $${help_lines[@]}; do \
IFS=$$':' ; \
help_split=($$help_line) ; \
help_command=`echo $${help_split[0]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
help_info=`echo $${help_split[2]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
printf '\033[36m'; \
printf "%-30s %s" $$help_command ; \
printf '\033[0m'; \
printf "%s\n" $$help_info; \
done
# Ensure required Vagrant plugins are installed
vagrant-plugins:
@installed_plugins=$$(vagrant plugin list); \
for plugin in vagrant-hostsupdater vagrant-disksize vagrant-vbguest; do \
if echo "$$installed_plugins" | grep -q $$plugin; then \
[ "$(MAKECMDGOALS)" != "vagrant-plugins" ] || echo "$$plugin plugin is already installed"; \
else \
vagrant plugin install $$plugin; \
fi; \
done
vagrant-up: venv roles vagrant-plugins ## launch local vagrant VM
vagrant up local
vagrant-provision: venv roles vagrant-plugins ## Provision local vagrant VM using ansible
vagrant provision local
staging-provision: venv roles ## Provision staging using ansible
${VENV}/ansible-playbook --user=root $(ANSIBLE_OPTS) --inventory-file=provisioning/inventory/staging.py provisioning/playbook.yml
production-provision: venv roles ## Provision production using ansible
${VENV}/ansible-playbook --user=root $(ANSIBLE_OPTS) --inventory-file=provisioning/inventory/production provisioning/playbook.yml
vagrant-deploy: ## Deploy app to local vagrant VM
bundle exec cap local deploy
staging-deploy: ## Deploy app to staging
bundle exec cap staging deploy
production-deploy: ## Deploy app to production
bundle exec cap production deploy
docker-up: ## Full Docker environment including ruby containers (persistent data) BETA
docker compose -f docker-compose.yml -f docker_images/persistent_services.yaml up
# Run up services required for CI (no persistence)
ci-services-up:
COMPOSE_PROJECT_NAME=morph-services docker compose -f docker_images/services.yaml up --build -d redis elasticsearch
services-up: ## Run up services with persistent data (use SERVICES="redis elasticsearch" to exclude mysql)
COMPOSE_PROJECT_NAME=morph-services docker compose -f docker_images/services.yaml -f docker_images/persistent_services.yaml up --build -d $${SERVICES}
services-down: ## Close down services required for CI / development
COMPOSE_PROJECT_NAME=morph-services docker compose -f docker_images/services.yaml down --remove-orphans
services-logs: ## View logs for services (use SERVICES=elasticsearch for specific service)
COMPOSE_PROJECT_NAME=morph-services docker compose -f docker_images/services.yaml logs $${SERVICES}
services-status: ## Check status of services
COMPOSE_PROJECT_NAME=morph-services docker compose -f docker_images/services.yaml ps
rspec: ## Run all rspec tests (Optionally add DONT_RUN_SLOW_TESTS=1 or DONT_RUN_DOCKER_TESTS=1 or DONT_RUN_GITHUB_TESTS=1)
RAILS_ENV=test bundle exec rspec
test: quick-tests all-tests ## Run quick test then everything for a full coverage/index.html report
quick-tests: ## Run quick rspec tests (excludes slow, docker and github tests)
DONT_RUN_GITHUB_TESTS=1 DONT_RUN_DOCKER_TESTS=1 bundle exec rake
echo "Passed quick tests!"
ci-tests: ## Run the same rspec tests as CI (slow but not docker nor github app tests)
DONT_RUN_DOCKER_TESTS=1 RUN_SLOW_TESTS=1 DONT_RUN_GITHUB_TESTS=1 bundle exec rake
echo "Passed CI tests!"
all-tests: ## Run all rspec tests
RUN_SLOW_TESTS=1 bundle exec rake
echo "Passed all tests!"
lint: ## Lint code
bundle exec rubocop
bundle exec haml-lint
clean: ## Clean out venv, installed roles and rails tmp/cache
[ -f provisioning/requirements.yml ] && $(VENV)/ansible-galaxy remove -r provisioning/requirements.yml -p provisioning/roles || true
rm -rf .venv provisioning/.roles-installed tmp/cache
clobber: clean ## Remove everything including logs
rm -f log/*.log
docker-clean: services-down ## Remove all Docker resources INCLUDING databases in volumes
docker system prune -af --volumes
share-web: ## Share web server on port 3000 to the internet (use PORT=N to use an alternative port)
ngrok http $${PORT:-3000}
mailcatcher: ## run mailcatcher to catch development emails
bundle exec mailcatcher