-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
169 lines (135 loc) · 5.03 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
.PHONY: run dev kill bash
DEFAULT_GOAL: help
export LOCAL_USER_ID ?= $(shell id -u $$USER)
WEB_SERVICE=app
DB_SERVICE=db
REDIS_SERVICE=redis
IMAGE_NAME=monorkin/blog
VERSION ?= $(shell ruby -r './config/version.rb' -e 'puts Blog::VERSION')
################################################################################
## DEVELOPMENT ##
################################################################################
## Starts all containers in the foreground
env:
@LOCAL_USER_ID=$(LOCAL_USER_ID) docker compose up
## Starts all containers in the foreground
update-env:
@LOCAL_USER_ID=$(LOCAL_USER_ID) docker compose up -d
## Stops all containers
kill-env:
@docker compose down
## Builds the development Docker image
build-env:
@docker compose build
## Starts a server
server: run_migrations
@bundle exec puma -C config/puma.rb
## Starts a development server
dev:
@./bin/dev
## Spawns an interactive Rails console in the web container
console:
@rails c
## Installs all required dependencies
bundle:
@bundle install --jobs `expr $$(nproc) - 1` --retry 3
## Spawns an interactive Bash shell in the web container
bash:
@if [ -z "$$ROOT" ]; then \
docker exec \
-u $(LOCAL_USER_ID) \
-it $$(docker compose ps -q $(WEB_SERVICE)) \
bash -c "reset -w && bash"; \
else \
docker exec \
-it $$(docker compose ps -q $(WEB_SERVICE)) \
bash; \
fi
## Run a command inside the docer container
run-command:
@docker exec \
-u $(LOCAL_USER_ID) \
-it $$(docker compose ps -q web) \
bash -c "reset -w && bash -c '$$COMMAND'"
## Reloads the currently running server
reload:
@touch ./tmp/restart.txt
## Toggles caching on or off
toggle-caching:
@rails dev:cache
## Disable Rack Mini Profiler ETag stripping
toggle-rack-mini-profiler-etag-stripping:
@if [ -f ./tmp/dev-disable-rack-mini-profiler-etag-stripping.txt ]; then \
rm ./tmp/dev-disable-rack-mini-profiler-etag-stripping.txt; \
else \
touch ./tmp/dev-disable-rack-mini-profiler-etag-stripping.txt; \
fi
@$(MAKE) reload
version:
@echo "$(VERSION)"
################################################################################
## TESTING ##
################################################################################
## Prepares and runs all tests in parallel
test: bundle
@echo "Check for security vulnerability"
@bundle exec brakeman -z
@echo "Running tests"
@bundle exec rails test:all
################################################################################
## DEPLOYMENT ##
################################################################################
server-logs:
ssh root@deploy.stanko.io "docker-compose logs --tail 100 -f stanko-io"
deploy:
$(MAKE) push-production-image \
&& ssh root@deploy.stanko.io "docker-compose pull stanko-io && docker-compose up -d"
list-images:
@docker image ls | grep $(IMAGE_NAME)
build-production-image:
@docker build . \
--target production \
-t $(IMAGE_NAME):latest \
-t $(IMAGE_NAME):$(VERSION)
push-production-image: build-production-image
@docker push $(IMAGE_NAME):$(VERSION)
@docker push $(IMAGE_NAME):latest
################################################################################
## REDIS ##
################################################################################
## Opens a redis-cli console
redis-cli:
@docker compose exec $(REDIS_SERVICE) redis-cli
################################################################################
## DATABASE ##
################################################################################
## Runs pending migrations and annotates models with the current DB schema
migrate: run_migrations annotate
## Undoes the previous migration, if possible, and annotates models with the current DB schema
rollback: rollback_migration annotate
## Runs the migrations
run_migrations:
@bundle exec rake db:migrate
## Undo the previous migration, if possible
rollback_migration:
@bundle exec rake db:rollback
## Adds annotation comments to the top of each model describing their DB schema
annotate:
@bundle exec annotate \
--models --show-migration --show-foreign-keys --show-indexes \
--classified-sort --with-comment
################################################################################
## HELP ##
################################################################################
## Shows the help menu
help:
@echo "Please use \`make <target>' where <target> is one of\n\n"
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf "%-30s %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)