-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from dduk-ddak/issue_80
Issue #80
- Loading branch information
Showing
10 changed files
with
226 additions
and
108 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,4 +101,6 @@ collected_static/ | |
# For hide SECRET_KEY | ||
secret.json | ||
pw.txt | ||
nginx/local_nginx.conf | ||
.prepared | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,22 @@ | ||
default: start | ||
OS := $(shell uname) | ||
|
||
sudo: | ||
sudo -v | ||
default: start | ||
.PHONY: start stop uninstall | ||
|
||
start: prepare sudo | ||
sudo service redis-server start | ||
python3 manage.py runworker & | ||
daphne -b 0.0.0.0 -p 8001 coding_night_live.asgi:channel_layer & | ||
sudo service nginx start # FIXME | ||
|
||
db.sqlite3: | ||
python3 manage.py migrate | ||
include Makefile.deps | ||
include Makefile.prepare | ||
|
||
pw.txt: db.sqlite3 | ||
python3 manage.py createsuperuserauto | ||
|
||
collected_static/: | ||
yes yes | python3 manage.py collectstatic | ||
start: \.prepared deps-start | ||
python3 manage.py runworker & | ||
daphne -b 0.0.0.0 -p 8001 coding_night_live.asgi:channel_layer & | ||
|
||
secret.json: db.sqlite3 | ||
python3 manage.py autodeploy | ||
|
||
prepare: deps-install db.sqlite3 pw.txt collected_static/ secret.json | ||
stop: deps-stop | ||
-killall -9 daphne | ||
-killall -9 python3 | ||
-killall -9 python # FIXME: daphne at MAC OS | ||
|
||
|
||
OS := $(shell uname) | ||
deps-install: | ||
ifeq ($(OS),Linux) | ||
sudo apt-get install redis-server | ||
sudo apt-get install nginx | ||
else | ||
echo 'ACITON REQUIRED) Need to install redis and nginx before this.' | ||
endif | ||
|
||
stop: sudo | ||
-sudo service nginx stop | ||
-sudo killall -9 daphne # FIXME | ||
-sudo killall -9 python3 # FIXME | ||
-sudo service redis-server stop | ||
|
||
clean: | ||
-rm secret.json db.sqlite3 | ||
-rm -r collected_static | ||
|
||
uninstall: stop clean | ||
uninstall: stop clean deps-uninstall |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
.PHONY: sudo deps-install deps-uninstall deps-start deps-stop prepare-nginx | ||
|
||
|
||
sudo: | ||
sudo -v | ||
|
||
|
||
deps-install: sudo | ||
ifeq ($(OS),Linux) | ||
sudo apt-get install redis-server | ||
sudo apt-get install nginx | ||
else ifeq ($(OS),Darwin) | ||
brew list redis > /dev/null || brew install redis --build-from-source # FIXME: Homebrew/homebrew-core#11134 | ||
brew list nginx > /dev/null || brew install nginx | ||
else | ||
echo 'ACITON REQUIRED) Need to install redis and nginx before this.' | ||
endif | ||
|
||
|
||
deps-uninstall: sudo | ||
ifeq ($(OS),Linux) | ||
# TODO | ||
echo 'ACITON REQUIRED) Need to uninstall redis and nginx after this.' | ||
else ifeq ($(OS),Darwin) | ||
-brew list redis > /dev/null && brew uninstall redis | ||
-brew list nginx > /dev/null && brew uninstall nginx | ||
else | ||
echo 'ACITON REQUIRED) Need to uninstall redis and nginx after this.' | ||
endif | ||
|
||
|
||
deps-start: sudo | ||
ifeq ($(OS),Linux) | ||
sudo service redis-server start | ||
else ifeq ($(OS),Darwin) | ||
brew services run redis | ||
else | ||
sudo redis-server & | ||
endif | ||
ifeq ($(OS),Linux) | ||
sudo service nginx start | ||
else | ||
sudo nginx & | ||
endif | ||
|
||
|
||
deps-stop: sudo | ||
ifeq ($(OS),Linux) | ||
sudo service nginx stop | ||
else ifeq ($(OS),Darwin) | ||
-sudo killall -9 'nginx: master process nginx' | ||
-sudo killall -9 'nginx: worker process' | ||
-sudo killall -9 nginx | ||
else | ||
-sudo killall -9 'nginx: master process nginx' | ||
-sudo killall -9 'nginx: worker process' | ||
-sudo killall -9 nginx | ||
endif | ||
ifeq ($(OS),Linux) | ||
-sudo service redis-server stop | ||
else ifeq ($(OS),Darwin) | ||
-brew services stop redis | ||
else | ||
-sudo killall -9 redis-server | ||
endif | ||
|
||
|
||
prepare-nginx: sudo nginx/local_nginx.conf | ||
ifeq ($(OS),Linux) | ||
sudo rm -f /etc/nginx/sites-enabled/local_nginx.conf | ||
sudo ln -s `pwd`/nginx/local_nginx.conf /etc/nginx/sites-enabled/ | ||
else ifeq ($(OS),Darwin) | ||
rm -f /usr/local/etc/nginx/servers/local_nginx.conf | ||
ln -s `pwd`/nginx/local_nginx.conf /usr/local/etc/nginx/servers/ | ||
else | ||
# FIXME ln -s `pwd`/nginx/local_nginx.conf /usr/local/etc/nginx/servers/ | ||
endif |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
.PHONY: prepare clean | ||
|
||
db.sqlite3: | ||
python3 manage.py migrate | ||
|
||
pw.txt: db.sqlite3 | ||
python3 manage.py createsuperuserauto | ||
|
||
collected_static/: | ||
yes yes | python3 manage.py collectstatic | ||
|
||
secret.json: db.sqlite3 | ||
python3 manage.py autodeploy | ||
|
||
nginx/local_nginx.conf: secret.json | ||
python3 manage.py nginxconfgenerator > nginx/local_nginx.conf | ||
|
||
prepare \.prepared: \ | ||
deps-install\ | ||
db.sqlite3\ | ||
pw.txt\ | ||
collected_static/\ | ||
secret.json\ | ||
nginx/local_nginx.conf\ | ||
prepare-nginx\ | ||
|
||
touch .prepared | ||
|
||
clean: | ||
-rm \ | ||
secret.json\ | ||
db.sqlite3\ | ||
pw.txt\ | ||
nginx/local_nginx.conf\ | ||
.prepared\ | ||
-rm -r collected_static |
This file contains 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 file contains 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
57 changes: 57 additions & 0 deletions
57
coding_night_live/management/commands/nginxconfgenerator.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.conf import settings | ||
from django.template import Template, Context | ||
|
||
from .autodeploy import loadSecret | ||
|
||
|
||
NGINX_CONF_TEMPLATE = Template(''' | ||
# <NOTICE> /etc/nginx/ may not your nginx installation path. please check your installation path before. | ||
# You need to run the script below! | ||
# sudo ln -s coding-night-live/coding-night-live_nginx.conf /etc/nginx/sites-enabled/ | ||
# ex) sudo ln -s /home/punk/coding-night-live/collected_static /etc/nginx/sites-enabled/ | ||
server { | ||
listen 80; | ||
server_name {{ SERVER_NAME }}; | ||
charset utf-8; | ||
client_max_body_size 20M; | ||
location /static/ { | ||
alias {{ BASE_DIR }}/collected_static/; | ||
} | ||
location / { | ||
proxy_pass http://0.0.0.0:8001; | ||
proxy_http_version 1.1; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "upgrade"; | ||
proxy_redirect off; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Host $server_name; | ||
} | ||
} | ||
''') | ||
|
||
|
||
def _dontBelieve(conf, key, _defaultValue): | ||
believableValue = conf.get(key, None) | ||
if believableValue: | ||
return believableValue | ||
return _defaultValue | ||
|
||
|
||
class Command(BaseCommand): | ||
def handle(self, *args, **options): | ||
secret = loadSecret() | ||
variables = Context({ | ||
'BASE_DIR': settings.BASE_DIR, | ||
'SERVER_NAME': _dontBelieve(secret, 'DOMAIN', 'localhost'), | ||
'PROXY_PASS': None, | ||
'PORT': None, | ||
}) | ||
self.stdout.write(NGINX_CONF_TEMPLATE.render(variables)) |
This file contains 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 file was deleted.
Oops, something went wrong.
Oops, something went wrong.