-
Notifications
You must be signed in to change notification settings - Fork 3
/
makefile
103 lines (85 loc) · 2.63 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
# This is the deployment recipe
# You require to install runit on the server.
# First you need to declare on which port the application will run
#
# echo 3000 > port
#
# Then you can setup a new runit service with
#
# make setup_service
#
# Also you need to install the git hooks, so you can push and update this repo
#
# make setup_git_hook
#
# Every time you push it will run
#
# make deploy
#
# Later you can test the application
#
# make service_run
#
# Last you can restart the application
#
# make restart
#
SHELL=/usr/local/rvm/bin/rvm-shell
## service
service_name = $(shell basename $(realpath .) )
app_dir = $(realpath .)
service_dir = $(HOME)/service/$(service_name)
run = $(service_dir)/run
log_dir = $(service_dir)/log
log = $(log_dir)/run
port = $(shell cat port)
setup_run:
mkdir -p $(service_dir)
echo "#!/bin/bash" > $(run)
echo "cd $(app_dir)" >> $(run)
echo "export HOME=$$(HOME)" >> $(run)
echo "exec chpst -u $(shell whoami) make service_run" >> $(run)
chmod +x $(run)
setup_log:
mkdir -p $(log_dir)
echo "#!/bin/bash" > $(log)
echo "exec chpst -u $(shell whoami) svlogd -tt $(app_dir)/log/" >> $(log)
chmod +x $(log)
setup_service: setup_run setup_log
@echo ""
@echo " You created a new runit service that will keep the application runinnig after a reboot"
@echo " also it will create a log on log folder"
@echo " just, one last step: run as sudo"
@echo " cp -r $(service_dir) /etc/service/"
@echo " chown $(shell whoami) /etc/service/$(service_name)/supervise/ "
@echo " chown $(shell whoami) /etc/service/$(service_name)/supervise/ok "
@echo " chown $(shell whoami) /etc/service/$(service_name)/supervise/control "
@echo " chown $(shell whoami) /etc/service/$(service_name)/supervise/status"
@echo ""
service_run:
## git hook
hook = .git/hooks/post-receive
setup_git_hook:
echo 'unset GIT_DIR'
echo 'cd .. && GIT_DIR=$$(pwd) && make git_hook deploy' > $(hook)
chmod +x $(hook)
git_hook:
env -i git reset --hard
env -i git submodule init
env -i git submodule update
## rails
export RAILS_ENV = $(shell git branch | grep '*' | awk '{print $$(2)}' )
bundle_install:
bundle install --without=development --without=test --deployment
migrate:
bundle exec rake db:migrate
precompile:
bundle exec rake assets:clean assets:precompile
all: deploy
deploy: bundle_install migrate precompile restart
# application specific
service_run:
mkdir -p tmp/pids tmp/logs
exec bundle exec puma -e $(RAILS_ENV) -p $(port)
restart:
sv restart $(service_name)