Created
August 21, 2013 15:51
-
-
Save framallo/6296268 to your computer and use it in GitHub Desktop.
node js deployment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This is the deployment recipe | |
| # You require to install runit on the server. | |
| # 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=./nvm-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 | |
| setup_run: | |
| mkdir -p $(service_dir) | |
| echo "#!/bin/bash" > $(run) | |
| echo "export HOME=$(HOME)" >> $(run) | |
| echo "cd $(app_dir)" >> $(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 '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 | |
| ## node | |
| export NODE_ENV = $(shell git branch | grep '*' | awk '{print $$(2)}' ) | |
| setup: | |
| source $(HOME)/.nvm/nvm.sh | |
| npm_install: | |
| npm install -d | |
| all: deploy | |
| deploy: npm_install restart | |
| # application specific | |
| service_run: | |
| exec node app.js | |
| restart: | |
| sv restart $(service_name) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| source $HOME/.nvm/nvm.sh | |
| nvm use 0.11.2 > /dev/null | |
| exec /bin/bash --norc "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment